feat: run 'cpplint -c' as a precommit hook (#14586)

* feat: `cpplint -c` all changed files, even staged

* refactor: simplify cpplint invocation

* fix: cpplint now EXIT_FAILUREs on linter errors

* feat: precommit hook runs 'cpplint -c'
This commit is contained in:
Charles Kerr 2018-09-12 14:43:54 -05:00 committed by GitHub
parent e860748d6b
commit 7b71d7cbce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View file

@ -65,7 +65,7 @@
"mock-release": "node ./script/ci-release-build.js",
"preinstall": "node -e 'process.exit(0)'",
"publish-to-npm": "node ./script/publish-to-npm.js",
"precommit": "python script/run-clang-format.py -r -c atom/ chromium_src/ brightray/ && npm run lint:js && remark docs -qf || (echo \"Code not formatted correctly.\" && exit 1)",
"precommit": "python script/run-clang-format.py -r -c atom/ chromium_src/ brightray/ && node ./script/cpplint.js -c && npm run lint:js && remark docs -qf || (echo \"Code not formatted correctly.\" && exit 1)",
"prepack": "check-for-leaks",
"prepush": "check-for-leaks",
"prepare-release": "node ./script/prepare-release.js",

View file

@ -12,12 +12,16 @@ function callCpplint (filenames, args) {
const linter = 'cpplint.py'
if (args.verbose) console.log([linter, ...filenames].join(' '))
try {
childProcess.execFile(linter, filenames, {cwd: SOURCE_ROOT}, (error, stdout, stderr) => {
childProcess.execFile(linter, filenames, {cwd: SOURCE_ROOT}, error => {
if (error) {
console.warn(error)
for (const line of error.message.split(/[\r\n]+/)) {
if (line.length && !line.startsWith('Done processing ')) {
console.warn(line)
}
}
if (error.message.includes('Command failed')) {
process.exit(1)
}
for (const line of stderr.split(/[\r\n]+/)) {
if (!line.startsWith('Done processing ')) console.warn(line)
}
})
} catch (e) {
@ -41,7 +45,7 @@ function parseCommandLine () {
}
async function findChangedFiles (top) {
const result = await GitProcess.exec(['diff', '--name-only'], top)
const result = await GitProcess.exec(['diff', 'HEAD', '--name-only'], top)
if (result.exitCode !== 0) {
console.log('Failed to find changed files', GitProcess.parseError(result.stderr))
process.exit(1)