Pre-commit-hook ignores exclude patterns
See original GitHub issueMy team wants to try black as a pre-commit hook on a provisional basis, so we run it only on files in one directory of the project as we develop a new feature.
While configuring this, I discovered that black seems to ignore inclusion/exclusion rules completely if it’s given a path to a file not a folder. Since the input to a pre-commit hook is a list of modified/created filepaths, all or our lovely inclusion/exclusion rules get ignored completely and that makes us sad 😦
I’m not familiar enough with the code to have a good gauge of this, but how much work do you think it would be to add support for this?
Thanks for the cool tool!! P.S. Personally, I’d take the leap and format the whole repo, but I’m not alone in this world 😉
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:15 (5 by maintainers)
Top Results From Across the Web
Exclude some files on running black using pre-commit
pre -commit finds all the python files, then applies pre-commit 's exclusion, and then passes that list of files to the underlying tools...
Read more >pre-commit
We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements....
Read more >Can I Exclude Files From Every Precommit Hook Except For One
The behavior we'd like to see is that black's exclude regex would apply even when full Precommithook ignores exclude patterns #395. Coding can...
Read more >pre-commit-config.yaml - platform/external/python/pybind11
repo: https://github.com/pre-commit/pre-commit-hooks. rev: v3.4.0. hooks: ... By default, this ignores pyi files, though black supports them. types: [text].
Read more >git-check-ignore Documentation - Git
(Matching an exclude pattern usually means the path is excluded, but if the pattern begins with " ! " then it is a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you’re using pre-commit you can control the inclusion / exclusion by using
files/excludein thepre-commitconfiguration.For example:
(etc. etc.)
Say you want to exclude both
^foo/and^bar/you can combine them with|(naively:(^foo/|^bar/))You can also mark your regex as verbose and write a multiline regex: