| # Copyright 2021 The IREE Authors |
| # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| # See https://llvm.org/LICENSE.txt for license information. |
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| # Checks buildifier formatting and lint in files modified vs the specified |
| # reference commit (default "main") |
| # See https://github.com/bazelbuild/buildtools/tree/master/buildifier |
| declare -a included_files_patterns=( |
| declare -a excluded_files_patterns=( |
| included_files_pattern="$(IFS="|" ; echo "${included_files_patterns[*]?}")" |
| excluded_files_pattern="$(IFS="|" ; echo "${excluded_files_patterns[*]?}")" |
| (git diff --name-only --diff-filter=d "${BASE_REF}" || kill $$) \ |
| | grep -E "${included_files_pattern?}" \ |
| | grep -v -E "${excluded_files_pattern?}") |
| if [ ${#files[@]} -eq 0 ]; then |
| echo "No Bazel files changed" |
| echo "Fixing formatting with Buildifier" |
| echo "Fixing automatically fixable lint with Buildifier" |
| buildifier -lint=fix "${files[@]}" |
| echo "Checking complicated lint with Buildifier" |
| # Sometimes people don't write docstrings and I am not going to make that |
| buildifier -lint=warn -warnings=-module-docstring,-function-docstring "${files[@]}" |