blob: b673dc3e5f8e6573cc0669a0db3cb9cb54a8b9a4 [file] [log] [blame]
Scott Todd778d00d2024-06-03 10:34:40 -07001# Pre-commit (https://pre-commit.com) configuration for assorted lint checks.
2#
3# See https://pre-commit.com/hooks.html for more hooks.
4
5exclude: "third_party/"
6
7repos:
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
Scott Toddf4cfb552024-06-10 09:25:54 -070021 - id: end-of-file-fixer
22 exclude_types: ["image", "jupyter"]
Scott Todd778d00d2024-06-03 10:34:40 -070023
Scott Toddf4cfb552024-06-10 09:25:54 -070024 - id: trailing-whitespace
25 exclude_types: ["image", "jupyter"]
Scott Todd778d00d2024-06-03 10:34:40 -070026
27- repo: https://github.com/psf/black
28 rev: 23.3.0
29 hooks:
30 - id: black
31 name: Run Black to format Python files
32
33- repo: https://github.com/pre-commit/mirrors-clang-format
34 # Loosely track the most recent versions in
35 # * Runner images: https://github.com/actions/runner-images/
36 # * Editor extensions: https://github.com/microsoft/vscode-cpptools
37 rev: v18.1.3
38 hooks:
39 - id: clang-format
40 name: Run clang-format on C/C++/etc. files
41 exclude_types: ["jupyter"]
42
43- repo: https://github.com/igorshubovych/markdownlint-cli
44 rev: v0.41.0
45 hooks:
46 - id: markdownlint
47 name: Run markdownlint on .md files
48 args: ["--config", "docs/.markdownlint.yml"]
49 files: "docs/website/.*.md"
50 exclude: "mlir-dialects/!(index).md"
51
52- repo: https://github.com/Lucas-C/pre-commit-hooks
53 rev: v1.5.5
54 hooks:
55 - id: forbid-tabs
56 exclude: ".gitmodules|Makefile"
57
58- repo: https://github.com/jlebar/pre-commit-hooks.git
59 rev: f2d115a052860b09b2888b4f104be614bf3b4779
60 hooks:
Scott Todd778d00d2024-06-03 10:34:40 -070061 - id: do-not-submit
62
63- repo: local
64 hooks:
Scott Todd5404ad72024-06-06 09:58:23 -070065 - id: buildifier
66 name: Run buildifier
67 entry: buildifier
68 language: golang
69 # Pinned to v7.1.2, but of course we can't use a tag because semver
70 # and "go install" just don't work together???
71 # This makes absolutely no sense and the maintainers have no intention
72 # of improving it or at least explaining it as hundreds of developers
73 # search for basic support: https://github.com/golang/go/issues/35732.
74 # Docs are technically at https://go.dev/ref/mod#go-install ¯\_(ツ)_/¯
75 additional_dependencies: ["github.com/bazelbuild/buildtools/buildifier@1429e15ae755a6762d0edf9198062dc6ed04408d"]
76 files: '^(.*/)?(BUILD\.bazel|BUILD|WORKSPACE|WORKSPACE\.bazel|WORKSPACE\.bzlmod|MODULE\.bazel)$|\.BUILD$|\.bzl$'
77 # Pin the language version so other system version are _not_ used.
78 # Older go versions used different syntax for "go install" (which is
79 # apparently different from "go get" and "go build"), so for this to
80 # work reliably at all we need to ensure at least some minimum. Syntax
81 # probably changed again in a future version, whatever.
82 language_version: "1.16"
83
Scott Todd778d00d2024-06-03 10:34:40 -070084 - id: bazel_to_cmake
85 name: Run bazel_to_cmake.py
86 language: python
Scott Toddd68a8592024-06-07 14:18:32 -070087 # Note: this passes file names to the tool. The tool can also be run
88 # manually with no arguments specified to walk directories on its own.
Scott Todd778d00d2024-06-03 10:34:40 -070089 entry: ./build_tools/bazel_to_cmake/bazel_to_cmake.py
Scott Toddd68a8592024-06-07 14:18:32 -070090 # Keep the top level directories here in sync with .bazel_to_cmake.cfg.py.
91 files: '^(compiler|runtime|samples|tests|tools)/(.*/)?(BUILD\.bazel|CMakeLists.txt)$'
Scott Todd778d00d2024-06-03 10:34:40 -070092
Scott Todd778d00d2024-06-03 10:34:40 -070093 - id: check_path_lengths
Scott Toddd68a8592024-06-07 14:18:32 -070094 name: Check for excessively long path lengths
95 language: fail
96 entry: Path lengths relative to the root should be < 75 characters (run ./build_tools/scripts/check_path_lengths.py for detailed output)
97 # The regex includes/excludes here should roughly match the behavior of
98 # the check_path_lengths.py script.
99 files: '^compiler/.{66,}/\w+\.'
100 exclude: 'test/'
Scott Todd778d00d2024-06-03 10:34:40 -0700101
102 - id: build_file_names
103 name: Check Bazel file names
104 entry: Files should be named BUILD.bazel instead of BUILD
105 language: fail
106 files: "BUILD$"
107
Scott Todd2baf6c32024-06-07 14:44:37 -0700108 # TODO(scotttodd): mypy type checking for Python (https://mypy-lang.org/)
109
Scott Todd778d00d2024-06-03 10:34:40 -0700110 # TODO(scotttodd): enable these checks when they work on Windows
111 # the generator scripts use \ on Windows instead of /
112
113 # - id: generate_cmake_e2e_test_artifacts_suite
114 # name: Run generate_cmake_e2e_test_artifacts_suite.py
115 # language: python
116 # entry: ./build_tools/testing/generate_cmake_e2e_test_artifacts_suite.py
117 # args: ["--output_dir", "./tests/e2e/test_artifacts"]
118 # # TODO(scotttodd): run only on relevant files
119 # always_run: true
120 # pass_filenames: false
121
122 # - id: generate_cmake_e2e_model_tests
123 # name: Run generate_cmake_e2e_model_tests.py
124 # language: python
125 # entry: ./build_tools/testing/generate_cmake_e2e_model_tests.py
126 # args: ["--output", "./tests/e2e/stablehlo_models/generated_e2e_model_tests.cmake"]
127 # # TODO(scotttodd): run only on relevant files
128 # always_run: true
129 # pass_filenames: false