Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 1 | # Pre-commit (https://pre-commit.com) configuration for assorted lint checks. |
| 2 | # |
| 3 | # See https://pre-commit.com/hooks.html for more hooks. |
| 4 | |
| 5 | exclude: "third_party/" |
| 6 | |
| 7 | repos: |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 8 | - repo: https://github.com/pre-commit/pre-commit-hooks |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 9 | rev: v3.2.0 |
| 10 | hooks: |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 11 | - id: check-merge-conflict |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 12 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 13 | - id: check-yaml |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 14 | # * Extensions can't be included in the mkdocs schema, so skip checking |
| 15 | # https://github.com/squidfunk/mkdocs-material/issues/6378 |
| 16 | # * clang-format files use `---` to split for multiple languages, |
| 17 | # resulting in errors like `expected a single document in the stream` |
| 18 | exclude: "mkdocs.yml|.clang-format" |
| 19 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 20 | - id: end-of-file-fixer |
Scott Todd | f4cfb55 | 2024-06-10 09:25:54 -0700 | [diff] [blame] | 21 | exclude_types: ["image", "jupyter"] |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 22 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 23 | - id: trailing-whitespace |
Scott Todd | f4cfb55 | 2024-06-10 09:25:54 -0700 | [diff] [blame] | 24 | exclude_types: ["image", "jupyter"] |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 25 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 26 | - repo: https://github.com/psf/black |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 27 | rev: 23.3.0 |
| 28 | hooks: |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 29 | - id: black |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 30 | name: Run Black to format Python files |
| 31 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 32 | - repo: https://github.com/pre-commit/mirrors-clang-format |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 33 | # Loosely track the most recent versions in |
| 34 | # * Runner images: https://github.com/actions/runner-images/ |
| 35 | # * Editor extensions: https://github.com/microsoft/vscode-cpptools |
| 36 | rev: v18.1.3 |
| 37 | hooks: |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 38 | - id: clang-format |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 39 | name: Run clang-format on C/C++/etc. files |
| 40 | exclude_types: ["jupyter"] |
| 41 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 42 | - repo: https://github.com/igorshubovych/markdownlint-cli |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 43 | rev: v0.41.0 |
| 44 | hooks: |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 45 | - id: markdownlint |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 46 | name: Run markdownlint on .md files |
| 47 | args: ["--config", "docs/.markdownlint.yml"] |
| 48 | files: "docs/website/.*.md" |
| 49 | exclude: "mlir-dialects/!(index).md" |
| 50 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 51 | - repo: https://github.com/Lucas-C/pre-commit-hooks |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 52 | rev: v1.5.5 |
| 53 | hooks: |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 54 | - id: forbid-tabs |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 55 | exclude: ".gitmodules|Makefile" |
| 56 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 57 | - repo: https://github.com/jlebar/pre-commit-hooks.git |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 58 | rev: f2d115a052860b09b2888b4f104be614bf3b4779 |
| 59 | hooks: |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 60 | - id: do-not-submit |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 61 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 62 | - repo: local |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 63 | hooks: |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 64 | - id: buildifier |
Scott Todd | 5404ad7 | 2024-06-06 09:58:23 -0700 | [diff] [blame] | 65 | name: Run buildifier |
| 66 | entry: buildifier |
| 67 | language: golang |
| 68 | # Pinned to v7.1.2, but of course we can't use a tag because semver |
| 69 | # and "go install" just don't work together??? |
| 70 | # This makes absolutely no sense and the maintainers have no intention |
| 71 | # of improving it or at least explaining it as hundreds of developers |
| 72 | # search for basic support: https://github.com/golang/go/issues/35732. |
| 73 | # Docs are technically at https://go.dev/ref/mod#go-install ¯\_(ツ)_/¯ |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 74 | additional_dependencies: |
| 75 | [ |
| 76 | "github.com/bazelbuild/buildtools/buildifier@1429e15ae755a6762d0edf9198062dc6ed04408d", |
| 77 | ] |
Scott Todd | 5404ad7 | 2024-06-06 09:58:23 -0700 | [diff] [blame] | 78 | files: '^(.*/)?(BUILD\.bazel|BUILD|WORKSPACE|WORKSPACE\.bazel|WORKSPACE\.bzlmod|MODULE\.bazel)$|\.BUILD$|\.bzl$' |
| 79 | # Pin the language version so other system version are _not_ used. |
| 80 | # Older go versions used different syntax for "go install" (which is |
| 81 | # apparently different from "go get" and "go build"), so for this to |
| 82 | # work reliably at all we need to ensure at least some minimum. Syntax |
| 83 | # probably changed again in a future version, whatever. |
| 84 | language_version: "1.16" |
| 85 | |
Scott Todd | 62bccc9 | 2024-12-04 10:07:10 -0800 | [diff] [blame] | 86 | # Convert BUILD.bazel files to CMakeLists.txt files in two passes to |
| 87 | # avoid potential race conditions. |
| 88 | # Note: this passes file names to the tool. The tool can also be run |
| 89 | # manually with no arguments specified to walk directories on its own. |
| 90 | # Keep the top level directories here in sync with .bazel_to_cmake.cfg.py. |
| 91 | - id: bazel_to_cmake_1 |
| 92 | name: Run bazel_to_cmake.py on BUILD.bazel files |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 93 | language: python |
| 94 | entry: ./build_tools/bazel_to_cmake/bazel_to_cmake.py |
Scott Todd | 62bccc9 | 2024-12-04 10:07:10 -0800 | [diff] [blame] | 95 | files: '^(compiler|runtime|samples|tests|tools)/(.*/)?(BUILD\.bazel)$' |
| 96 | - id: bazel_to_cmake_2 |
| 97 | name: Run bazel_to_cmake.py on CMakeLists.txt files |
| 98 | language: python |
| 99 | entry: ./build_tools/bazel_to_cmake/bazel_to_cmake.py |
| 100 | files: "^(compiler|runtime|samples|tests|tools)/(.*/)?(CMakeLists.txt)$" |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 101 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 102 | - id: check_path_lengths |
Scott Todd | d68a859 | 2024-06-07 14:18:32 -0700 | [diff] [blame] | 103 | name: Check for excessively long path lengths |
| 104 | language: fail |
| 105 | entry: Path lengths relative to the root should be < 75 characters (run ./build_tools/scripts/check_path_lengths.py for detailed output) |
| 106 | # The regex includes/excludes here should roughly match the behavior of |
| 107 | # the check_path_lengths.py script. |
| 108 | files: '^compiler/.{66,}/\w+\.' |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 109 | exclude: "test/" |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 110 | |
Scott Todd | 9b05f17 | 2024-08-14 10:55:09 -0700 | [diff] [blame] | 111 | - id: build_file_names |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 112 | name: Check Bazel file names |
| 113 | entry: Files should be named BUILD.bazel instead of BUILD |
| 114 | language: fail |
| 115 | files: "BUILD$" |
| 116 | |
Scott Todd | 2baf6c3 | 2024-06-07 14:44:37 -0700 | [diff] [blame] | 117 | # TODO(scotttodd): mypy type checking for Python (https://mypy-lang.org/) |