File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
const { is_comment_node } = require ( '@linthtml/dom-utils' ) ;
3
3
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
+ } ;
5
13
6
14
module . exports = {
7
15
name : 'htmlacademy/space-between-comments' ,
8
16
// eslint-disable-next-line camelcase
9
17
lint ( node , rule_config , { report } ) {
10
18
if ( is_comment_node ( node ) ) {
11
19
const comment = node . data ;
12
- const isEdges = hasSpacesAtStartAndEnd ( comment ) ;
20
+ const isEdges = hasSpacesAtStartAndEnd ( rule_config , comment ) ;
13
21
14
22
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
+
15
28
report ( {
16
29
position : node . loc ,
17
- message : 'The comment does not contain spaces at the beginning and end of the message.'
30
+ message
18
31
} ) ;
19
32
}
20
33
}
You can’t perform that action at this time.
0 commit comments