Excluding paths via pre-commit / wrongly targeted files
Closed this issue · 4 comments
Description
Dear @adamchainz
Thx for this amazing package! Just threw it on a 12 year old codebase and it looks great!
Just one thing that came up: I use helm charts in my repo and it started reformatting a file in charts/my-project/templates
. The odd thing is, the file is no HTML file but a .tpl
.
I'm not that familiar with pre-commit (I just use it 😅 ) and wasn't able to configure it.
I see two scenarios here:
- Maybe it targets *.tpl files by accient?
- Maybe I have to configure that I don't want the helm charts directory. Then, for other people as stupid as me, a hint in the Readme on how to do that would be amazing
Supplemental: It also tries rewriting this file: Rewriting apps/account/tests/templates/test_template_employee_detail.py
Thx for all the hard work! ❤️
Ronny
The default configuration targets all files in all directories called templates
. (And I just pushed this commit that will limit it to text files in the next release.)
It's deliberately not limited to HTML files because templates are often used for other file formats too, like text files for emails or CSS for user-customizable themes.
You can exclude your problematic files like:
- repo: https://github.com/adamchainz/djade-pre-commit
rev: 1.0.0
hooks:
- id: djade
exclude: |
(?x)^(
charts/.*
|.*\.py
)$
I will look at writing a blog post on pre-commit's exclusion mechanisms, then linking it.
That works great! I tried out v1.1.0 and still my Pyton file named something_template.py
got discovered and is a wontfix. It will show up every time I run the formatter (unless I set the exclude).
Since I might not be the only one with this issue, to improve DX, do you think we should add the exclude: *.py
configuration to the docs? Maybe as a default?
And really looking forward to the blog article! I know that I know way too little about these things. ❤️
That works great! I tried out v1.1.0 and still my Pyton file named something_template.py got discovered and is a wontfix. It will show up every time I run the formatter (unless I set the exclude).
Since I might not be the only one with this issue, to improve DX, do you think we should add the
exclude: *.py
configuration to the docs? Maybe as a default?
It's still matching with the above config? The .*\.py
bit should exclude it.
Yes, I think we could add an exclusion in the pre-commit repo, but as exclude_types: [python]
. There are some use cases for putting Python files in template directories.
No worries, it works now just fine with your regex. Thx for that!
Yes, I think we could add an exclusion in the pre-commit repo, but as exclude_types: [python]. There are some use cases for putting Python files in template directories.
Hm, true. Maybe add a hint in the Readme to prime folks on that issue? 🤔