-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using rubocop with -a option. #214
Comments
You'll have to write a custom hook to accomplish this, since the built-in RuboCop hook is intended simply to report errors, not to alter files before commit. |
@jawshooah yes, but i send another parameter to rubocop command (as you can see in example above), that run with -a --auto-correct option should also fix warnings. What I missed? |
The core problem is that any changes Actually, I'm not sure that you could even accomplish what you want with a custom hook at all, since restoring the environment wipes out any changes made during the hook run. @sds, can you think of a way around this? |
@skywinder Overcommit is not intended to run hooks that modify any files or add/remove files from the git index. It's not really an intended use case due to technical details of how we implement the pre-commit hook saving and restoring of the working tree. It also keeps the tool open to supporting cool features in future like running hooks in parallel (#144) — the moment you start to encourage hooks to modify files you provide more ways for a user to shoot themselves in the foot since you have multiple actors (hooks) modifying a shared resource (the git index). My recommendation is your custom hook should simply print out the command that should be run to auto correct the offenses if it finds any. Hope that helps. |
@sds thanks for clarifying! It's definitely makes sense! |
Sorry that's not helpful at all. The |
@janwerkhoven What @sds explained above is that preserving file modifications during hook runs would require a significant overhaul of Overcommit's internals, and it just isn't worth it to support this one use-case. Especially when you can accomplish the same thing by just running |
We're tracking adding support for pre-commit hooks with file-changing side effects in #238. It's definitely something we know will be useful. Open to well-tested pull requests for those who want it sooner rather than later! |
I try to use rubocop with
-a
(--auto-correct
) option to fix all minor issues automatically.I try to put in the
.overcommit.yml
file strings likeBut it's not apply fixes to files before commit.
So, questions is:
How to run
rubocop -a
before pre-commit checks automatically? Is there any option for it in overcommit project?The text was updated successfully, but these errors were encountered: