build: auto-fix linting issues on commit (#16466)

* build: auto-fix formatting during commit

* use lint-staged as precommit hook to autofix issues
This commit is contained in:
Samuel Attard 2019-01-21 14:46:32 -08:00 committed by GitHub
parent 3ca87d205f
commit 0b0679e065
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 1074 additions and 64 deletions

View file

@ -116,12 +116,12 @@ const LINTERS = [ {
function parseCommandLine () {
let help
const opts = minimist(process.argv.slice(2), {
boolean: [ 'c++', 'javascript', 'python', 'gn', 'help', 'changed', 'fix', 'verbose' ],
boolean: [ 'c++', 'javascript', 'python', 'gn', 'help', 'changed', 'fix', 'verbose', 'only' ],
alias: { 'c++': ['cc', 'cpp', 'cxx'], javascript: ['js', 'es'], python: 'py', changed: 'c', help: 'h', verbose: 'v' },
unknown: arg => { help = true }
})
if (help || opts.help) {
console.log('Usage: script/lint.js [--cc] [--js] [--py] [-c|--changed] [-h|--help] [-v|--verbose] [--fix]')
console.log('Usage: script/lint.js [--cc] [--js] [--py] [-c|--changed] [-h|--help] [-v|--verbose] [--fix] [--only -- file1 file2]')
process.exit(0)
}
return opts
@ -161,6 +161,8 @@ async function findFiles (args, linter) {
if (!whitelist.size) {
return []
}
} else if (args.only) {
whitelist = new Set(args._)
}
// accumulate the raw list of files