Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Report needless disables (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
edg2s authored Nov 19, 2020
1 parent 34fa57d commit 0619fdd
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions tasks/grunt-stylelint.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,44 @@ module.exports = function ( grunt ) {
}
}

const warningsCount = data.results.reduce( function ( count, item ) {
return ( count + item.warnings.length );
let warningsCount = 0;

if ( data.needlessDisables ) {
data.needlessDisables.forEach( function ( nd ) {
if ( nd.ranges.length ) {
grunt.log.writeln();
grunt.log.writeln(
chalk.underline( nd.source )
);
nd.ranges.forEach( function ( range ) {
warningsCount++;
grunt.log.writeln(
chalk.yellow( 'Needless disable: ' ) +
range.unusedRule +
', start line: ' + range.start +
', end line: ' + range.end
);
} );
}
} );
}

warningsCount += data.results.reduce( function ( count, item ) {
return count + item.warnings.length;
}, 0 );

if ( !data.errored ) {
if ( warningsCount ) {
grunt.log.writeln();
grunt.log.writeln( chalk.yellow.bold( [
'⚠ ', warningsCount, pluralize( ' warning', warningsCount ), '\n'
].join( '' ) ) );
}

if ( data.errored ) {
done( !options.failOnError );
} else {
grunt.log.ok( 'Linted ' + options.files.length + ' files without errors' );
done();
} else {
if ( options.failOnError && warningsCount > 0 ) {
grunt.log.writeln( chalk.red.bold( [
'\u2716 ', warningsCount, pluralize( ' problem', warningsCount ), '\n'
].join( '' ) ) );
}
done( !options.failOnError );
}
}, function ( err ) {
grunt.fail.warn( 'Running stylelint failed\n' + err.stack.toString() );
Expand Down

0 comments on commit 0619fdd

Please sign in to comment.