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: |
| 8 | |
| 9 | - repo: https://github.com/pre-commit/pre-commit-hooks |
| 10 | rev: v3.2.0 |
| 11 | hooks: |
| 12 | - id: check-merge-conflict |
| 13 | |
| 14 | - id: check-yaml |
| 15 | # * Extensions can't be included in the mkdocs schema, so skip checking |
| 16 | # https://github.com/squidfunk/mkdocs-material/issues/6378 |
| 17 | # * clang-format files use `---` to split for multiple languages, |
| 18 | # resulting in errors like `expected a single document in the stream` |
| 19 | exclude: "mkdocs.yml|.clang-format" |
| 20 | |
| 21 | # TODO(scotttodd): enable once enough contributors are familiar with pre-commit |
| 22 | # - id: end-of-file-fixer |
| 23 | # exclude_types: ["image", "jupyter"] |
| 24 | |
| 25 | # TODO(scotttodd): enable once enough contributors are familiar with pre-commit |
| 26 | # - id: trailing-whitespace |
| 27 | # exclude_types: ["image", "jupyter"] |
| 28 | |
| 29 | - repo: https://github.com/psf/black |
| 30 | rev: 23.3.0 |
| 31 | hooks: |
| 32 | - id: black |
| 33 | name: Run Black to format Python files |
| 34 | |
| 35 | - repo: https://github.com/pre-commit/mirrors-clang-format |
| 36 | # Loosely track the most recent versions in |
| 37 | # * Runner images: https://github.com/actions/runner-images/ |
| 38 | # * Editor extensions: https://github.com/microsoft/vscode-cpptools |
| 39 | rev: v18.1.3 |
| 40 | hooks: |
| 41 | - id: clang-format |
| 42 | name: Run clang-format on C/C++/etc. files |
| 43 | exclude_types: ["jupyter"] |
| 44 | |
| 45 | - repo: https://github.com/igorshubovych/markdownlint-cli |
| 46 | rev: v0.41.0 |
| 47 | hooks: |
| 48 | - id: markdownlint |
| 49 | name: Run markdownlint on .md files |
| 50 | args: ["--config", "docs/.markdownlint.yml"] |
| 51 | files: "docs/website/.*.md" |
| 52 | exclude: "mlir-dialects/!(index).md" |
| 53 | |
| 54 | - repo: https://github.com/Lucas-C/pre-commit-hooks |
| 55 | rev: v1.5.5 |
| 56 | hooks: |
| 57 | - id: forbid-tabs |
| 58 | exclude: ".gitmodules|Makefile" |
| 59 | |
| 60 | - repo: https://github.com/jlebar/pre-commit-hooks.git |
| 61 | rev: f2d115a052860b09b2888b4f104be614bf3b4779 |
| 62 | hooks: |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 63 | - id: do-not-submit |
| 64 | |
| 65 | - repo: local |
| 66 | hooks: |
Scott Todd | 5404ad7 | 2024-06-06 09:58:23 -0700 | [diff] [blame] | 67 | - id: buildifier |
| 68 | name: Run buildifier |
| 69 | entry: buildifier |
| 70 | language: golang |
| 71 | # Pinned to v7.1.2, but of course we can't use a tag because semver |
| 72 | # and "go install" just don't work together??? |
| 73 | # This makes absolutely no sense and the maintainers have no intention |
| 74 | # of improving it or at least explaining it as hundreds of developers |
| 75 | # search for basic support: https://github.com/golang/go/issues/35732. |
| 76 | # Docs are technically at https://go.dev/ref/mod#go-install ¯\_(ツ)_/¯ |
| 77 | additional_dependencies: ["github.com/bazelbuild/buildtools/buildifier@1429e15ae755a6762d0edf9198062dc6ed04408d"] |
| 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 | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 86 | - id: bazel_to_cmake |
| 87 | name: Run bazel_to_cmake.py |
| 88 | language: python |
Scott Todd | d68a859 | 2024-06-07 14:18:32 -0700 | [diff] [blame] | 89 | # Note: this passes file names to the tool. The tool can also be run |
| 90 | # manually with no arguments specified to walk directories on its own. |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 91 | entry: ./build_tools/bazel_to_cmake/bazel_to_cmake.py |
Scott Todd | d68a859 | 2024-06-07 14:18:32 -0700 | [diff] [blame] | 92 | # Keep the top level directories here in sync with .bazel_to_cmake.cfg.py. |
| 93 | files: '^(compiler|runtime|samples|tests|tools)/(.*/)?(BUILD\.bazel|CMakeLists.txt)$' |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 94 | |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 95 | - id: check_path_lengths |
Scott Todd | d68a859 | 2024-06-07 14:18:32 -0700 | [diff] [blame] | 96 | name: Check for excessively long path lengths |
| 97 | language: fail |
| 98 | entry: Path lengths relative to the root should be < 75 characters (run ./build_tools/scripts/check_path_lengths.py for detailed output) |
| 99 | # The regex includes/excludes here should roughly match the behavior of |
| 100 | # the check_path_lengths.py script. |
| 101 | files: '^compiler/.{66,}/\w+\.' |
| 102 | exclude: 'test/' |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 103 | |
| 104 | - id: build_file_names |
| 105 | name: Check Bazel file names |
| 106 | entry: Files should be named BUILD.bazel instead of BUILD |
| 107 | language: fail |
| 108 | files: "BUILD$" |
| 109 | |
Scott Todd | 2baf6c3 | 2024-06-07 14:44:37 -0700 | [diff] [blame^] | 110 | # TODO(scotttodd): mypy type checking for Python (https://mypy-lang.org/) |
| 111 | |
Scott Todd | 778d00d | 2024-06-03 10:34:40 -0700 | [diff] [blame] | 112 | # TODO(scotttodd): enable these checks when they work on Windows |
| 113 | # the generator scripts use \ on Windows instead of / |
| 114 | |
| 115 | # - id: generate_cmake_e2e_test_artifacts_suite |
| 116 | # name: Run generate_cmake_e2e_test_artifacts_suite.py |
| 117 | # language: python |
| 118 | # entry: ./build_tools/testing/generate_cmake_e2e_test_artifacts_suite.py |
| 119 | # args: ["--output_dir", "./tests/e2e/test_artifacts"] |
| 120 | # # TODO(scotttodd): run only on relevant files |
| 121 | # always_run: true |
| 122 | # pass_filenames: false |
| 123 | |
| 124 | # - id: generate_cmake_e2e_model_tests |
| 125 | # name: Run generate_cmake_e2e_model_tests.py |
| 126 | # language: python |
| 127 | # entry: ./build_tools/testing/generate_cmake_e2e_model_tests.py |
| 128 | # args: ["--output", "./tests/e2e/stablehlo_models/generated_e2e_model_tests.cmake"] |
| 129 | # # TODO(scotttodd): run only on relevant files |
| 130 | # always_run: true |
| 131 | # pass_filenames: false |