lint-staged lints unstaged files
tonirah opened this issue · 1 comments
tonirah commented
Issue
Having changes in several files, some staged for commit and some not, the pre-commit hook will fail if there are linting errors in an unstaged file.
Expected behavior
pre-commit hook / lint-stage should affect staged files and ignore unstaged files.
Cause
I think the lint-stage config is the issue:
// package.json
...
"scripts": {
...
"lint": "eslint --ignore-path .gitignore \"src/**/*.+(ts|js|tsx)\"",
"format": "prettier --ignore-path .gitignore \"src/**/*.+(ts|js|tsx)\" --write",
...
},
"lint-staged": {
"./src/**/*.{ts,js,jsx,tsx}": [
"yarn lint --fix",
"yarn format"
]
},
Attaching the path \"src/**/*.+(ts|js|tsx)\"
to both commands will make eslint and prettier run on all files.
See also: lint-staged/lint-staged#869
Proposed solution
// package.json
"lint-staged": {
"./src/**/*.{ts,js,jsx,tsx}": [
"eslint --ignore-path .gitignore --fix",
"prettier --ignore-path .gitignore --write"
]
},
Works for me. lint-stage appends the staged file paths at the end of the commands. Should I open an PR with this?
jpedroschmitz commented
Hey @tonirah, thanks for reporting it!
I'll test the solution and update it in the following days! Thanks