GitHub 代码规范管理:pre-commit 代码检查器 入门使用介绍

如何让每次git commit -m xxx 会自动检查代码格式和规范问题
  1. 安装
    pip install pre-commit
    
  2. 配置.yaml文件

    在git项目的根目录创建一个.pre-commit-config.yaml 文件

    例如:

    # See https://pre-commit.com for more information
    # See https://pre-commit.com/hooks.html for more hooks
    repos:
    -   repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v2.4.0
        hooks:
        -   id: check-xml
        -   id: check-added-large-files
        -   id: check-byte-order-marker
    -   repo: https://gitlab.com/pycqa/flake8
        rev: '3.7.9'
        hooks:
        -   id: flake8
    -   repo: https://github.com/codespell-project/codespell
        rev: v1.16.0
        hooks:
        -   id: codespell
    
  3. 在终端执行下述命令
    pre-commit install
    
  4. 即可实现,每次git commit -m xxxx 代码自动检查

    具体检查统一的代码格式要求,可以在上述.yaml文件中设置

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