Skip to content

Commit 1ef8879

Browse files
Adds htmlacademy/space-between-comments
1 parent facbec4 commit 1ef8879

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

rules/space-between-comments/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
'use strict';
22
const { is_comment_node } = require('@linthtml/dom-utils');
33

4-
const hasSpacesAtStartAndEnd = (string) => string.startsWith(' ') && string.endsWith(' ');
4+
const hasSpacesAtStartAndEnd = (rule, string) => {
5+
rule = rule === undefined ? 'space' : rule;
6+
7+
if (rule === 'space') {
8+
return string.startsWith(' ') && string.endsWith(' ');
9+
} else if (rule === 'no-space') {
10+
return !string.startsWith(' ') && !string.endsWith(' ');
11+
}
12+
};
513

614
module.exports = {
715
name: 'htmlacademy/space-between-comments',
816
// eslint-disable-next-line camelcase
917
lint(node, rule_config, { report }) {
1018
if (is_comment_node(node)) {
1119
const comment = node.data;
12-
const isEdges = hasSpacesAtStartAndEnd(comment);
20+
const isEdges = hasSpacesAtStartAndEnd(rule_config, comment);
1321

1422
if (!isEdges) {
23+
// eslint-disable-next-line camelcase
24+
const message = rule_config === 'space'
25+
? 'The comment should contain spaces at the beginning and end of the message.'
26+
: 'The comment should not contain spaces at the beginning and end of the message.';
27+
1528
report({
1629
position: node.loc,
17-
message: 'The comment does not contain spaces at the beginning and end of the message.'
30+
message
1831
});
1932
}
2033
}

0 commit comments

Comments
 (0)