blob: efc1b63720753ee3a34da62127aa16c2f825a37a [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:
Scott Todd9b05f172024-08-14 10:55:09 -07008 - repo: https://github.com/pre-commit/pre-commit-hooks
Scott Todd778d00d2024-06-03 10:34:40 -07009 rev: v3.2.0
10 hooks:
Scott Todd9b05f172024-08-14 10:55:09 -070011 - id: check-merge-conflict
Scott Todd778d00d2024-06-03 10:34:40 -070012
Scott Todd9b05f172024-08-14 10:55:09 -070013 - id: check-yaml
Scott Todd778d00d2024-06-03 10:34:40 -070014 # * 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 Todd9b05f172024-08-14 10:55:09 -070020 - id: end-of-file-fixer
Scott Toddf4cfb552024-06-10 09:25:54 -070021 exclude_types: ["image", "jupyter"]
Scott Todd778d00d2024-06-03 10:34:40 -070022
Scott Todd9b05f172024-08-14 10:55:09 -070023 - id: trailing-whitespace
Scott Toddf4cfb552024-06-10 09:25:54 -070024 exclude_types: ["image", "jupyter"]
Scott Todd778d00d2024-06-03 10:34:40 -070025
Scott Todd9b05f172024-08-14 10:55:09 -070026 - repo: https://github.com/psf/black
Scott Todd778d00d2024-06-03 10:34:40 -070027 rev: 23.3.0
28 hooks:
Scott Todd9b05f172024-08-14 10:55:09 -070029 - id: black
Scott Todd778d00d2024-06-03 10:34:40 -070030 name: Run Black to format Python files
31
Scott Todd9b05f172024-08-14 10:55:09 -070032 - repo: https://github.com/pre-commit/mirrors-clang-format
Scott Todd778d00d2024-06-03 10:34:40 -070033 # 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 Todd9b05f172024-08-14 10:55:09 -070038 - id: clang-format
Scott Todd778d00d2024-06-03 10:34:40 -070039 name: Run clang-format on C/C++/etc. files
40 exclude_types: ["jupyter"]
41
Scott Todd9b05f172024-08-14 10:55:09 -070042 - repo: https://github.com/igorshubovych/markdownlint-cli
Scott Todd778d00d2024-06-03 10:34:40 -070043 rev: v0.41.0
44 hooks:
Scott Todd9b05f172024-08-14 10:55:09 -070045 - id: markdownlint
Scott Todd778d00d2024-06-03 10:34:40 -070046 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 Todd9b05f172024-08-14 10:55:09 -070051 - repo: https://github.com/Lucas-C/pre-commit-hooks
Scott Todd778d00d2024-06-03 10:34:40 -070052 rev: v1.5.5
53 hooks:
Scott Todd9b05f172024-08-14 10:55:09 -070054 - id: forbid-tabs
Scott Todd778d00d2024-06-03 10:34:40 -070055 exclude: ".gitmodules|Makefile"
56
Scott Todd9b05f172024-08-14 10:55:09 -070057 - repo: https://github.com/jlebar/pre-commit-hooks.git
Scott Todd778d00d2024-06-03 10:34:40 -070058 rev: f2d115a052860b09b2888b4f104be614bf3b4779
59 hooks:
Scott Todd9b05f172024-08-14 10:55:09 -070060 - id: do-not-submit
Scott Todd778d00d2024-06-03 10:34:40 -070061
Scott Todd9b05f172024-08-14 10:55:09 -070062 - repo: local
Scott Todd778d00d2024-06-03 10:34:40 -070063 hooks:
Scott Todd9b05f172024-08-14 10:55:09 -070064 - id: buildifier
Scott Todd5404ad72024-06-06 09:58:23 -070065 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 Todd9b05f172024-08-14 10:55:09 -070074 additional_dependencies:
75 [
76 "github.com/bazelbuild/buildtools/buildifier@1429e15ae755a6762d0edf9198062dc6ed04408d",
77 ]
Scott Todd5404ad72024-06-06 09:58:23 -070078 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 Todd62bccc92024-12-04 10:07:10 -080086 # 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 Todd778d00d2024-06-03 10:34:40 -070093 language: python
94 entry: ./build_tools/bazel_to_cmake/bazel_to_cmake.py
Scott Todd62bccc92024-12-04 10:07:10 -080095 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 Todd778d00d2024-06-03 10:34:40 -0700101
Scott Todd9b05f172024-08-14 10:55:09 -0700102 - id: check_path_lengths
Scott Toddd68a8592024-06-07 14:18:32 -0700103 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 Todd9b05f172024-08-14 10:55:09 -0700109 exclude: "test/"
Scott Todd778d00d2024-06-03 10:34:40 -0700110
Scott Todd9b05f172024-08-14 10:55:09 -0700111 - id: build_file_names
Scott Todd778d00d2024-06-03 10:34:40 -0700112 name: Check Bazel file names
113 entry: Files should be named BUILD.bazel instead of BUILD
114 language: fail
115 files: "BUILD$"
116
Scott Todd2baf6c32024-06-07 14:44:37 -0700117 # TODO(scotttodd): mypy type checking for Python (https://mypy-lang.org/)