From 5df9d41dbceb697c76181fcddea9873ec2d9d860 Mon Sep 17 00:00:00 2001 From: Baturalp Gurdin <9674241+suchcodemuchwow@users.noreply.github.com> Date: Fri, 1 Oct 2021 13:51:58 +0200 Subject: [PATCH] chore: add modifications to staging automatically after eslint fix (#113443) After precommit hook runs with --fix flag changes are not added to staging. However it also does not validate staging area since eslint is only looking for last changes on file not staging area this results fellows to commit with linting errors which fails in CI. This commit resolves this issue by adding fixed files right after linting to staging area. Closes #52722 Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- src/dev/run_precommit_hook.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/dev/run_precommit_hook.js b/src/dev/run_precommit_hook.js index e1eafaf28d95..0a594a232cc2 100644 --- a/src/dev/run_precommit_hook.js +++ b/src/dev/run_precommit_hook.js @@ -6,6 +6,9 @@ * Side Public License, v 1. */ +import SimpleGit from 'simple-git/promise'; + +import { REPO_ROOT } from '@kbn/utils'; import { run, combineErrors, createFlagError, createFailError } from '@kbn/dev-utils'; import * as Eslint from './eslint'; import * as Stylelint from './stylelint'; @@ -48,6 +51,11 @@ run( await Linter.lintFiles(log, filesToLint, { fix: flags.fix, }); + + if (flags.fix) { + const simpleGit = new SimpleGit(REPO_ROOT); + await simpleGit.add(filesToLint); + } } catch (error) { errors.push(error); }