-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set ESLint rules as errors while preventing build tools from failing.
The gist of this PR is: eslint -f json | eslines With these changes in place, the linting task will report: * only parsing errors, when running on master branch. * for other branches, any ESLint error in * lines modified within that branch * any linted files for the rule no-unused-vars
- Loading branch information
Showing
6 changed files
with
92 additions
and
104 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"rulesNotToDowngrade": ["no-unused-vars"], | ||
"remote": "origin/master", | ||
"processors": { | ||
"default": "lines-modified", | ||
"master": "parsing-errors" | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,59 @@ | ||
#!/usr/bin/env node | ||
const child_process = require( 'child_process' ); | ||
|
||
const path = require( 'path' ); | ||
var args = [ '--cache', '--quiet', '--ext=.js', '--ext=.jsx' ]; | ||
if ( process.argv.length > 2 ) { | ||
args = args.concat( process.argv.slice( 2 ) ); | ||
const child_process = require( 'child_process' ); | ||
|
||
var argsESLint = [ '--cache', '--quiet', '--ext=.js,.jsx', '--format=json' ]; | ||
var argsESLines = [ ]; | ||
|
||
const markerIndex = process.argv.indexOf('--'); | ||
if ( ( process.argv.length > 2 ) && ( markerIndex > 2 )) { | ||
// use -- as a marker for end of options, | ||
// so any value that follows the marker is considered an option for ESLines. | ||
if ( markerIndex > -1 ) { | ||
argsESLint = argsESLint.concat( process.argv.slice( 2, markerIndex ) ); | ||
argsESLines = argsESLines.concat( process.argv.slice( markerIndex + 1 ) ); | ||
} else { | ||
argsESLint = argsESLint.concat( process.argv.slice( 2 ) ); | ||
} | ||
} else { | ||
args = args.concat( [ '.' ] ); | ||
process.stdout.write( 'No files to lint\n' ); | ||
process.exit( 0 ); | ||
} | ||
|
||
const results = child_process.spawnSync( path.join( '.', 'node_modules', '.bin', 'eslint' ), args ); | ||
const eslint = child_process.spawn( path.join( '.', 'node_modules', '.bin', 'eslint' ), argsESLint ); | ||
const eslines = child_process.spawn( path.join( '.', 'node_modules', '.bin', 'eslines' ), argsESLines ); | ||
|
||
if ( results.stdout ) { | ||
process.stdout.write( results.stdout ); | ||
} | ||
if ( results.stderr ) { | ||
process.stderr.write( results.stderr ); | ||
} | ||
process.on( 'exit', function() { | ||
process.exit( results.status ); | ||
} ); | ||
eslint.stdout.on( 'data', ( data ) => { | ||
eslines.stdin.write( data ); | ||
}); | ||
|
||
var eslintStdErr = 0; | ||
eslint.stderr.on( 'data', ( data ) => { | ||
eslintStdErr = 1; | ||
process.stderr.write( data ); | ||
}); | ||
|
||
eslint.on('close', ( code ) => { | ||
eslines.stdin.end(); | ||
}); | ||
|
||
eslines.stdout.on( 'data', ( data ) => { | ||
process.stdout.write( data ); | ||
}); | ||
|
||
eslines.stderr.on( 'data', ( data ) => { | ||
process.stderr.write( data ); | ||
}); | ||
|
||
eslines.on( 'close', ( code ) => { | ||
// since the goal of eslines is to downgrade errors | ||
// on non-modified lines, we can't count on eslint's | ||
// exit code, but we assume that if eslint output | ||
// something on its stderr, this means it encountered | ||
// some other error | ||
if ( eslintStdErr === 1 ) { | ||
process.exit( 1 ); | ||
} | ||
process.exit( code ); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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