-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlint.sh
executable file
·65 lines (55 loc) · 2 KB
/
lint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /bin/bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)"
function print_error {
read line file <<<$(caller)
printf "\n⛔️ An error occurred during the following lint step ⛔️\n" >&2
sed "${line}q;d" "$file" >&2
}
trap print_error ERR
#####################
# Bazel file linting
#####################
# Find all Bazel-ish files - these templates come from Buildifier's default search list
BAZEL_FILES=$(find ${REPO_ROOT} -type f \
\( -name "*.bzl" \
-o -name "*.sky" \
-o -name "BUILD.bazel" \
-o -name "BUILD" \
-o -name "*.BUILD" \
-o -name "BUILD.*.bazel" \
-o -name "BUILD.*.oss" \
-o -name "MODULE.bazel" \
-o -name "WORKSPACE" \
-o -name "WORKSPACE.bazel" \
-o -name "WORKSPACE.oss" \
-o -name "WORKSPACE.*.bazel" \
-o -name "WORKSPACE.*.oss" \) \
-print)
BUILDIFIER_ARGS=("-lint=fix" "-mode=fix" "-v=false")
BUILDIFIER_INVOCATION="bazel run -- //tools/buildifier ${BUILDIFIER_ARGS[@]}"
echo $BAZEL_FILES | xargs ${BUILDIFIER_INVOCATION}
#################
# Python linting
#################
# Sort imports
bazel run -- //tools/isort ${REPO_ROOT} --dont-follow-links
# Autoformat
bazel run -- //tools/black ${REPO_ROOT}
# Ensure flake8 compliance
bazel run -- //tools/flake8 ${REPO_ROOT}
#################
# Go linting
#################
GO_FILES=$(find ${REPO_ROOT} -type f -name "*.go" -print)
GOFMT_ARGS=("")
GOFMT_INVOCATION="bazel run -- @rules_go//go fmt ${GOFMT_ARGS[@]}"
echo $GO_FILES | xargs ${GOFMT_INVOCATION}
#################
# Markdown Linting
#################
MARKDOWN_FILES=$(find ${REPO_ROOT} -type f -name "*.md" -print)
PRETTIER_ARGS=("--write" "--config ${REPO_ROOT}/.prettierrc")
PRETTIER_INVOCATION="bazel run -- //tools/prettier ${PRETTIER_ARGS[@]}"
echo $MARKDOWN_FILES | xargs ${PRETTIER_INVOCATION}
printf "\n✨ Linting completed successfully! ✨\n"