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 3994d1434e..68f1e892d3 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 d86ea1f786..ec955c7c7f 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 1492123e16..7b662994d1 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 24efaa74f1..3c0f5c3dd1 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 b89b5db858..7ea7c5fc3f 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 ee66d51de9..e8b546a606 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 e255e6733d..fb0bdedd3b 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 f13b5f9f62..5ec13ece53 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 f381613ed6..eee617802b 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 87732331f8..05e4f1c507 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 cdf06202b7..b1bbb6bd3a 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 d25a3d250a..3f70503009 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 76e66216c4..931ceb1316 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 7fb7a75285..0cd1aafcd3 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 470fd792b1..444a5f374b 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 a4bb907dd1..f3dc23129f 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 4d20020361..179c240097 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 74a4edd628..0f7c96698d 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 c336d60755..625d0b91fd 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 b7dbd33ccf..8a67d548bf 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 a5107e6fc8..77b1269a9d 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