Skip to content

Commit 465153e

Browse files
committed
linting: add shelcheck for shell script lint
Add linting for shell scripts in the scipts directory as well as any *.sh file accross the project using shellcheck. Signed-off-by: Andreas Hatziiliou <andreas.hatziiliou@savoirfairelinux.com>
1 parent 403daac commit 465153e

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

nix/util.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ rec {
8686

8787
inherit (pkgs)
8888
nixpkgs-fmt
89-
shfmt;
89+
shfmt
90+
shellcheck;
9091

9192
inherit (pkgs.python3Packages)
9293
mpmath sympy black pyparsing pyyaml;

scripts/format

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ if ! command -v shfmt 2>&1 >/dev/null; then
4141
error "shfmt not found. Are you running in a nix shell? See BUILDING.md."
4242
exit 1
4343
fi
44-
shfmt -s -w -l -i 2 -ci -fn $(shfmt -f $(git grep -l '' :/))
44+
45+
# Find all scripts in the repo
46+
ALL_FILES=$(git grep -l '' :/)
47+
SHELL_SCRIPTS=$(echo "$ALL_FILES" | xargs shfmt -f)
48+
shfmt -s -l -i 2 -ci -fn $SHELL_SCRIPTS
4549

4650
info "Formatting python scripts"
4751
if ! command -v black 2>&1 >/dev/null; then

scripts/lint

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,36 @@ gh_error_simple()
106106
fi
107107
}
108108

109+
run-shellcheck()
110+
{
111+
if ! command -v shellcheck >/dev/null; then
112+
gh_error_simple "Shellcheck missing" "shellcheck is not installed"
113+
error "Lint shellcheck"
114+
SUCCESS=false
115+
gh_summary_failure "Lint shellcheck"
116+
return 0
117+
fi
118+
119+
checkerr "Lint shellcheck" "$(shellcheck --severity=warning $SHELL_SCRIPTS)"
120+
}
121+
109122
# Formatting
110123
SUCCESS=true
111124

125+
# Get list of shell scripts for linting
126+
ALL_FILES=$(git grep -l '' :/)
127+
SHELL_SCRIPTS=$(echo "$ALL_FILES" | xargs shfmt -f)
128+
112129
gh_group_start "Linting nix files with nixpkgs-fmt"
113130
checkerr "Lint nix" "$(nixpkgs-fmt --check "$ROOT")"
114131
gh_group_end
115132

116133
gh_group_start "Linting shell scripts with shfmt"
117-
checkerr "Lint shell" "$(shfmt -s -l -i 2 -ci -fn $(shfmt -f $(git grep -l '' :/)))"
134+
checkerr "Lint shell" "$(echo $SHELL_SCRIPTS | xargs shfmt -s -l -i 2 -ci -fn)"
135+
gh_group_end
136+
137+
gh_group_start "Linting shell scripts with shellcheck"
138+
run-shellcheck
118139
gh_group_end
119140

120141
gh_group_start "Linting python scripts with black"

0 commit comments

Comments
 (0)