xref: /freebsd/sys/contrib/openzfs/config/Shellcheck.am (revision faf25f48d601ae39f5752602f3020e2e92605625)
1# Global ShellCheck exclusions:
2#
3# ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090]
4# Not following: a was not specified as input (see shellcheck -x). [SC1091]
5# Prefer putting braces around variable references even when not strictly required. [SC2250]
6# In POSIX sh, 'local' is undefined. [SC2039] # older ShellCheck versions
7# In POSIX sh, 'local' is undefined. [SC3043] # newer ShellCheck versions
8
9SHELLCHECKSCRIPTS =
10
11JUST_SHELLCHECK_OPTS    = $(addprefix shellcheck-here-,$(subst /,^,$(1)))
12JUST_CHECKBASHISMS_OPTS = $(addprefix checkbashisms-here-,$(subst /,^,$(1)))
13SHELLCHECK_OPTS         = $(call JUST_SHELLCHECK_OPTS,$(1)) $(call JUST_CHECKBASHISMS_OPTS,$(1))
14
15PHONY += shellcheck
16
17_STGT = $(subst ^,/,$(subst shellcheck-here-,,$@))
18shellcheck-here-%:
19if HAVE_SHELLCHECK
20	shellcheck --format=gcc --enable=all --exclude=SC1090,SC1091,SC2039,SC2250,SC3043 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") "$$([ -e "$(_STGT)" ] || echo "$(srcdir)/")$(_STGT)"
21else
22	@echo "skipping shellcheck of" $(_STGT) "because shellcheck is not installed"
23endif
24
25shellcheck: $(SHELLCHECKSCRIPTS) $(call JUST_SHELLCHECK_OPTS,$(SHELLCHECKSCRIPTS))
26
27
28PHONY += checkbashisms
29
30# command -v *is* specified by POSIX and every shell in existence supports it
31_BTGT = $(subst ^,/,$(subst checkbashisms-here-,,$@))
32checkbashisms-here-%:
33if HAVE_CHECKBASHISMS
34	! { [ -n "$(SHELLCHECK_SHELL)" ] && echo '#!/bin/$(SHELLCHECK_SHELL)'; cat "$$([ -e "$(_BTGT)" ] || echo "$(srcdir)/")$(_BTGT)"; } | \
35	checkbashisms -npx 2>&1 | grep -vFe "'command' with option other than -p" -e 'command -v' -e 'any possible bashisms' $(CHECKBASHISMS_IGNORE) >&2
36else
37	@echo "skipping checkbashisms of" $(_BTGT) "because checkbashisms is not installed"
38endif
39
40checkbashisms: $(SHELLCHECKSCRIPTS) $(call JUST_CHECKBASHISMS_OPTS,$(SHELLCHECKSCRIPTS))
41