-
Notifications
You must be signed in to change notification settings - Fork 11
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
Feature request: Commit formatted files automatically in a pre commit hook #22
Comments
Personally I don't have that much trust in resharper and I'm not sure I want to add an option that encourages this. I think best practice is to abort the commit if formatting is needed. If you add the --fail-on-diff option it will abort the commit and allow you to review the modifications, edit if necessary, then re-stage and commit. If you really want to throw caution to the wind. You could probably change your pre-commit hook to perform the steps you described. Something like this: dotnet regitlint -f staged --format-only
Resharper modifies and writes the files to disk. You don't need to save anything manually. What your describing sounds like a behavior of your IDE or the git plugin for your IDE. |
It's not so bad if used with I believe this feature request has a lot of value (I would definitely use it with A useful feature would be a new flag such as
This way the stray newline or missing newline at the end of the file just get fixed but more substantial changes like renaming a variable still stops the commit. I have experienced multiple teams across multiple repos use a similar commit workflow in the JavaScript world (implemented with ESLint and Husky). |
@benrobot Thanks for chiming in. On occasion resharper will get confused when a dependency fails to build resulting in using statements incorrectly getting removed. That was my first thought when this idea was mentioned. I think --format-only addresses that. No surprise that risky behavior is acceptable in the js world though. Auto formatting on commit is probably no riskier than running |
Is it possible to use ReGitLint in a way to auto-commit formatted file?
I'm currently using this in my pre-commit hook:
dotnet regitlint -f staged --format-only
But all it does when executing is commiting the unformated files. The format fixes are applied to the files, but then I have to save all modified files manually to make them appear as unstaged changes. Is there a way to format all files, save the changes, stage the changed made by ReGitLint and commit them using only one commit?
The text was updated successfully, but these errors were encountered: