Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev/precommitHook] log all failures, don't stop at first #19271

Merged
merged 4 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/dev/run/fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { inspect } from 'util';

const FAIL_TAG = Symbol('fail error');

export function createFailError(reason, exitCode = 1) {
Expand All @@ -29,3 +31,23 @@ export function createFailError(reason, exitCode = 1) {
export function isFailError(error) {
return Boolean(error && error[FAIL_TAG]);
}

export function combineErrors(errors) {
if (errors.length === 1) {
return errors[0];
}

const exitCode = errors
.filter(isFailError)
.reduce((acc, error) => Math.max(acc, error.exitCode), 1);

const message = errors.reduce((acc, error) => {
if (isFailError(error)) {
return acc + '\n' + error.message;
}

return acc + `\nUNHANDLED ERROR\n${inspect(error)}`;
}, '');

return createFailError(`${errors.length} errors:\n${message}`, exitCode);
}
2 changes: 1 addition & 1 deletion src/dev/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
*/

export { run } from './run';
export { createFailError } from './fail';
export { createFailError, combineErrors } from './fail';
21 changes: 17 additions & 4 deletions src/dev/run_precommit_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,33 @@
* under the License.
*/

import { run } from './run';

import { run, combineErrors } from './run';
import * as Eslint from './eslint';
import * as Tslint from './tslint';
import { getFilesForCommit, checkFileCasing } from './precommit_hook';

run(async ({ log }) => {
const files = await getFilesForCommit();
await checkFileCasing(log, files);
const errors = [];

try {
await checkFileCasing(log, files);
} catch (error) {
errors.push(error);
}

for (const Linter of [Eslint, Tslint]) {
const filesToLint = Linter.pickFilesToLint(log, files);
if (filesToLint.length > 0) {
await Linter.lintFiles(log, filesToLint);
try {
await Linter.lintFiles(log, filesToLint);
} catch (error) {
errors.push(error);
}
}
}

if (errors.length) {
throw combineErrors(errors);
}
});