You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding linting checks for pre-commit (e.g. prettier, eslint, markdownlint) using the --fix option, the commit still goes through and fixes the file afterwards.
Lefthook version
Using lefthook version 1.3.2
Steps to reproduce
Commit file with fixable linting error, when having a linting check in pre-commit with the --fix option.
Expected results
If a file is automatically fixed by resolving the linting issues, I would want my commit to still be blocked, but fix the file.
Only way to circumvent this for the moment: do 2 separate checks: one purely for verifying, and one for fixing. However, this decreases the speed of the pre-commit checking a lot.
Actual results
Commit with linting mistakes still goes through, while file is fixed.
Possible Solution
Either on the side of the specific packages: add error code when fixes are executed
For lefthook: keep track when fix has happened and give the option to block commits in these types of cases.
(Specifically for prettier: there is a package pretty-quick that gives the option to --bail when a fix happens and still block the commit, but such a solution is not available for each linter.)
The text was updated successfully, but these errors were encountered:
Hey @ava-mc! It's a good idea but I have concerns about the solution. The reason lefthook doesn't block commits is - the linter's return code is 0, so it finishes successfully. Many people want lefthook to behave smoothly and add changes for fixed files automatically.
I can recommend you the following configuration to get what you want:
pre-commit:
commands:
lint:
# it looks like a hack but it makes sense that commands should fail (return non-0) to fail the hookrun: npm run lint || (npm run lint --fix && exit 1)
Or if you want to automatically add fixed files to the commit, use the following:
🔧 Summary
When adding linting checks for pre-commit (e.g. prettier, eslint, markdownlint) using the --fix option, the commit still goes through and fixes the file afterwards.
Lefthook version
Using lefthook version 1.3.2
Steps to reproduce
Commit file with fixable linting error, when having a linting check in pre-commit with the --fix option.
Expected results
If a file is automatically fixed by resolving the linting issues, I would want my commit to still be blocked, but fix the file.
Only way to circumvent this for the moment: do 2 separate checks: one purely for verifying, and one for fixing. However, this decreases the speed of the pre-commit checking a lot.
Actual results
Commit with linting mistakes still goes through, while file is fixed.
Possible Solution
Either on the side of the specific packages: add error code when fixes are executed
For lefthook: keep track when fix has happened and give the option to block commits in these types of cases.
(Specifically for prettier: there is a package pretty-quick that gives the option to --bail when a fix happens and still block the commit, but such a solution is not available for each linter.)
The text was updated successfully, but these errors were encountered: