mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[dev/precommitHook] log all failures, don't stop at first (#19271)
This commit is contained in:
parent
da2da74a08
commit
d9b31710d0
3 changed files with 40 additions and 5 deletions
|
@ -17,6 +17,8 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { inspect } from 'util';
|
||||
|
||||
const FAIL_TAG = Symbol('fail error');
|
||||
|
||||
export function createFailError(reason, exitCode = 1) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -18,4 +18,4 @@
|
|||
*/
|
||||
|
||||
export { run } from './run';
|
||||
export { createFailError } from './fail';
|
||||
export { createFailError, combineErrors } from './fail';
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue