-
Notifications
You must be signed in to change notification settings - Fork 16
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
in_place = true doesn't work in pre-commit #39
Comments
Another easy way to fix would be to make a second pre-commit hook in .pre-commit-hooks.yaml called |
Thanks for clearly laying out this issue! I'm actually the opposite to you in that I almost always manually configure my hooks based on the locally-installed tooling. So, I don't really have a strong preference here as long as any resolution 1. doesn't negatively impact too many people, and 2. doesn't introduce too much complexity to the codebase. Based on the above requirements, I have a slight preference for your suggestion to create additional hooks. Seems like it'll preserve backwards compatibility without introducing any unintended behavioral changes. I'll happily consider a PR if you find time to create one! |
@pappasam any chance of a new release tag on github for the new pre-commit hook? pre-commit requires the tag on github as a version reference so the new hook is inaccessible until then. |
@wwuck sorry, done! |
I'm going through moving any config from .pre-commit-config.yaml into other config files wherever possible to make sure that running tools from terminal has the same result as running in the pre-commit hook.
So I changed from having:
to:
And adding the following to pyproject.toml
This then works fine when running something like
toml-sort pyproject.toml
and that fixes the file in-place.However, when I run the pre-commit hook it doesn't run the files in-place, it just uses the --check argument from https://github.com/pappasam/toml-sort/blob/main/.pre-commit-hooks.yaml instead as command line arguments take precedence over pyproject.toml arguments. This means that both check and in_place are True and as args.check is checked first (line 357 of cli.py) so my setting
in_place = true
basically has no effect.I'm not sure of the best way to fix this.
Having a standard args of --check for the pre-commit does make sense as either --check or --in-place needs to be defined when running multiple files. And defaulting to an option that doesn't result in overwritten files is best. But it would also be good if it was possible for the in_place setting in pyproject.toml to work when running toml-sort from pre-commit.
Maybe the easiest way is to change the tool behaviour so that if both in-place and check are true then it runs in-place, rather than check.
That would just mean swapping
to:
Obviously that is a fairly large change in behaviour, though I imagine very few people would have both --check and --in-place set other than in my scenario where in_place is set in pyproject.toml and --check is only being set as the default pre-commit args.
Obviously for now I can workaround this easily enough by changing the pre-commit args to define --in-place and not --check, but I would prefer not having to set the same setting twice.
The text was updated successfully, but these errors were encountered: