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:
parent
3ca87d205f
commit
0b0679e065
3 changed files with 1074 additions and 64 deletions
1112
package-lock.json
generated
1112
package-lock.json
generated
File diff suppressed because it is too large
Load diff
18
package.json
18
package.json
|
@ -4,6 +4,7 @@
|
||||||
"repository": "https://github.com/electron/electron",
|
"repository": "https://github.com/electron/electron",
|
||||||
"description": "Build cross platform desktop apps with JavaScript, HTML, and CSS",
|
"description": "Build cross platform desktop apps with JavaScript, HTML, and CSS",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@octokit/rest": "^16.3.2",
|
||||||
"aliasify": "^2.1.0",
|
"aliasify": "^2.1.0",
|
||||||
"asar": "^0.11.0",
|
"asar": "^0.11.0",
|
||||||
"browserify": "^13.1.0",
|
"browserify": "^13.1.0",
|
||||||
|
@ -18,9 +19,9 @@
|
||||||
"eslint-config-standard": "^12.0.0",
|
"eslint-config-standard": "^12.0.0",
|
||||||
"eslint-plugin-mocha": "^5.2.0",
|
"eslint-plugin-mocha": "^5.2.0",
|
||||||
"folder-hash": "^2.1.1",
|
"folder-hash": "^2.1.1",
|
||||||
"@octokit/rest": "^16.3.2",
|
|
||||||
"husky": "^0.14.3",
|
"husky": "^0.14.3",
|
||||||
"lint": "^1.1.2",
|
"lint": "^1.1.2",
|
||||||
|
"lint-staged": "^8.1.0",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
"nugget": "^2.0.1",
|
"nugget": "^2.0.1",
|
||||||
"octicons": "^7.3.0",
|
"octicons": "^7.3.0",
|
||||||
|
@ -53,7 +54,7 @@
|
||||||
"create-api-json": "electron-docs-linter docs --outfile=electron-api.json",
|
"create-api-json": "electron-docs-linter docs --outfile=electron-api.json",
|
||||||
"create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --in=electron-api.json --out=electron.d.ts",
|
"create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --in=electron-api.json --out=electron.d.ts",
|
||||||
"preinstall": "node -e 'process.exit(0)'",
|
"preinstall": "node -e 'process.exit(0)'",
|
||||||
"precommit": "python script/run-clang-format.py -r -c atom/ chromium_src/ && node ./script/lint.js -c && remark docs -qf || (echo \"Code not formatted correctly.\" && exit 1)",
|
"precommit": "lint-staged",
|
||||||
"prepack": "check-for-leaks",
|
"prepack": "check-for-leaks",
|
||||||
"prepush": "check-for-leaks",
|
"prepush": "check-for-leaks",
|
||||||
"repl": "node ./script/start.js --interactive",
|
"repl": "node ./script/start.js --interactive",
|
||||||
|
@ -69,5 +70,18 @@
|
||||||
"replacements": {
|
"replacements": {
|
||||||
"@electron/internal/(.+)": "./lib/$1"
|
"@electron/internal/(.+)": "./lib/$1"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{js,ts}": [
|
||||||
|
"node script/lint.js --js --fix --only --",
|
||||||
|
"git add"
|
||||||
|
],
|
||||||
|
"*.{cc,mm,c,h}": [
|
||||||
|
"python script/run-clang-format.py -r -c --fix",
|
||||||
|
"git add"
|
||||||
|
],
|
||||||
|
"*.md": [
|
||||||
|
"remark -qf"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,12 +116,12 @@ const LINTERS = [ {
|
||||||
function parseCommandLine () {
|
function parseCommandLine () {
|
||||||
let help
|
let help
|
||||||
const opts = minimist(process.argv.slice(2), {
|
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' },
|
alias: { 'c++': ['cc', 'cpp', 'cxx'], javascript: ['js', 'es'], python: 'py', changed: 'c', help: 'h', verbose: 'v' },
|
||||||
unknown: arg => { help = true }
|
unknown: arg => { help = true }
|
||||||
})
|
})
|
||||||
if (help || opts.help) {
|
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)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
return opts
|
return opts
|
||||||
|
@ -161,6 +161,8 @@ async function findFiles (args, linter) {
|
||||||
if (!whitelist.size) {
|
if (!whitelist.size) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
} else if (args.only) {
|
||||||
|
whitelist = new Set(args._)
|
||||||
}
|
}
|
||||||
|
|
||||||
// accumulate the raw list of files
|
// accumulate the raw list of files
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue