Skip to content

Commit b47ab4f

Browse files
feat: add the fixer function to eslint/rules/no-empty-comments
PR-URL: #3340 Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent fdee038 commit b47ab4f

File tree

2 files changed

+64
-7
lines changed
  • lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments

2 files changed

+64
-7
lines changed

lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/lib/main.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,23 @@ function main(context) {
4949
context.report({
5050
'node': null,
5151
'message': 'Empty comments are not allowed',
52-
'loc': comment.loc
52+
'loc': comment.loc,
53+
'fix': fix
5354
});
55+
56+
/**
57+
* Fixes the lint error.
58+
*
59+
* @private
60+
* @param {Function} fixer - ESLint fixer
61+
* @returns {(Object|null)} fix or null
62+
*/
63+
function fix( fixer ) {
64+
if ( comment.type === 'Block' || comment.type === 'Line' ) {
65+
return fixer.removeRange( comment.range );
66+
}
67+
return null;
68+
}
5469
}
5570

5671
/**
@@ -98,11 +113,12 @@ function main(context) {
98113

99114
rule = {
100115
'meta': {
116+
'type': 'layout',
101117
'docs': {
102118
'description': 'enforce that comments are not empty'
103119
},
104-
'schema': [],
105-
'fixable': null
120+
'fixable': 'code',
121+
'schema': []
106122
},
107123
'create': main
108124
};

lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-comments/test/fixtures/invalid.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ test = {
3333
'message': 'Empty comments are not allowed',
3434
'type': null
3535
}
36-
]
36+
],
37+
'output': [
38+
'function pow2( x ) {',
39+
' ',
40+
' return x*x;',
41+
'}'
42+
].join( '\n' )
3743
};
3844
invalid.push( test );
3945

@@ -55,7 +61,19 @@ test = {
5561
'message': 'Empty comments are not allowed',
5662
'type': null
5763
}
58-
]
64+
],
65+
'output': [
66+
'function fizzBuzz() {',
67+
' var out;',
68+
' var i;',
69+
'',
70+
' for ( i = 1; i <= 100; i++ ) {',
71+
' out = ( i % 5 === 0 ) ? "Buzz" : ( i % 3 === 0 ) ? "Fizz" : i;',
72+
' ',
73+
' console.log( out );',
74+
' }',
75+
'}'
76+
].join( '\n' )
5977
};
6078
invalid.push( test );
6179

@@ -81,7 +99,19 @@ test = {
8199
'message': 'Empty comments are not allowed',
82100
'type': null
83101
}
84-
]
102+
],
103+
'output': [
104+
'function makePerson() {',
105+
' var person = {',
106+
' ',
107+
' \'title\': \'engineer\',',
108+
'',
109+
' ',
110+
' \'name\': \'Susan\'',
111+
' };',
112+
' return person;',
113+
'}'
114+
].join( '\n' )
85115
};
86116
invalid.push( test );
87117

@@ -102,7 +132,18 @@ test = {
102132
'message': 'Empty comments are not allowed',
103133
'type': null
104134
}
105-
]
135+
],
136+
'output': [
137+
'function square( x ) {',
138+
' var out;',
139+
' var x;',
140+
'',
141+
' out = x*x;',
142+
' ',
143+
'',
144+
' return out;',
145+
'}'
146+
].join( '\n' )
106147
};
107148
invalid.push( test );
108149

0 commit comments

Comments
 (0)