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 коммит произвёл GitHub
Родитель e860748d6b
Коммит 7b71d7cbce
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -65,7 +65,7 @@
"mock-release": "node ./script/ci-release-build.js", "mock-release": "node ./script/ci-release-build.js",
"preinstall": "node -e 'process.exit(0)'", "preinstall": "node -e 'process.exit(0)'",
"publish-to-npm": "node ./script/publish-to-npm.js", "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", "prepack": "check-for-leaks",
"prepush": "check-for-leaks", "prepush": "check-for-leaks",
"prepare-release": "node ./script/prepare-release.js", "prepare-release": "node ./script/prepare-release.js",

Просмотреть файл

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