forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-commit config and replace many lint checks with it. (iree-org…
…#17538) This adds a [pre-commit](https://pre-commit.com/) configuration file and migrates checks from our previous `lint.yml` and `lint.sh` files to using these new hooks, making progress on iree-org#17430. Each hook is versioned and is automatically installed by pre-commit when used. * Documentation updates to https://iree.dev/developers/general/contributing/#coding-style-guidelines will follow after some soak time (I haven't tested the actual pre-commit git hook portion of the tooling yet, for example). TLDR: ```bash # setup (or using your package manager of choice) py -m pip install --user pipx py -m pipx ensurepath pipx install pre-commit # run manually on changed files pre-commit run # run manually on all files pre-commit run --all-files # install git hook scripts pre-commit install ``` * A few checks are disabled for now. * `end-of-file-fixer` and `trailing-whitespace` are new checks for this project so I want to give developers some time to learn pre-commit workflows before adding them. * Other checks like `generated_cmake_files` and `buildifier` are still using the existing scripts while I figure out how to cleanly migrate them. Sample runs: * Success: https://github.com/iree-org/iree/actions/runs/9324252254/job/25669139815?pr=17538#step:4:54 * One error: https://github.com/iree-org/iree/actions/runs/9324187058/job/25668919747?pr=17538#step:4:85 skip-ci: test lint job only
- Loading branch information
Showing
6 changed files
with
123 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Pre-commit (https://pre-commit.com) configuration for assorted lint checks. | ||
# | ||
# See https://pre-commit.com/hooks.html for more hooks. | ||
|
||
exclude: "third_party/" | ||
|
||
repos: | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.2.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
|
||
- id: check-yaml | ||
# * Extensions can't be included in the mkdocs schema, so skip checking | ||
# https://github.com/squidfunk/mkdocs-material/issues/6378 | ||
# * clang-format files use `---` to split for multiple languages, | ||
# resulting in errors like `expected a single document in the stream` | ||
exclude: "mkdocs.yml|.clang-format" | ||
|
||
# TODO(scotttodd): enable once enough contributors are familiar with pre-commit | ||
# - id: end-of-file-fixer | ||
# exclude_types: ["image", "jupyter"] | ||
|
||
# TODO(scotttodd): enable once enough contributors are familiar with pre-commit | ||
# - id: trailing-whitespace | ||
# exclude_types: ["image", "jupyter"] | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 23.3.0 | ||
hooks: | ||
- id: black | ||
name: Run Black to format Python files | ||
|
||
- repo: https://github.com/pre-commit/mirrors-clang-format | ||
# Loosely track the most recent versions in | ||
# * Runner images: https://github.com/actions/runner-images/ | ||
# * Editor extensions: https://github.com/microsoft/vscode-cpptools | ||
rev: v18.1.3 | ||
hooks: | ||
- id: clang-format | ||
name: Run clang-format on C/C++/etc. files | ||
exclude_types: ["jupyter"] | ||
|
||
- repo: https://github.com/igorshubovych/markdownlint-cli | ||
rev: v0.41.0 | ||
hooks: | ||
- id: markdownlint | ||
name: Run markdownlint on .md files | ||
args: ["--config", "docs/.markdownlint.yml"] | ||
files: "docs/website/.*.md" | ||
exclude: "mlir-dialects/!(index).md" | ||
|
||
- repo: https://github.com/Lucas-C/pre-commit-hooks | ||
rev: v1.5.5 | ||
hooks: | ||
- id: forbid-tabs | ||
exclude: ".gitmodules|Makefile" | ||
|
||
- repo: https://github.com/jlebar/pre-commit-hooks.git | ||
rev: f2d115a052860b09b2888b4f104be614bf3b4779 | ||
hooks: | ||
# TODO(scotttodd): Download as needed | ||
# https://github.com/jlebar/pre-commit-hooks/issues/3 | ||
# TODO(scotttodd): enable when this works on Windows | ||
# https://github.com/bazelbuild/buildtools/issues/914 | ||
# could try `git add . --renormalize` | ||
# - id: bazel-buildifier | ||
|
||
- id: do-not-submit | ||
|
||
- repo: local | ||
hooks: | ||
- id: bazel_to_cmake | ||
name: Run bazel_to_cmake.py | ||
language: python | ||
entry: ./build_tools/bazel_to_cmake/bazel_to_cmake.py | ||
# TODO(scotttodd): run on BUILD.bazel/CMakeLists.txt files individually | ||
always_run: true | ||
pass_filenames: false | ||
|
||
# TODO(scotttodd): replace with an official pre-commit hook? | ||
# See https://github.com/pre-commit/pre-commit-hooks/issues/760 | ||
- id: check_path_lengths | ||
name: Run check_path_lengths.py | ||
language: python | ||
entry: ./build_tools/scripts/check_path_lengths.py | ||
always_run: true | ||
pass_filenames: false | ||
|
||
- id: build_file_names | ||
name: Check Bazel file names | ||
entry: Files should be named BUILD.bazel instead of BUILD | ||
language: fail | ||
files: "BUILD$" | ||
|
||
# TODO(scotttodd): enable these checks when they work on Windows | ||
# the generator scripts use \ on Windows instead of / | ||
|
||
# - id: generate_cmake_e2e_test_artifacts_suite | ||
# name: Run generate_cmake_e2e_test_artifacts_suite.py | ||
# language: python | ||
# entry: ./build_tools/testing/generate_cmake_e2e_test_artifacts_suite.py | ||
# args: ["--output_dir", "./tests/e2e/test_artifacts"] | ||
# # TODO(scotttodd): run only on relevant files | ||
# always_run: true | ||
# pass_filenames: false | ||
|
||
# - id: generate_cmake_e2e_model_tests | ||
# name: Run generate_cmake_e2e_model_tests.py | ||
# language: python | ||
# entry: ./build_tools/testing/generate_cmake_e2e_model_tests.py | ||
# args: ["--output", "./tests/e2e/stablehlo_models/generated_e2e_model_tests.cmake"] | ||
# # TODO(scotttodd): run only on relevant files | ||
# always_run: true | ||
# pass_filenames: false |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.