add pre-commit

This tool provides a extensible way to configure pre-commit hooks
to do something from running linters to spell-checking and it proved
to be useful.

Change-Id: I77cf6c85559989bd051798e601640e0039342924
This commit is contained in:
suzhengwei 2023-05-30 17:22:23 +08:00
parent b2f2a58e3c
commit 6d77bc827a
2 changed files with 42 additions and 0 deletions

27
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,27 @@
---
default_language_version:
# force all unspecified python hooks to run python3
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: mixed-line-ending
args: ['--fix', 'lf']
exclude: '.*\.(svg)$'
- id: check-byte-order-marker
- id: check-merge-conflict
- id: debug-statements
- id: check-yaml
files: .*\.(yaml|yml)$
- repo: local
hooks:
- id: flake8
name: flake8
additional_dependencies:
- hacking>=3.0.1,<3.1.0
language: python
entry: flake8
files: '^.*\.py$'
exclude: '^(doc|releasenotes|tools)/.*$'

View File

@ -45,3 +45,18 @@ Masakari Specific Commandments
- [M332] Yield must always be followed by a space when yielding a value.
- [M333] Policy registration should be in the central location ``masakari/policies/``
- [M334] Do not use the oslo_policy.policy.Enforcer.enforce() method.
Use of pre-commit checks
------------------------
`pre-commit`_ is a software tool that allows us to manage pre-commit checks as
part of the Git repository's configuration
and to run checks as Git pre-commit hooks (or other types of Git hooks)
automatically on developer machines.
It helps to catch and fix common issues before they get pushed to the server.
After the installation of the tool (e.g. on Fedora via
`sudo dnf install pre-commit`) simply `cd` to the Git repository and run
`pre-commit install` to let the tool install its Git pre-commit hook.
From now on these predefined checks will run on files that you change in new
Git commits.
.. _pre-commit: https://pre-commit.com/