From e1e836cb594e5a393790601dce36c7157b2a2d73 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 31 Jan 2023 17:29:34 +0530 Subject: [PATCH] chore: Run linters on staged files only (#6347) - This PR speeds up the pre-commit hook to lint only the staged files instead of running it across all files as it does now. --- .husky/pre-commit | 12 +++++++++--- package.json | 5 ----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 7774f34f5..9984ac506 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,11 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npm run eslint -bundle exec rubocop -a -git add + +# lint js and vue files +npx --no-install lint-staged + +# lint only staged ruby files +git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop -a + +# stage rubocop changes to files +git diff --name-only --cached | xargs git add diff --git a/package.json b/package.json index 01b348e32..e9863123b 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,6 @@ }, "husky": { "hooks": { - "pre-commit": "lint-staged", "pre-push": "sh bin/validate_push" } }, @@ -138,10 +137,6 @@ "eslint --fix", "git add" ], - "!(*schema).rb": [ - "bundle exec rubocop -a", - "git add" - ], "*.scss": [ "scss-lint" ]