如何在预提交中排除多个目录

问题描述 投票:0回答:1

我想通过预提交忽略多个文件模式。例如 'migrations/.' 和 'tests/.' 预提交配置文件中可用的排除参数只接受字符串而不是列表。我当前的配置文件:

.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/.*'

尝试将排除项更改为列表并放入 2 个排除项类别。两者都是无效配置

exclude: 
- 'migrations/.*'
- 'tests/.*'
exclude: 'migrations/.*'
exclude: 'tests/.*'
pre-commit pre-commit.com
1个回答
0
投票

我找到了问题的答案:

要匹配多个模式,请使用

|
正则表达式运算符:

exclude: 'migrations/.*|tests/.*'

也可以工作:

exclude: '(migrations|tests)/.*'

如果要匹配的模式很多,可以使用多行正则表达式格式:

exclude: |
    (?x)^(
        migrations/.*|
        tests/.*
    )$
© www.soinside.com 2019 - 2024. All rights reserved.