-
Notifications
You must be signed in to change notification settings - Fork 29
/
run-lint
executable file
·57 lines (46 loc) · 1.46 KB
/
run-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
#!/bin/sh
space=' '
tab=' '
red='\033[1;31m'
green='\033[1;32m'
reset='\033[0m'
ok=yes
error() {
printf "${red}ERROR${reset} %s\n" "$*"
ok=no
}
echo "--- Lua Lint ---"
luacheck src/ spec/ examples/ "$@" || error "Luacheck found problems"
echo
echo "--- Other checks ---"
for file in \
src/pallene/*.lua \
spec/*.lua \
examples/*/*.lua \
examples/*/*.pln
do
if grep --line-number "[$space$tab]$" "$file"; then
# Forbid trailing whitespace because some editors like to automatically delete it.
# Such whitespace can cause spurious diffs later down the road, when someone is working on
# an unrelated pull request and their editor "helpfully" deletes the trailing whitespace.
error "File $file has a line that ends in whitespace"
fi
if grep --line-number "^$space*$tab" "$file"; then
# Standardize on spaces because mixing tabs and spaces is endless pain.
error "File $file has tab-based indentation"
fi
if ! grep --line-number --quiet 'SPDX-License-Identifier' "$file"; then
error "File $file is missing a copyright header"
fi
done
if grep --line-number -E \
"^[$space$tab]*self:(check_exp|check_var|check_initializer)" \
src/pallene/typechecker.lua;
then
# Using grep to catch this logic error isn't ideal, but it's better than nothing.
error "You should not ignore the return value here"
fi
if [ "$ok" != yes ]; then
exit 1
fi
printf "${green}OK${reset}\n"