fix: pass staged filenames to the eslint pre-commit hook
PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / ESLint (pull_request) Successful in 35s
PR Check / Typecheck (pull_request) Canceled after 15s
PR Check / Secret scan (gitleaks) (pull_request) Canceled after 0s
PR Check / Dependency audit (pull_request) Canceled after 0s
PR Check / Dockerfile lint (droast) (pull_request) Canceled after 0s
PR Check / AI code review (opencode) (pull_request) Canceled after 0s
PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / ESLint (pull_request) Successful in 35s
PR Check / Typecheck (pull_request) Canceled after 15s
PR Check / Secret scan (gitleaks) (pull_request) Canceled after 0s
PR Check / Dependency audit (pull_request) Canceled after 0s
PR Check / Dockerfile lint (droast) (pull_request) Canceled after 0s
PR Check / AI code review (opencode) (pull_request) Canceled after 0s
Validated from review comment 82 on this PR: the 'bash -c' wrapper consumed the first staged filename as $0 and the command never referenced $@, so eslint received zero file arguments and linted the whole repo - --fix silently rewrote unstaged files and WIP lint errors blocked unrelated commits. The entry now receives filenames directly from pre-commit (empirically verified with an arg probe); documented the re-stage loop for --fix and dropped the redundant 'types: [file]' filter.
This commit is contained in:
1 parent
8fa8eb63b2
commit
81d658a871
1 file changed
+10
-3
+10
-3
@@ -55,15 +55,22 @@ repos:
|
|||||||
|
|
||||||
# --------------------------------------------------------- ESLint (Nuxt) -
|
# --------------------------------------------------------- ESLint (Nuxt) -
|
||||||
# Local hook: needs `pnpm install` to have run in this repo. --fix makes
|
# Local hook: needs `pnpm install` to have run in this repo. --fix makes
|
||||||
# it a helper; only staged files are linted (fast).
|
# it a helper; only staged files are linted (fast). When --fix rewrites
|
||||||
|
# a staged file, pre-commit aborts the commit ("files were modified") -
|
||||||
|
# re-stage and commit again; that re-stage loop is the standard price
|
||||||
|
# of a fixer hook.
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: eslint
|
- id: eslint
|
||||||
name: eslint --fix (staged files)
|
name: eslint --fix (staged files)
|
||||||
entry: bash -c 'pnpm exec eslint --fix'
|
# no shell wrapper: pre-commit appends the staged filenames to the
|
||||||
|
# entry itself. A 'bash -c' wrapper would eat the first filename
|
||||||
|
# as $0 and eslint would get no file arguments at all (linting the
|
||||||
|
# whole repo instead - review finding on this PR, empirically
|
||||||
|
# verified).
|
||||||
|
entry: pnpm exec eslint --fix
|
||||||
language: system
|
language: system
|
||||||
files: \.(vue|ts|js|mjs|cjs)$
|
files: \.(vue|ts|js|mjs|cjs)$
|
||||||
types: [file]
|
|
||||||
|
|
||||||
# When Go services arrive, add:
|
# When Go services arrive, add:
|
||||||
# - repo: https://github.com/dnephin/pre-commit-golang
|
# - repo: https://github.com/dnephin/pre-commit-golang
|
||||||
|
|||||||
Reference in new issue
Block a user