Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,22 @@ function main(context) {
context.report({
'node': null,
'message': 'Empty comments are not allowed',
'loc': comment.loc
'loc': comment.loc,
'fix': fix
});

/**
* Fixes the lint error by removing empty comments.
* @private
* @param {Function} fixer - ESLint fixer
* @returns {(Object|null)} fix or null
*/
function fix( fixer ) {
if ( comment.type === 'Block' || comment.type === 'Line' ) {
return fixer.removeRange( comment.range );
}
return null;
}
}

/**
Expand Down Expand Up @@ -98,11 +112,12 @@ function main(context) {

rule = {
'meta': {
'type': 'layout',
'docs': {
'description': 'enforce that comments are not empty'
},
'schema': [],
'fixable': null
'fixable': 'code',
'schema': []
},
'create': main
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ test = {
'message': 'Empty comments are not allowed',
'type': null
}
]
],
'output': [
'function pow2( x ) {',
' ',
' return x*x;',
'}'
].join( '\n' )
};
invalid.push( test );

Expand All @@ -55,7 +61,19 @@ test = {
'message': 'Empty comments are not allowed',
'type': null
}
]
],
'output': [
'function fizzBuzz() {',
' var out;',
' var i;',
'',
' for ( i = 1; i <= 100; i++ ) {',
' out = ( i % 5 === 0 ) ? "Buzz" : ( i % 3 === 0 ) ? "Fizz" : i;',
' ',
' console.log( out );',
' }',
'}'
].join( '\n' )
};
invalid.push( test );

Expand All @@ -81,7 +99,19 @@ test = {
'message': 'Empty comments are not allowed',
'type': null
}
]
],
'output': [
'function makePerson() {',
' var person = {',
' ',
' \'title\': \'engineer\',',
'',
' ',
' \'name\': \'Susan\'',
' };',
' return person;',
'}'
].join( '\n' )
};
invalid.push( test );

Expand All @@ -102,7 +132,18 @@ test = {
'message': 'Empty comments are not allowed',
'type': null
}
]
],
'output': [
'function square( x ) {',
' var out;',
' var x;',
'',
' out = x*x;',
' ',
'',
' return out;',
'}'
].join( '\n' )
};
invalid.push( test );

Expand Down
Loading