From e150e032e9c6942befc5a90aafe6be3a01d57938 Mon Sep 17 00:00:00 2001 From: Tom Weininger Date: Wed, 21 Sep 2022 16:31:59 +0200 Subject: [PATCH] Add pre-commit Change-Id: I3fda3d18cea0e22e2999481551429122619b2144 --- .pre-commit-config.yaml | 32 ++++++++++++++++++++++++++++++++ HACKING.rst | 15 +++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..1994034f89 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,32 @@ +# 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: 3298ddab3c13dd77d6ce1fc0baf97691430d84b0 # v4.3.0 + hooks: + - id: trailing-whitespace + # Replaces or checks mixed line ending + - id: mixed-line-ending + args: ['--fix', 'lf'] + exclude: '.*\.(svg)$' + - id: end-of-file-fixer + # Forbid files which have a UTF-8 byte-order marker + - id: check-byte-order-marker + # Checks that non-binary executables have a proper shebang + - id: check-executables-have-shebangs + # Check for files that contain merge conflict strings. + - id: check-merge-conflict + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + - id: check-added-large-files +- repo: local + hooks: + - id: flake8 + name: flake8 + additional_dependencies: + - hacking>=3.1.0,<3.2.0 + language: python + entry: flake8 + files: '^.*\.py$' + exclude: '^(doc|releasenotes|tools)/.*$' diff --git a/HACKING.rst b/HACKING.rst index bb18b28f1e..d0adf6c709 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -149,3 +149,18 @@ By "industry standards" we either mean RFCs or well-established best practices. We are generally not interested in defining new standards if a prior open standard already exists. We should also avoid doing things which directly or indirectly contradict established standards. + +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/