我可以通过传递 git commit 标志来忽略 flake8 错误吗?

CIs*_*ies 3 git pre-commit-hook pre-commit.com

我有一个flake8:check todo预提交挂钩,我现在想忽略它。

git commit --no-verify如果我确实希望所有其他挂钩运行,我可以忽略一切

我也可以编辑我的.pre-commit-hooks.yaml以删除相关的挂钩,但我确实想要它。只是现在不...

是否可以仅针对此提交/推送跳过挂钩检查?


我的配置.pre-commit-config.yaml:

default_language_version:
    python: python3.6
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.1.0 # 4.2.0 drops python<3.7
  hooks:
  - id: check-added-large-files
  - id: check-case-conflict
  - id: check-docstring-first
  - id: check-executables-have-shebangs
  - id: check-toml
  - id: check-merge-conflict
  - id: check-yaml
  - id: debug-statements
  - id: end-of-file-fixer
  - id: mixed-line-ending
  - id: sort-simple-yaml
  - id: trailing-whitespace
- repo: local
  hooks:
  - id: todo
    name: Check TODO
    language: pygrep
    args: [-i]
    entry: TODO
    types: [text]
    exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
- repo: https://gitlab.com/pycqa/flake8
  rev: 3.9.2
  hooks:
  - id: flake8
    # P103 - disallows "{}" in strings
    # E203 - ":" with whitespace before it
    # E501 - line length (black will handle most of the issues, and what it can't - should be ingored)
    args: ["-j8", "--ignore=E203,E501,P103"]
    additional_dependencies:
    - flake8-broken-line
    - flake8-bugbear
    - flake8-comprehensions
    - flake8-debugger
    - flake8-string-format
- repo: https://github.com/PyCQA/isort
  rev: 5.10.1
  hooks:
  - id: isort
    args: ["--profile", "black"] # solves conflicts between black and isort
- repo: https://github.com/psf/black
  hooks:
  - id: black
  rev: 22.3.0
Run Code Online (Sandbox Code Playgroud)

Per*_*rfi 6

这实际上是文档中描述的确切情况:

并非所有钩子都是完美的,因此有时您可能需要跳过一个或多个钩子的执行。预提交通过查询 SKIP 环境变量来解决这个问题。SKIP 环境变量是一个逗号分隔的钩子 ID 列表。这允许您跳过单个挂钩,而不是 --no-verifying 整个提交。

$ SKIP=flake8 git commit -m "foo"
Run Code Online (Sandbox Code Playgroud)