1.安装
pip install pre-commit
2.在项目的根目录下创建 .pre-commit-config.yaml文件(根据项目的需要配置),内容如下:
repos:
#代码格式化
- repo: https://github.com/python/black
rev: 22.1.0
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
#对json文件内容进行格式化
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.1
hooks:
- id: prettier
files: ^mark_data/
types: [json]
args: ["--print-width", "12"]