Makefile: add make targets lint, lint-sh, lint-lua

- move lint commands from Jerkinsfile into sh files.
This commit is contained in:
Jan-Tarek Butt 2019-12-14 22:18:58 +01:00
parent 2186ce2dc8
commit 9417b89321
4 changed files with 42 additions and 4 deletions

View File

@ -103,6 +103,13 @@ endef
list-targets: FORCE
@$(foreach target,$(GLUON_TARGETS),echo '$(target)';)
lint: lint-lua lint-sh
lint-lua: FORCE
@scripts/lint-lua.sh
lint-sh: FORCE
@scripts/lint-sh.sh
GLUON_DEFAULT_PACKAGES := hostapd-mini

View File

@ -1,11 +1,9 @@
def lualint() {
sh 'luacheck package scripts targets'
make lint-lua
}
def shelllint() {
sh 'find -not \( -path './*.git/*' -prune \) -not \( -path './package/*' -prune \) -not \( -path './scripts/*' -prune \) -type f -exec bash -c 'if echo $1 | grep -qE ".*\.sh$" || head -n1 $1 | grep -qE "^#.*(sh|bash|dash|ksh)$"; then shellcheck -f gcc $1; fi' _ {} \;'
sh 'find package -type f -exec bash -c 'if echo $1 | grep -qE ".*\.sh$" || head -n1 $1 | grep -qE "^#.*(sh|bash|dash|ksh)$"; then shellcheck -x -f gcc -s sh -eSC2039,SC1091,SC2155,SC2034 $1; fi' _ {} \;'
sh 'find scripts -type f -exec bash -c 'if echo $1 | grep -qE ".*\.sh$" || head -n1 $1 | grep -qE "^#.*(sh|bash|dash|ksh)$"; then shellcheck -f gcc -x -e SC2154,SC1090,SC2181,SC2155,SC2148,SC2034,SC2148 $1; fi' _ {} \;'
make lint-sh
}
run_lint_set = [

5
scripts/lint-lua.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
set -e
luacheck package scripts targets

28
scripts/lint-sh.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
set -e
is_scriptfile() {
if echo "$1" | grep -qE '.*\.sh$' || head -n1 "$1" | grep -qE '^#.*(sh|bash)$'; then
return 0
fi
return 1
}
find contrib -type f | while read -r file; do
if is_scriptfile "$file"; then
shellcheck -f gcc "$file"
fi
done
find package -type f | while read -r file; do
if is_scriptfile "$file"; then
shellcheck -x -f gcc -s sh -eSC2039,SC1091,SC2155,SC2034 "$file"
fi
done
find scripts -type f | while read -r file; do
if is_scriptfile "$file"; then
shellcheck -f gcc -x -e SC2154,SC1090,SC2181,SC2155,SC2148,SC2034,SC2148 "$file"
fi
done