Skip to content

Commit 300e3a5

Browse files
committed
Appease the new formatter
Which currently misbehaves because of numtide/treefmt-nix#96.
1 parent 81a59b7 commit 300e3a5

File tree

8 files changed

+52
-47
lines changed

8 files changed

+52
-47
lines changed

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ inputs = {
5656
...
5757
};
5858
```
59+
5960
Make `strict-bash` and `strict-mode.bash` available to your derivations.
6061

6162
```nix
@@ -104,13 +105,14 @@ contents of this file change. By using `source`, all of your scripts are checked
104105
against a consistent strict mode.
105106

106107
Now, to the behavior of this “strict mode”:
107-
* `set -e` / `-o errexit`: exit immediately if any command has a non-zero exit;
108-
* `set -u` / `-o nounset`: references to undefined variables are an error;
109-
* `set -o pipefail`: if a command that is not the end of the a pipeline (`|`)
110-
fails, fail the whole pipeline;
111-
* `shopt -s inherit_errexit`: If a subshell (`$()`) fails, fail the calling
112-
shell; and
113-
* `trap … ERR`: When an error occurs, report _where_ it occurred.
108+
109+
- `set -e` / `-o errexit`: exit immediately if any command has a non-zero exit;
110+
- `set -u` / `-o nounset`: references to undefined variables are an error;
111+
- `set -o pipefail`: if a command that is not the end of the a pipeline (`|`)
112+
fails, fail the whole pipeline;
113+
- `shopt -s inherit_errexit`: If a subshell (`$()`) fails, fail the calling
114+
shell; and
115+
- `trap … ERR`: When an error occurs, report _where_ it occurred.
114116

115117
## FAQ
116118

@@ -162,27 +164,29 @@ Combining the two is also an option, and should ensure that the disabling is sco
162164

163165
There are other useful things to include in a script preface, but they
164166
aren’t included here for various reasons:
165-
* `IFS=$'\n\t'`: remove space as a field separator – often you want spaces
167+
168+
- `IFS=$'\n\t'`: remove space as a field separator – often you want spaces
166169
preserved, and only newlines or tabs to be used to separate fields. This
167170
eliminates a common mistake, but it doesn’t actually make Bash catch any
168171
additional bad behavior, so it’s not part of this strict mode.
169-
* `LC_ALL=C`: remove locale-dependence from the script. This is usually what
172+
- `LC_ALL=C`: remove locale-dependence from the script. This is usually what
170173
you want, but if it were part of strict mode, you would lose the value
171174
before you could decide you want to keep it, so it’s not included here.
172175

173176
## resources
174177

