I have multiple file patterns I want to ignore with pre-commit. For example 'migrations/.' and 'tests/.' The exclude parameter available in the pre-commit configuration file only accepts a string and not a list though. My current configuration file:
.pre-commit-config.yaml
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
language_version: python3.8
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
exclude: 'migrations/.*'
Tried changing exclude to a list and also putting in 2 exclude categories. Both were invalid configuations
exclude:
- 'migrations/.*'
- 'tests/.*'
exclude: 'migrations/.*'
exclude: 'tests/.*'
I found an answer to my question:
To match multiple patterns use the |
regex operator:
exclude: 'migrations/.*|tests/.*'
Also would work:
exclude: '(migrations|tests)/.*'
If there are a lot of patterns to match there is a multi-line regex format:
exclude: |
(?x)^(
migrations/.*|
tests/.*
)$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With