|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Summary: config for setting up git hooks using the pre-commit framework. This |
| 16 | +# is optional and NOT set up by default nor used by the scripts in check/. Here |
| 17 | +# is a suggested installation approach; after doing this, the pre-commit hooks |
| 18 | +# will be called automatically by git at the appropriate times: |
| 19 | +# |
| 20 | +# pip install pre-commit |
| 21 | +# pre-commit install -t pre-commit -t commit-msg -t pre-push |
| 22 | +# pre-commit run |
| 23 | + |
| 24 | +default_stages: |
| 25 | + - pre-commit |
| 26 | + |
| 27 | +# Note: these are Python regular expressions matched with re.search. |
| 28 | +exclude: | |
| 29 | + (?x)^( |
| 30 | + .*\.egg-info/.* | |
| 31 | + .*\.h5 | |
| 32 | + .*\.ipynb_checkpoints(/.*)? | |
| 33 | + .*\.log | |
| 34 | + .*\.out | |
| 35 | + .*\.pytest_cache/.* | |
| 36 | + .*__pycache__/.* | |
| 37 | + .env/.* | |
| 38 | + .venv/.* | |
| 39 | + \.([^/]*cache/.*) | |
| 40 | + \.coverage(\..*)? | |
| 41 | + docs/_build/.* | |
| 42 | + venv/.* |
| 43 | + )$ |
| 44 | +
|
| 45 | +fail_fast: true |
| 46 | + |
| 47 | +minimum_pre_commit_version: '4.4.0' |
| 48 | + |
| 49 | +repos: |
| 50 | +# ~~~~ Pre-commit hooks ~~~~ |
| 51 | + |
| 52 | + - repo: https://github.com/pre-commit/pre-commit-hooks |
| 53 | + rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0 |
| 54 | + hooks: |
| 55 | + # Note: don't use check-yaml bc it doesn't read the yamllint config. |
| 56 | + # Use separate yamllint hook later in this file. |
| 57 | + |
| 58 | + - id: no-commit-to-branch |
| 59 | + name: 'Check that the commit is not made to the main branch' |
| 60 | + args: [--branch, main, --branch, master] |
| 61 | + |
| 62 | + - id: check-merge-conflict |
| 63 | + name: "Check that files are free of merge git conflict strings" |
| 64 | + |
| 65 | + - id: check-illegal-windows-names |
| 66 | + name: "Check that file names can be used on Windows" |
| 67 | + |
| 68 | + - id: check-case-conflict |
| 69 | + name: "Check that file names won't conflict on case-insensitive systems" |
| 70 | + |
| 71 | + - id: name-tests-test |
| 72 | + name: 'Verify test files are named correctly' |
| 73 | + |
| 74 | + - id: check-symlinks |
| 75 | + name: 'Check for symlinks that do not point to anything' |
| 76 | + |
| 77 | + - id: destroyed-symlinks |
| 78 | + name: 'Check that symlinks are not turned into regular files' |
| 79 | + |
| 80 | + - id: check-shebang-scripts-are-executable |
| 81 | + name: 'Check that shell script files are executable' |
| 82 | + |
| 83 | + - id: debug-statements |
| 84 | + name: 'Check that Python files are free of debug statements' |
| 85 | + |
| 86 | + - id: check-toml |
| 87 | + name: 'Check TOML files for valid syntax' |
| 88 | + |
| 89 | + - id: check-xml |
| 90 | + name: 'Check XML files for valid syntax' |
| 91 | + |
| 92 | + - repo: https://github.com/adrienverge/yamllint |
| 93 | + rev: cba56bcde1fdd01c1deb3f945e69764c291a6530 # frozen: v1.38.0 |
| 94 | + hooks: |
| 95 | + - id: yamllint |
| 96 | + name: 'Run YAML linter' |
| 97 | + files: \.(yaml|yml|cff)$ |
| 98 | + args: [--format=colored, --no-warnings] |
| 99 | + |
| 100 | + - repo: https://github.com/python-jsonschema/check-jsonschema |
| 101 | + rev: 'ed81924a8b1cecdaa570b072528fa80c9c4d6ccd' # frozen: 0.37.1 |
| 102 | + hooks: |
| 103 | + - id: check-jsonschema |
| 104 | + name: 'Check that Jupyter notebooks are valid JSON' |
| 105 | + types: [jupyter] |
| 106 | + files: '.*\.ipynb$' |
| 107 | + # Note: pre-commit will download & cache this file automatically. |
| 108 | + # yamllint disable rule:line-length |
| 109 | + args: [--schemafile, https://raw.githubusercontent.com/jupyter/nbformat/refs/heads/main/nbformat/v4/nbformat.v4.0.schema.json] |
| 110 | + |
| 111 | + - repo: https://github.com/jumanjihouse/pre-commit-hooks |
| 112 | + rev: '38980559e3a605691d6579f96222c30778e5a69e' # frozen: 3.0.0 |
| 113 | + hooks: |
| 114 | + - id: shellcheck |
| 115 | + name: 'Check shell scripts' |
| 116 | + files: '(\.sh$|^check/[^.]+$)' |
| 117 | + |
| 118 | + - repo: https://github.com/hadolint/hadolint |
| 119 | + rev: v2.14.0 |
| 120 | + hooks: |
| 121 | + - id: hadolint |
| 122 | + name: 'Check Docker files' |
| 123 | + files: (?i)dockerfile$ |
| 124 | + args: [--failure-threshold, error] |
| 125 | + |
| 126 | + # Note this is used for YAML files, despite that it's named "jsonschema". |
| 127 | + - repo: https://github.com/python-jsonschema/check-jsonschema |
| 128 | + rev: 'ed81924a8b1cecdaa570b072528fa80c9c4d6ccd' # frozen: 0.37.1 |
| 129 | + hooks: |
| 130 | + - id: check-github-workflows |
| 131 | + name: 'Check GitHub workflow files' |
| 132 | + |
| 133 | +# ~~~~ Commit message hooks ~~~~ |
| 134 | + |
| 135 | + - repo: https://github.com/crate-ci/typos |
| 136 | + rev: c96c46fae465ab9e3607401d9ce93d75e7998023 # frozen: v1 |
| 137 | + hooks: |
| 138 | + - id: typos |
| 139 | + name: 'Check commit message for typos' |
| 140 | + stages: [commit-msg] |
| 141 | + # Important: add "args: []" to prevent typos from autofixing your files. |
| 142 | + # C.f. https://github.com/crate-ci/typos/blob/master/docs/pre-commit.md |
| 143 | + args: [] |
| 144 | + |
| 145 | +# ~~~~ Pre-push hooks ~~~~ |
| 146 | + |
| 147 | + - repo: local |
| 148 | + hooks: |
| 149 | + - id: format-incremental |
| 150 | + name: 'Run check/format-incremental' |
| 151 | + entry: check/format-incremental |
| 152 | + language: script |
| 153 | + pass_filenames: false |
| 154 | + files: \.(cc|h|cu|py)$ |
| 155 | + stages: [pre-push] |
| 156 | + |
| 157 | + - repo: https://github.com/Pierre-Sassoulas/copyright_notice_precommit |
| 158 | + rev: 'd9215b6b2a028d1614c92cf43a9fcff3b1dd889e' # frozen: 0.1.2 |
| 159 | + hooks: |
| 160 | + - id: copyright-notice |
| 161 | + name: 'Check that files have a copyright notice' |
| 162 | + types: [python] |
| 163 | + stages: [pre-push] |
| 164 | + args: [--notice=dev_tools/apache-license-header.txt] |
| 165 | + |
| 166 | + - repo: https://github.com/tcort/markdown-link-check |
| 167 | + rev: ffc61540dea52bad1c41cfeedcf26c53ad9447ba # frozen: v3.14.2 |
| 168 | + hooks: |
| 169 | + - id: markdown-link-check |
| 170 | + name: 'Check Markdown file lint' |
| 171 | + types: [markdown] |
| 172 | + stages: [pre-push] |
| 173 | + |
| 174 | + - repo: https://github.com/pre-commit/pygrep-hooks |
| 175 | + rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316 # frozen: v1.10.0 |
| 176 | + hooks: |
| 177 | + - id: python-check-blanket-noqa |
| 178 | + name: 'Check that "# noqa" annotations include error codes' |
| 179 | + stages: [pre-push] |
| 180 | + |
| 181 | + - id: python-check-blanket-type-ignore |
| 182 | + name: 'Check that "# type: ignore" comments include error codes' |
| 183 | + stages: [pre-push] |
| 184 | + |
| 185 | + - id: python-check-mock-methods |
| 186 | + name: 'Check for common mistakes when using unittest.mock' |
| 187 | + stages: [pre-push] |
0 commit comments