175-
* [Use Bash Strict Mode (Unless You Love Debugging)](http://redsymbol.net/articles/unofficial-bash-strict-mode/)
176-
* [Bash strict mode and why you should care](https://olivergondza.github.io/2019/10/01/bash-strict-mode.html)
177-
* [Fail Fast Bash Scripting](https://dougrichardson.us/notes/fail-fast-bash-scripting.html)
178-
178+
- [Use Bash Strict Mode (Unless You Love Debugging)](http://redsymbol.net/articles/unofficial-bash-strict-mode/)
179+
- [Bash strict mode and why you should care](https://olivergondza.github.io/2019/10/01/bash-strict-mode.html)
180+
- [Fail Fast Bash Scripting](https://dougrichardson.us/notes/fail-fast-bash-scripting.html)
179181

180-
[^1]: Sourcing a file relative to the script is difficult. The second line is a
182+
[^1]:
183+
Sourcing a file relative to the script is difficult. The second line is a
181184
compact way to do it fairly reliably. See [How do I get the directory where
182185
a Bash script is located from within the script
183186
itself?](https://stackoverflow.com/questions/59895) for a lot of discussion
184187
on this topic.
185188

186-
[^2]: The variable `SCRIPTDIR` above was chosen for affinity with the special
189+
[^2]:
190+
The variable `SCRIPTDIR` above was chosen for affinity with the special
187191
value that `shellcheck` uses to indicate an import relative to the script
188192
(however, the name that you use does not have to match `shellcheck`).

bin/strict-mode.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set \
44
-o pipefail
55

66
# `inherit_errexit` was only added in Bash 4.4, and MacOS still includes 3.2.
7-
[[ "${BASH_VERSINFO[0]}" -ge 4 && "${BASH_VERSINFO[1]}" -ge 4 ]] \
8-
&& shopt -s inherit_errexit
7+
[[ ${BASH_VERSINFO[0]} -ge 4 && ${BASH_VERSINFO[1]} -ge 4 ]] &&
8+
shopt -s inherit_errexit
99

1010
# shellcheck disable=SC2154 # `s` is assigned, but shellcheck can’t tell.
1111
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR

default-builder.sh renamed to default-builder.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
### shouldn’t have to copy it, but I can’t find it in the store, so I’m at
44
### a loss.
55

6-
source "${stdenv}/setup"
6+
# shellcheck disable=SC1091
7+
source "${stdenv:?}/setup"
78
genericBuild

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
["-e" "${path}/bin/strict-bash"]
3333
++ (
3434
if newArgs == []
35-
then [./default-builder.sh]
35+
then [./default-builder.bash]
3636
else newArgs
3737
);
3838
});

garnix.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
builds:
22
exclude: []
33
include:
4-
- '*.aarch64-linux'
5-
- '*.aarch64-linux.*'
6-
- '*.x86_64-linux'
7-
- '*.x86_64-linux.*'
8-
- '*.aarch64-darwin'
9-
- '*.aarch64-darwin.*'
10-
- '*.x86_64-darwin'
11-
- '*.x86_64-darwin.*'
12-
- 'nixosConfigurations.*'
4+
- "*.aarch64-darwin"
5+
- "*.aarch64-darwin.*"
6+
- "*.aarch64-linux"
7+
- "*.aarch64-linux.*"
8+
- "*.x86_64-darwin"
9+
- "*.x86_64-darwin.*"
10+
- "*.x86_64-linux"
11+
- "*.x86_64-linux.*"
12+
- "homeConfigurations.*"

test/all-tests.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ bats_require_minimum_version 1.5.0
1212
# Run from somewhere that we’re unlikely to find strict-mode.bash.
1313
cd "$TMPDIR"
1414
run -1 "$BATS_TEST_DIRNAME/is-on-path"
15-
[[ "$output" =~ strict-mode\.bash:\ No\ such\ file\ or\ directory$ ]]
15+
[[ $output =~ strict-mode\.bash:\ No\ such\ file\ or\ directory$ ]]
1616
}

test/generate

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ mkdir -p "${test_path}"
1414
cd "${template_path}" || exit 125
1515
for t in *; do
1616
old="${template_path}/${t}"
17-
if [[ "${t}" =~ .*\.bash$ ]]; then
17+
if [[ ${t} =~ .*\.bash$ ]]; then
1818
new="${test_path}/${t%.bash}"
1919
{
2020
cat "${test_path}.bash"
2121
echo
2222
cat "${old}"
23-
} > "${new}"
23+
} >"${new}"
2424
chmod +x "${new}"
2525
else
2626
new="${test_path}/${t}"

test/template/all-tests.bats

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,40 @@ bats_require_minimum_version 1.5.0
77

88
@test "failing subshell does" {
99
run -1 "$BATS_TEST_DIRNAME/null-hypothesis2"
10-
[[ "$output" =~ ^cat:\ nothing-here-man:\ No\ such\ file\ or\ directory &&
11-
"$output" =~ Error\ on\ line &&
12-
"$output" =~ :\ cat\ nothing-here-man ]]
10+
[[ $output =~ ^cat:\ nothing-here-man:\ No\ such\ file\ or\ directory &&
11+
$output =~ Error\ on\ line &&
12+
$output =~ :\ cat\ nothing-here-man ]]
1313
}
1414

1515
@test "set -e stops immediately" {
1616
run -1 "$BATS_TEST_DIRNAME/set-e"
17-
[[ "$output" =~ ^cat:\ nothing-here-man:\ No\ such\ file\ or\ directory &&
18-
"$output" =~ Error\ on\ line &&
19-
"$output" =~ :\ cat\ nothing-here-man ]]
17+
[[ $output =~ ^cat:\ nothing-here-man:\ No\ such\ file\ or\ directory &&
18+
$output =~ Error\ on\ line &&
19+
$output =~ :\ cat\ nothing-here-man ]]
2020
}
2121

2222
@test "set -u catches undefined variables" {
2323
run -1 "$BATS_TEST_DIRNAME/set-u"
24-
[[ "$output" =~ line &&
25-
"$output" =~ :\ undefined:\ unbound\ variable ]]
24+
[[ $output =~ line &&
25+
$output =~ :\ undefined:\ unbound\ variable ]]
2626
}
2727

2828
@test "set -o pipefail catches broken pipes" {
2929
run -1 "$BATS_TEST_DIRNAME/set-o-pipefail"
30-
[[ "$output" =~ Error\ on\ line &&
31-
"$output" =~ :\ cat ]]
30+
[[ $output =~ Error\ on\ line &&
31+
$output =~ :\ cat ]]
3232
}
3333

3434
@test "shopt -s inherit_errexit catches broken subshells" {
3535
run -1 "$BATS_TEST_DIRNAME/shopt-s-inherit_errexit"
36-
[[ "$output" =~ ^cat:\ nothing-here-man:\ No\ such\ file\ or\ directory &&
37-
"$output" =~ Error\ on\ line &&
38-
"$output" =~ :\ RESULT=\$\(cat\ nothing-here-man\) ]]
36+
[[ $output =~ ^cat:\ nothing-here-man:\ No\ such\ file\ or\ directory &&
37+
$output =~ Error\ on\ line &&
38+
$output =~ :\ RESULT=\$\(cat\ nothing-here-man\) ]]
3939
}
4040

4141
@test "inherit_errexit also pipefails" {
4242
run -1 "$BATS_TEST_DIRNAME/inherit_errexit-pipefail"
43-
[[ "$output" =~ ^cat:\ nothing-here-man:\ No\ such\ file\ or\ directory &&
44-
"$output" =~ Error\ on\ line &&
45-
"$output" =~ :\ RESULT=\$\(cat\ nothing-here-man\ |\ cat\) ]]
43+
[[ $output =~ ^cat:\ nothing-here-man:\ No\ such\ file\ or\ directory &&
44+
$output =~ Error\ on\ line &&
45+
$output =~ :\ RESULT=\$\(cat\ nothing-here-man\ |\ cat\) ]]
4646
}

0 commit comments

Comments
 (0)