Last active
November 1, 2016 15:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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