Skip to content

Instantly share code, notes, and snippets.

@aduth
Last active November 1, 2016 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aduth/0316b947571687d05ad405eba61402af to your computer and use it in GitHub Desktop.
Save aduth/0316b947571687d05ad405eba61402af to your computer and use it in GitHub Desktop.
Finds ESLint rules which are declared as warnings but for which there are no issues, to be safely upgraded to error
/* eslint-disable no-console */
/**
* External dependencies
*/
const execSync = require( 'child_process' ).execSync;
const reduce = require( 'lodash/reduce' );
/**
* Internal dependencies
*/
const rules = require( './.eslintrc' ).rules;
function getRuleLevel( config ) {
if ( 'number' === typeof config ) {
return config;
}
if ( Array.isArray( config ) ) {
return config[ 0 ];
}
return 0;
}
reduce( rules, ( memo, config, rule ) => {
if ( 1 !== getRuleLevel( config ) ) {
return Promise.resolve();
}
return memo.then( () => {
return new Promise( ( resolve ) => {
try {
execSync( './node_modules/.bin/eslint --quiet --ext .jsx,.js --rule \'' + rule + ': 2\' .' );
console.log( 'NO ERROR: ' + rule );
} catch ( error ) {
} finally {
resolve();
}
} );
} );
}, Promise.resolve() ).then( () => {
console.log( 'Done' );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment