-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set ESLint rules as errors while preventing hooks/CI from failing #6945
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"rulesNotToDowngrade": ["no-unused-vars"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this option? I tried referencing the project documentation but it seems either unnecessary in that we should leverage errors as defined in our configuration or invalid in that it's assuming that all errors are warnings if not modified in the current changeset. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The core idea of Different teams can have different use cases for this. Ours, and one that I'd recommend for every project, is to not downgrade There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've talked privately to aduth about this and all is clear now. |
||
"remote": "origin/master", | ||
"processors": { | ||
"default": "lines-modified", | ||
"master": "parsing-errors" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
#!/bin/sh | ||
|
||
PATH="$PATH:/usr/local/bin" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nosolosw For those of us using GUI git apps like Tower.app, removing PATH causes commit to stop working as the app no longer has PATH info to run the commands in More info: https://www.git-tower.com/help/mac/faq-and-tips/faq#faq-hook-scripts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure @raoulwegat , can you test #12548 works and green-lit it? |
||
|
||
printf "\nBy contributing to this project, you license the materials you contribute under the GNU General Public License v2 (or later). All materials must have GPLv2 compatible licenses — see .github/CONTRIBUTING.md for details.\n\n" | ||
|
||
# Make quick pass over config files on every change | ||
|
@@ -16,21 +14,13 @@ pass=true | |
|
||
printf "\nValidating .jsx and .js:\n" | ||
|
||
for file in ${files}; do | ||
./node_modules/.bin/eslint --cache ${file} | ||
if [ $? -ne 0 ]; then | ||
printf "\033[31meslint Failed: %s\033[0m\n" "${file}" | ||
pass=false | ||
else | ||
printf "\033[32meslint Passed: %s\033[0m\n" "${file}" | ||
fi | ||
done | ||
|
||
printf "\neslint validation complete\n" | ||
|
||
if ! $pass; then | ||
printf "\n\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass validation tests but do not. Please fix the errors and try again.\n\n" | ||
exit 1 | ||
else | ||
printf "\n\033[42mCOMMIT SUCCEEDED\033[0m\n\n" | ||
./bin/run-lint $(git diff --cached --name-only client/ server/ test/ | grep ".jsx*$") -- --diff=index | ||
linter_exit_code=$? | ||
if [ ! 0 = "$linter_exit_code" ] | ||
then | ||
printf "\n" | ||
printf "\033[41mCOMMIT ABORTED:\033[0m the linter reported some problems. If you are aware of them and it is OK, repeat the commit command with --no-verify to avoid this check. You may also want to execute the linter after the errors have been solved: ./bin/run-lint \$(git diff --cached --name-only client/ server/ test/) -- --diff=index" | ||
printf "\n" | ||
fi | ||
|
||
exit $linter_exit_code |
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 ); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a bit of irony in that these files don't adhere to our ESLint configuration 😄 Specifically, lacking space before closing paren. Also var below should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, indeed! :D And probably has to do with the fact that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also: AFAIK, this was a script that originally only run in CircleCI and in dev machines and maybe and the time If it is not a blocker, I'd prefer solving (and testing) this in another PR after this has been landed. |
||
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we ever reading this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it had a typo, sorry. This was fixed (and updated with new config) within the latest changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