From 8df0bde321ab6e4c38cf17e89c8bc331369c7f0a Mon Sep 17 00:00:00 2001 From: Damian Szuberski Date: Mon, 7 Feb 2022 20:59:09 +0100 Subject: [PATCH] Add `--enable=all` to ShellCheck by default Change enforced shell type from `dash` to `sh` and excluded `SC2039` and `SC3043` by default. `local` keyword is accepted by all POSIX shells from practical point of view. There is no need anymore to enforce dash so `local` is accepted. Reviewed-by: George Melikov Reviewed-by: Brian Behlendorf Signed-off-by: szubersk Closes #13020 --- cmd/Makefile.am | 1 - cmd/fsck_zfs/Makefile.am | 1 - cmd/zed/Makefile.am | 1 - cmd/zed/zed.d/Makefile.am | 3 +-- cmd/zpool/Makefile.am | 1 - cmd/zvol_wait/Makefile.am | 1 - config/Shellcheck.am | 10 +++++++++- contrib/Makefile.am | 1 - contrib/bash_completion.d/Makefile.am | 1 - contrib/bpftrace/Makefile.am | 1 - contrib/dracut/02zfsexpandknowledge/Makefile.am | 1 - contrib/dracut/90zfs/Makefile.am | 1 - contrib/initramfs/Makefile.am | 1 - contrib/initramfs/hooks/Makefile.am | 1 - contrib/initramfs/scripts/Makefile.am | 1 - contrib/initramfs/scripts/local-top/Makefile.am | 1 - etc/Makefile.am | 1 - etc/default/Makefile.am | 3 +-- etc/init.d/Makefile.am | 3 +-- etc/zfs/Makefile.am | 3 +-- scripts/Makefile.am | 1 - 21 files changed, 13 insertions(+), 25 deletions(-) diff --git a/cmd/Makefile.am b/cmd/Makefile.am index 3994d1434..68f1e892d 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -9,7 +9,6 @@ CPPCHECKDIRS += raidz_test zfs_ids_to_path zpool_influxdb # TODO: #12084: SHELLCHECKDIRS += vdev_id SHELLCHECKDIRS = fsck_zfs zed zpool zvol_wait -SHELLCHECK_OPTS = --enable=all if USING_PYTHON SUBDIRS += arcstat arc_summary dbufstat diff --git a/cmd/fsck_zfs/Makefile.am b/cmd/fsck_zfs/Makefile.am index d86ea1f78..ec955c7c7 100644 --- a/cmd/fsck_zfs/Makefile.am +++ b/cmd/fsck_zfs/Makefile.am @@ -5,4 +5,3 @@ dist_sbin_SCRIPTS = fsck.zfs SUBSTFILES += $(dist_sbin_SCRIPTS) -SHELLCHECK_OPTS = --enable=all diff --git a/cmd/zed/Makefile.am b/cmd/zed/Makefile.am index 1492123e1..7b662994d 100644 --- a/cmd/zed/Makefile.am +++ b/cmd/zed/Makefile.am @@ -5,7 +5,6 @@ AM_CFLAGS += $(LIBUDEV_CFLAGS) $(LIBUUID_CFLAGS) SUBDIRS = zed.d SHELLCHECKDIRS = $(SUBDIRS) -SHELLCHECK_OPTS = --enable=all sbin_PROGRAMS = zed diff --git a/cmd/zed/zed.d/Makefile.am b/cmd/zed/zed.d/Makefile.am index 24efaa74f..3c0f5c3dd 100644 --- a/cmd/zed/zed.d/Makefile.am +++ b/cmd/zed/zed.d/Makefile.am @@ -11,8 +11,7 @@ dist_zedconf_DATA = \ zed.rc SHELLCHECKSCRIPTS = zed-functions.sh zed.rc -SHELLCHECK_OPTS = --enable=all -SHELLCHECK_SHELL = dash +SHELLCHECK_SHELL = sh zedexecdir = $(zfsexecdir)/zed.d diff --git a/cmd/zpool/Makefile.am b/cmd/zpool/Makefile.am index b89b5db85..7ea7c5fc3 100644 --- a/cmd/zpool/Makefile.am +++ b/cmd/zpool/Makefile.am @@ -5,7 +5,6 @@ AM_CFLAGS += $(LIBBLKID_CFLAGS) $(LIBUUID_CFLAGS) DEFAULT_INCLUDES += -I$(srcdir) -SHELLCHECK_OPTS = --enable=all sbin_PROGRAMS = zpool diff --git a/cmd/zvol_wait/Makefile.am b/cmd/zvol_wait/Makefile.am index ee66d51de..e8b546a60 100644 --- a/cmd/zvol_wait/Makefile.am +++ b/cmd/zvol_wait/Makefile.am @@ -2,4 +2,3 @@ include $(top_srcdir)/config/Shellcheck.am dist_bin_SCRIPTS = zvol_wait -SHELLCHECK_OPTS = --enable=all diff --git a/config/Shellcheck.am b/config/Shellcheck.am index e255e6733..fb0bdedd3 100644 --- a/config/Shellcheck.am +++ b/config/Shellcheck.am @@ -1,7 +1,15 @@ .PHONY: shellcheck shellcheck: $(SCRIPTS) $(SHELLCHECKSCRIPTS) + +# ShellCheck exclusions +# +# ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090] +# Not following: a was not specified as input (see shellcheck -x). [SC1091] +# Prefer putting braces around variable references even when not strictly required. [SC2250] +# In POSIX sh, 'local' is undefined. [SC2039] # older ShellCheck versions +# In POSIX sh, 'local' is undefined. [SC3043] # newer ShellCheck versions if HAVE_SHELLCHECK - [ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; shellcheck --format=gcc --exclude=SC1090,SC1091,SC2250 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") $(SHELLCHECK_OPTS) $(SCRIPTS) $(SHELLCHECKSCRIPTS) + [ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; shellcheck --format=gcc --enable=all --exclude=SC1090,SC1091,SC2039,SC2250,SC3043 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") $(SHELLCHECK_OPTS) $(SCRIPTS) $(SHELLCHECKSCRIPTS) else @[ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; echo "skipping shellcheck of" $(SCRIPTS) $(SHELLCHECKSCRIPTS) "because shellcheck is not installed" endif diff --git a/contrib/Makefile.am b/contrib/Makefile.am index f13b5f9f6..5ec13ece5 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -10,4 +10,3 @@ endif DIST_SUBDIRS = bash_completion.d bpftrace dracut initramfs pam_zfs_key pyzfs zcp SHELLCHECKDIRS = bash_completion.d bpftrace dracut initramfs -SHELLCHECK_OPTS = --enable=all diff --git a/contrib/bash_completion.d/Makefile.am b/contrib/bash_completion.d/Makefile.am index f381613ed..eee617802 100644 --- a/contrib/bash_completion.d/Makefile.am +++ b/contrib/bash_completion.d/Makefile.am @@ -10,4 +10,3 @@ SUBSTFILES += $(noinst_DATA) SHELLCHECKSCRIPTS = $(noinst_DATA) SHELLCHECK_SHELL = bash -SHELLCHECK_OPTS = --enable=all diff --git a/contrib/bpftrace/Makefile.am b/contrib/bpftrace/Makefile.am index 87732331f..05e4f1c50 100644 --- a/contrib/bpftrace/Makefile.am +++ b/contrib/bpftrace/Makefile.am @@ -5,4 +5,3 @@ EXTRA_DIST = \ zfs-trace.sh SHELLCHECKSCRIPTS = zfs-trace.sh -SHELLCHECK_OPTS = --enable=all diff --git a/contrib/dracut/02zfsexpandknowledge/Makefile.am b/contrib/dracut/02zfsexpandknowledge/Makefile.am index cdf06202b..b1bbb6bd3 100644 --- a/contrib/dracut/02zfsexpandknowledge/Makefile.am +++ b/contrib/dracut/02zfsexpandknowledge/Makefile.am @@ -5,5 +5,4 @@ pkgdracutdir = $(dracutdir)/modules.d/02zfsexpandknowledge pkgdracut_SCRIPTS = \ module-setup.sh -SHELLCHECK_OPTS = --enable=all SUBSTFILES += $(pkgdracut_SCRIPTS) diff --git a/contrib/dracut/90zfs/Makefile.am b/contrib/dracut/90zfs/Makefile.am index d25a3d250..3f7050300 100644 --- a/contrib/dracut/90zfs/Makefile.am +++ b/contrib/dracut/90zfs/Makefile.am @@ -19,7 +19,6 @@ pkgdracut_DATA = \ zfs-rollback-bootfs.service SUBSTFILES += $(pkgdracut_SCRIPTS) $(pkgdracut_DATA) -SHELLCHECK_OPTS = --enable=all # Provided by /bin/sleep, and, again, every implementation of that supports this CHECKBASHISMS_IGNORE = -e 'sleep only takes one integer' -e 'sleep 0.' diff --git a/contrib/initramfs/Makefile.am b/contrib/initramfs/Makefile.am index 76e66216c..931ceb131 100644 --- a/contrib/initramfs/Makefile.am +++ b/contrib/initramfs/Makefile.am @@ -7,7 +7,6 @@ dist_initrd_SCRIPTS = \ SUBDIRS = conf.d conf-hooks.d hooks scripts SHELLCHECKDIRS = hooks scripts -SHELLCHECK_OPTS = --enable=all EXTRA_DIST = \ README.initramfs.markdown diff --git a/contrib/initramfs/hooks/Makefile.am b/contrib/initramfs/hooks/Makefile.am index 7fb7a7528..0cd1aafcd 100644 --- a/contrib/initramfs/hooks/Makefile.am +++ b/contrib/initramfs/hooks/Makefile.am @@ -7,5 +7,4 @@ hooks_SCRIPTS = \ zfs \ zfsunlock -SHELLCHECK_OPTS = --enable=all SUBSTFILES += $(hooks_SCRIPTS) diff --git a/contrib/initramfs/scripts/Makefile.am b/contrib/initramfs/scripts/Makefile.am index 470fd792b..444a5f374 100644 --- a/contrib/initramfs/scripts/Makefile.am +++ b/contrib/initramfs/scripts/Makefile.am @@ -9,4 +9,3 @@ SUBDIRS = local-top SHELLCHECKDIRS = $(SUBDIRS) SHELLCHECK_SHELL = sh -SHELLCHECK_OPTS = --enable=all diff --git a/contrib/initramfs/scripts/local-top/Makefile.am b/contrib/initramfs/scripts/local-top/Makefile.am index a4bb907dd..f3dc23129 100644 --- a/contrib/initramfs/scripts/local-top/Makefile.am +++ b/contrib/initramfs/scripts/local-top/Makefile.am @@ -5,4 +5,3 @@ localtopdir = /usr/share/initramfs-tools/scripts/local-top dist_localtop_SCRIPTS = \ zfs -SHELLCHECK_OPTS = --enable=all diff --git a/etc/Makefile.am b/etc/Makefile.am index 4d2002036..179c24009 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -2,7 +2,6 @@ include $(top_srcdir)/config/Shellcheck.am SUBDIRS = zfs sudoers.d SHELLCHECKDIRS = default $(ZFS_INIT_SYSV) zfs -SHELLCHECK_OPTS = --enable=all if BUILD_LINUX SUBDIRS += default $(ZFS_INIT_SYSTEMD) $(ZFS_INIT_SYSV) $(ZFS_MODULE_LOAD) diff --git a/etc/default/Makefile.am b/etc/default/Makefile.am index 74a4edd62..0f7c96698 100644 --- a/etc/default/Makefile.am +++ b/etc/default/Makefile.am @@ -5,5 +5,4 @@ initconf_SCRIPTS = zfs SUBSTFILES += $(initconf_SCRIPTS) -SHELLCHECK_SHELL = dash -SHELLCHECK_OPTS = --enable=all +SHELLCHECK_SHELL = sh diff --git a/etc/init.d/Makefile.am b/etc/init.d/Makefile.am index c336d6075..625d0b91f 100644 --- a/etc/init.d/Makefile.am +++ b/etc/init.d/Makefile.am @@ -7,5 +7,4 @@ init_SCRIPTS = zfs-import zfs-load-key zfs-mount zfs-share zfs-zed SUBSTFILES += $(init_SCRIPTS) -SHELLCHECK_SHELL = dash -SHELLCHECK_OPTS = --enable=all +SHELLCHECK_SHELL = sh diff --git a/etc/zfs/Makefile.am b/etc/zfs/Makefile.am index b7dbd33cc..8a67d548b 100644 --- a/etc/zfs/Makefile.am +++ b/etc/zfs/Makefile.am @@ -15,5 +15,4 @@ pkgsysconf_SCRIPTS = \ SUBSTFILES += $(pkgsysconf_SCRIPTS) -SHELLCHECK_OPTS = --enable=all -SHELLCHECK_SHELL = dash +SHELLCHECK_SHELL = sh diff --git a/scripts/Makefile.am b/scripts/Makefile.am index a5107e6fc..77b1269a9 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -28,7 +28,6 @@ EXTRA_DIST = \ $(EXTRA_SCRIPTS) SHELLCHECKSCRIPTS = $(EXTRA_SCRIPTS) -SHELLCHECK_OPTS = --enable=all define EXTRA_ENVIRONMENT