diff --git a/package.json b/package.json index 8e942ba9c777..38ebcb71693e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/script/cpplint.js b/script/cpplint.js index 47aa4f90558f..f54acc54161f 100755 --- a/script/cpplint.js +++ b/script/cpplint.js @@ -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 stderr.split(/[\r\n]+/)) { - if (!line.startsWith('Done processing ')) console.warn(line) + 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) + } } }) } 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)