Skip to content
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

Fix wrong target for sort-simple-yaml #1113

Closed
wants to merge 1 commit into from
Closed

Conversation

ctcjab
Copy link

@ctcjab ctcjab commented Dec 11, 2024

Configure sort-simple-yaml to apply to only yaml files.

Configure sort-simple-yaml to apply to only yaml files.
@asottile
Copy link
Member

if you read the docs for this hook you'll understand why the default is the way it is

@asottile asottile closed this Dec 11, 2024
@ctcjab
Copy link
Author

ctcjab commented Dec 13, 2024

Where are the docs you're referring to? I had already read the docstrings in https://github.com/pre-commit/pre-commit-hooks/blob/main/pre_commit_hooks/sort_simple_yaml.py and they all talk about YAML files, there is no mention that this hook is meant for other filetypes.

@asottile
Copy link
Member

the README is typically the place to look first

@ctcjab
Copy link
Author

ctcjab commented Dec 13, 2024

Note that sort-simple-yaml by default matches no files as it enforces a very specific format. You must opt in to this by setting files

I see what happened: Whoever set this hook up in the monorepo where I hit this did so via files: ^our_team_subdirectory/ and did not include any extension matching in that regex (e.g. [^.]+\.ya?ml$ at the end), so it ended up unintentionally rewriting .py files. Perhaps this person made the reasonable assumption that this hook was already limiting itself to yaml files.

I already fixed the regex in our repo (before even submitting this PR). I am still wondering if it makes sense to accept this PR – would including the types: [yaml] here not make it easier to use this hook? And match the docstrings better, which indicate the hook is only intended to target yaml files?

@asottile
Copy link
Member

no it would make it more difficult in the case that you used this on a file which identify doesn't recognize as yaml -- and usually files is sufficient in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants