From 9417b89321e54b4fcc1a0d68ef1158cc05ec92f8 Mon Sep 17 00:00:00 2001 From: Jan-Tarek Butt Date: Sat, 14 Dec 2019 22:18:58 +0100 Subject: [PATCH] Makefile: add make targets lint, lint-sh, lint-lua - move lint commands from Jerkinsfile into sh files. --- Makefile | 7 +++++++ contrib/ci/Jenkinsfile | 6 ++---- scripts/lint-lua.sh | 5 +++++ scripts/lint-sh.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100755 scripts/lint-lua.sh create mode 100755 scripts/lint-sh.sh diff --git a/Makefile b/Makefile index a9849104..34343356 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/contrib/ci/Jenkinsfile b/contrib/ci/Jenkinsfile index d62464f8..87a89bef 100644 --- a/contrib/ci/Jenkinsfile +++ b/contrib/ci/Jenkinsfile @@ -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 = [ diff --git a/scripts/lint-lua.sh b/scripts/lint-lua.sh new file mode 100755 index 00000000..e958e3f1 --- /dev/null +++ b/scripts/lint-lua.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +luacheck package scripts targets diff --git a/scripts/lint-sh.sh b/scripts/lint-sh.sh new file mode 100755 index 00000000..d3b73782 --- /dev/null +++ b/scripts/lint-sh.sh @@ -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