Skip to content

Commit af82c84

Browse files
authored
Merge pull request #14048 from roberth/shellcheck
Shellcheck
2 parents 5292b0e + 8a9d9bb commit af82c84

File tree

7 files changed

+35
-29
lines changed

7 files changed

+35
-29
lines changed

maintainers/flake-module.nix

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,8 @@
106106
enable = true;
107107
excludes = [
108108
# We haven't linted these files yet
109-
''^config/install-sh$''
110-
''^misc/bash/completion\.sh$''
111-
''^misc/fish/completion\.fish$''
112-
''^misc/zsh/completion\.zsh$''
113-
''^scripts/create-darwin-volume\.sh$''
114-
''^scripts/install-darwin-multi-user\.sh$''
115109
''^scripts/install-multi-user\.sh$''
116110
''^scripts/install-systemd-multi-user\.sh$''
117-
''^src/nix/get-env\.sh$''
118-
''^tests/functional/ca/build-dry\.sh$''
119-
''^tests/functional/ca/build-with-garbage-path\.sh$''
120-
''^tests/functional/ca/common\.sh$''
121-
''^tests/functional/ca/concurrent-builds\.sh$''
122-
''^tests/functional/ca/eval-store\.sh$''
123-
''^tests/functional/ca/gc\.sh$''
124-
''^tests/functional/ca/import-from-derivation\.sh$''
125-
''^tests/functional/ca/new-build-cmd\.sh$''
126-
''^tests/functional/ca/nix-shell\.sh$''
127-
''^tests/functional/ca/post-hook\.sh$''
128-
''^tests/functional/ca/recursive\.sh$''
129-
''^tests/functional/ca/repl\.sh$''
130-
''^tests/functional/ca/selfref-gc\.sh$''
131-
''^tests/functional/ca/why-depends\.sh$''
132-
''^tests/functional/characterisation-test-infra\.sh$''
133-
''^tests/functional/common/vars-and-functions\.sh$''
134111
''^tests/functional/completions\.sh$''
135112
''^tests/functional/compute-levels\.sh$''
136113
''^tests/functional/config\.sh$''
@@ -248,6 +225,25 @@
248225
''^tests/functional/user-envs\.builder\.sh$''
249226
''^tests/functional/user-envs\.sh$''
250227
''^tests/functional/why-depends\.sh$''
228+
229+
# Shellcheck doesn't support fish or zsh shell syntax
230+
''^misc/fish/completion\.fish$''
231+
''^misc/zsh/completion\.zsh$''
232+
233+
# Content-addressed test files that use recursive-*looking* sourcing
234+
# (cd .. && source <self>), causing shellcheck to loop
235+
# They're small wrapper scripts with not a lot going on
236+
''^tests/functional/ca/build-dry\.sh$''
237+
''^tests/functional/ca/eval-store\.sh$''
238+
''^tests/functional/ca/gc\.sh$''
239+
''^tests/functional/ca/import-from-derivation\.sh$''
240+
''^tests/functional/ca/new-build-cmd\.sh$''
241+
''^tests/functional/ca/nix-shell\.sh$''
242+
''^tests/functional/ca/post-hook\.sh$''
243+
''^tests/functional/ca/recursive\.sh$''
244+
''^tests/functional/ca/repl\.sh$''
245+
''^tests/functional/ca/selfref-gc\.sh$''
246+
''^tests/functional/ca/why-depends\.sh$''
251247
];
252248
};
253249
};

