|
| 1 | +# |
| 2 | +# Installation and activation of pre-commit: |
| 3 | +# |
| 4 | +# $ pip3 install pre-commit && pre-commit install |
| 5 | +# |
| 6 | +# With this, you get git pre-commit hook checks like shown in the terminal |
| 7 | +# on this page: https://pre-commit.com/index.html#usage |
| 8 | +# |
| 9 | +# It is easy to handle as a pre-commit hook once you get the hang of it. |
| 10 | +# If not skipped using git commit --no-verify, it makes each commit bisect-able, |
| 11 | +# whereas a check only run on a GitHub CI push will normally only run its checks |
| 12 | +# on the latest commit of a tree. |
| 13 | +# |
| 14 | +# However, it does not have to be used as a pre-commit hook: |
| 15 | +# Of course it can be used just for GitHub CI only: |
| 16 | +# |
| 17 | +# pre-commit runs in the GitHub Workflow of this project on each push and PR. |
| 18 | +# You can run it locally as well on demand after making changes to check them: |
| 19 | +# |
| 20 | +# $ pip3 install pre-commit |
| 21 | +# $ pre-commit run # run only needed checks |
| 22 | +# $ pre-commit run -a # run all fixes and checks |
| 23 | +# |
| 24 | +# You can enable it as git pre-commit hook for your local clone using: |
| 25 | +# $ pre-commit install |
| 26 | +# |
| 27 | +# Then, the fixups and checks defined below run by default when you commit. |
| 28 | +# |
| 29 | +# To commit with all git pre-commit hooks skipped (for exceptional cases): |
| 30 | +# $ git commit --no-verify |
| 31 | +# |
| 32 | +# To commit with some checks skipped: |
| 33 | +# $ SKIP=mypy,pylint git commit -m "unchecked emergency commit" |
| 34 | +# |
| 35 | +# Documentation: https://pre-commit.com/#temporarily-disabling-hooks |
| 36 | +# All hooks: https://pre-commit.com/hooks.html |
| 37 | +# |
| 38 | +fail_fast: false |
| 39 | +default_stages: [commit, push] |
| 40 | +repos: |
| 41 | +- repo: https://github.com/pre-commit/pre-commit-hooks |
| 42 | + rev: v4.5.0 |
| 43 | + # https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md: |
| 44 | + hooks: |
| 45 | + - id: no-commit-to-branch |
| 46 | + name: "ensure that you don't commit to the local master branch" |
| 47 | + args: [--branch, master] |
| 48 | + always_run: true |
| 49 | + - id: trailing-whitespace |
| 50 | + name: 'check and fix files to have no trailing whitespace' |
| 51 | + exclude: install-sh |
| 52 | + - id: end-of-file-fixer |
| 53 | + name: 'check and fix that files have a trailing newline' |
| 54 | + exclude: | |
| 55 | + (?x)^( |
| 56 | + arch/x86/include/arch/msr-index.h |
| 57 | + ) |
| 58 | + - id: mixed-line-ending |
| 59 | + args: ['--fix=lf'] |
| 60 | + name: 'check and fix that line endings are line feeds' |
| 61 | + - id: check-added-large-files |
| 62 | + args: ['--maxkb=12'] |
| 63 | + name: 'check that no large files are added' |
| 64 | + - id: check-executables-have-shebangs |
| 65 | + - id: debug-statements |
| 66 | + name: 'check for debugger imports and breakpoint calls' |
| 67 | + - id: check-shebang-scripts-are-executable |
| 68 | + - id: check-merge-conflict |
| 69 | + - id: check-yaml |
| 70 | + name: 'check the syntax of yaml files' |
| 71 | +- repo: local |
| 72 | + hooks: |
| 73 | + - id: pytest |
| 74 | + name: run Python3 unit tests |
| 75 | + entry: env PYTHONDEVMODE=yes python3 -m pytest -v |
| 76 | + pass_filenames: false |
| 77 | + language: python |
| 78 | + types: [python] |
| 79 | + additional_dependencies: [pytest] |
| 80 | +- repo: https://github.com/akaihola/darker |
| 81 | + rev: 1.7.2 |
| 82 | + hooks: |
| 83 | + - id: darker |
| 84 | + name: format staged changes like black and isort would format them |
| 85 | + args: [--skip-string-normalization, --isort, -tpy36] |
| 86 | + additional_dependencies: [isort] |
| 87 | +- repo: https://github.com/pre-commit/mirrors-mypy |
| 88 | + rev: v1.8.0 |
| 89 | + hooks: |
| 90 | + - id: mypy |
| 91 | + name: run mypy |
| 92 | +- repo: https://github.com/pylint-dev/pylint |
| 93 | + rev: v3.0.3 |
| 94 | + hooks: |
| 95 | + - id: pylint |
| 96 | + name: run pylint |
| 97 | + args: [--jobs=4, --spelling-dict=en_US] # Spell checks: See .pylintrc |
| 98 | + files: '(^xtf-runner|\.py)$' |
| 99 | + log_file: ".git/pre-commit-pylint.log" |
| 100 | + additional_dependencies: ['pylint[spelling]', pytest] |
| 101 | +- repo: local |
| 102 | + hooks: |
| 103 | + - id: git-diff # Ref: https://github.com/pre-commit/pre-commit/issues/1712 |
| 104 | + name: Show and fail on not staged changes, also fixups may make them |
| 105 | + entry: git diff --exit-code |
| 106 | + language: system |
| 107 | + pass_filenames: false |
| 108 | + always_run: true |
0 commit comments