File tree Expand file tree Collapse file tree 2 files changed +63
-7
lines changed
Expand file tree Collapse file tree 2 files changed +63
-7
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,22 @@ 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 by removing empty comments.
58+ * @private
59+ * @param {Function } fixer - ESLint fixer
60+ * @returns {(Object|null) } fix or null
61+ */
62+ function fix ( fixer ) {
63+ if ( comment . type === 'Block' || comment . type === 'Line' ) {
64+ return fixer . removeRange ( comment . range ) ;
65+ }
66+ return null ;
67+ }
5468 }
5569
5670 /**
@@ -98,11 +112,12 @@ function main(context) {
98112
99113rule = {
100114 'meta' : {
115+ 'type' : 'layout' ,
101116 'docs' : {
102117 'description' : 'enforce that comments are not empty'
103118 } ,
104- 'schema ' : [ ] ,
105- 'fixable ' : null
119+ 'fixable ' : 'code' ,
120+ 'schema ' : [ ]
106121 } ,
107122 'create' : main
108123} ;
Original file line number Diff line number Diff 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} ;
3844invalid . 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} ;
6078invalid . 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} ;
86116invalid . 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} ;
107148invalid . push ( test ) ;
108149
You can’t perform that action at this time.
0 commit comments