-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlint
executable file
·78 lines (66 loc) · 1.72 KB
/
lint
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
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
# consts
ROOT="$(realpath "$(dirname "$0")"/../../)"
checkerr()
{
if [[ $? == 127 ]]; then
SUCCESS=false
return
fi
if [[ ${#1} != 0 ]]; then
echo "$1" | while read -r file line; do
echo "::error file=$file,line=${line:-1},title=Format error::$file require to be formatted"
done
SUCCESS=false
fi
}
# Formatting
SUCCESS=true
echo "::group::Linting nix files with nixpkgs-fmt"
checkerr "$(nixpkgs-fmt --check "$ROOT")"
echo "::endgroup::"
echo "::group::Linting shell scripts with shfmt"
checkerr "$(shfmt -s -l -i 2 -ci -fn $(shfmt -f $(git grep -l '' :/)))"
echo "::endgroup::"
echo "::group::Linting python scripts with black"
if ! diff=$(black --check --diff -q --include scripts/tests "$ROOT"); then
echo "::error title=Format error::$diff"
SUCCESS=false
fi
echo "::endgroup::"
echo "::group::Linting c files with astyle"
checkerr "$(astyle $(git ls-files ":/*.c" ":/*.h") --options="$ROOT/.astylerc" --dry-run --formatted | awk '{print $2}')"
echo "::endgroup::"
check-eol-dry-run()
{
for file in $(git ls-files -- ":/"); do
if [[ $(tail -c1 "$file" | wc -l) == 0 ]]; then
l=$(wc -l <"$file")
echo "$file $l"
fi
done
}
echo "::group::Checking eol"
checkerr "$(check-eol-dry-run)"
echo "::endgroup::"
check-spdx()
{
for file in $(git ls-files -- ":/" ":/!:*LICENSE*" ":/!:.git*" ":/!:flake.lock"); do
if [[ $(grep "SPDX-License-Identifier:" $file | wc -l) == 0 ]]; then
echo "$file is missing SPDX License header"
SUCCESS=false
fi
done
}
echo "::group::Checking SPDX headers"
check-spdx
echo "::endgroup::"
#
if ! $SUCCESS; then
exit 1
fi