misc/bash/completion.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck shell=bash
12
function _complete_nix {
23
local -a words
34
local cword cur

packaging/dev-shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pkgs.nixComponents2.nix-util.overrideAttrs (
118118
modular.pre-commit.settings.package
119119
(pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
120120
pkgs.buildPackages.nixfmt-rfc-style
121+
pkgs.buildPackages.shellcheck
121122
pkgs.buildPackages.gdb
122123
]
123124
++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) (

src/nix/get-env.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
# shellcheck shell=bash
12
set -e
3+
# shellcheck disable=SC1090 # Dynamic sourcing is intentional
24
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source "$NIX_ATTRS_SH_FILE"; fi
35

46
export IN_NIX_SHELL=impure
57
export dontAddDisableDepTrack=1
68

79
if [[ -n $stdenv ]]; then
8-
source $stdenv/setup
10+
# shellcheck disable=SC1091 # setup file is in nix store
11+
source "$stdenv"/setup
912
fi
1013

1114
# Better to use compgen, but stdenv bash doesn't have it.
@@ -17,10 +20,10 @@ __dumpEnv() {
1720

1821
printf ' "bashFunctions": {\n'
1922
local __first=1
20-
while read __line; do
23+
while read -r __line; do
2124
if ! [[ $__line =~ ^declare\ -f\ (.*) ]]; then continue; fi
2225
__fun_name="${BASH_REMATCH[1]}"
23-
__fun_body="$(type $__fun_name)"
26+
__fun_body="$(type "$__fun_name")"
2427
if [[ $__fun_body =~ \{(.*)\} ]]; then
2528
if [[ -z $__first ]]; then printf ',\n'; else __first=; fi
2629
__fun_body="${BASH_REMATCH[1]}"
@@ -37,7 +40,7 @@ __dumpEnv() {
3740

3841
printf ' "variables": {\n'
3942
local __first=1
40-
while read __line; do
43+
while read -r __line; do
4144
if ! [[ $__line =~ ^declare\ (-[^ ])\ ([^=]*) ]]; then continue; fi
4245
local type="${BASH_REMATCH[1]}"
4346
local __var_name="${BASH_REMATCH[2]}"
@@ -76,7 +79,9 @@ __dumpEnv() {
7679
elif [[ $type == -a ]]; then
7780
printf '"type": "array", "value": ['
7881
local __first2=1
82+
# shellcheck disable=SC1087 # Complex array manipulation, syntax is correct
7983
__var_name="$__var_name[@]"
84+
# shellcheck disable=SC1087 # Complex array manipulation, syntax is correct
8085
for __i in "${!__var_name}"; do
8186
if [[ -z $__first2 ]]; then printf ', '; else __first2=; fi
8287
__escapeString "$__i"
@@ -142,6 +147,7 @@ __dumpEnvToOutput() {
142147
# array with a format like `outname => /nix/store/hash-drvname-outname`.
143148
# Otherwise it is a space-separated list of output variable names.
144149
if [ -e "$NIX_ATTRS_SH_FILE" ]; then
150+
# shellcheck disable=SC2154 # outputs is set by sourced file
145151
for __output in "${outputs[@]}"; do
146152
__dumpEnvToOutput "$__output"
147153
done

tests/functional/ca/build-with-garbage-path.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ requireDaemonNewerThan "2.4pre20210621"
88

99
# Get the output path of `rootCA`, and put some garbage instead
1010
outPath="$(nix-build ./content-addressed.nix -A rootCA --no-out-link)"
11+
# shellcheck disable=SC2046 # Multiple store paths need to become individual args
1112
nix-store --delete $(nix-store -q --referrers-closure "$outPath")
1213
touch "$outPath"
1314

tests/functional/ca/common.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck shell=bash
12
source ../common.sh
23

34
enableFeatures "ca-derivations"

tests/functional/characterisation-test-infra.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ echo Bye! > "$TEST_ROOT/expected"
4040
diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
4141
(( "$badDiff" == 1 ))
4242
)
43-
[[ "$(echo Bye! )" == $(< "$TEST_ROOT/expected") ]]
43+
[[ "Bye!" == $(< "$TEST_ROOT/expected") ]]
4444

4545
# _NIX_TEST_ACCEPT=1 matches non-empty
4646
echo Hi! > "$TEST_ROOT/got"
@@ -57,7 +57,7 @@ echo Bye! > "$TEST_ROOT/expected"
5757
_NIX_TEST_ACCEPT=1 diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"
5858
(( "$badDiff" == 1 ))
5959
)
60-
[[ "$(echo Hi! )" == $(< "$TEST_ROOT/expected") ]]
60+
[[ "Hi!" == $(< "$TEST_ROOT/expected") ]]
6161
# second time succeeds
6262
(
6363
diffAndAcceptInner test "$TEST_ROOT/got" "$TEST_ROOT/expected"

0 commit comments

Comments
 (0)