@eslint-sh/eslint-plugin 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -8
- package/dist/command-harvest/builtins/bash.d.ts +1 -1
- package/dist/command-harvest/builtins/bash.js +1 -1
- package/dist/command-harvest/builtins/bats.d.ts +2 -0
- package/dist/command-harvest/builtins/bats.js +3 -0
- package/dist/command-harvest/wrapper-table.d.ts +3 -19
- package/dist/command-harvest/wrapper-table.js +8 -38
- package/dist/configs/bash-3-2.d.ts +7 -6
- package/dist/configs/bash-3-2.js +5 -3
- package/dist/configs/posix-portable.d.ts +1 -1
- package/dist/configs/posix-portable.js +1 -0
- package/dist/declaration-conventions/read-declared-commands.d.ts +2 -2
- package/dist/declaration-conventions/read-declared-commands.js +2 -2
- package/dist/eslint-plugin-syntax.d.ts +4 -0
- package/dist/eslint-plugin.d.ts +86 -40
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -2
- package/dist/language/shell-language-options.d.ts +18 -15
- package/dist/language/shell-language-options.js +33 -26
- package/dist/language/shell-language.d.ts +10 -9
- package/dist/language/shell-language.js +18 -35
- package/dist/language/shell-source-code.d.ts +17 -9
- package/dist/language/shell-source-code.js +53 -12
- package/dist/rules/bash-variable-semantics.d.ts +22 -0
- package/dist/rules/bash-variable-semantics.js +41 -0
- package/dist/rules/compat/create-compat-rule.js +1 -1
- package/dist/rules/compat/declaration-options.d.ts +2 -2
- package/dist/rules/compat/declaration-options.js +5 -2
- package/dist/rules/compat/no-append-all-redirect.js +1 -1
- package/dist/rules/compat/no-associative-arrays.js +2 -2
- package/dist/rules/compat/no-brace-sequence-padding-step.d.ts +15 -0
- package/dist/rules/compat/no-brace-sequence-padding-step.js +287 -0
- package/dist/rules/compat/no-case-attributes.js +3 -3
- package/dist/rules/compat/no-case-fallthrough.js +2 -2
- package/dist/rules/compat/no-case-modification.js +2 -2
- package/dist/rules/compat/no-coproc.js +1 -1
- package/dist/rules/compat/no-declare-g.js +3 -3
- package/dist/rules/compat/no-double-bracket.js +2 -2
- package/dist/rules/compat/no-epoch-variables.js +2 -2
- package/dist/rules/compat/no-fd-variable.js +1 -1
- package/dist/rules/compat/no-globstar.js +1 -1
- package/dist/rules/compat/no-lastpipe-semantics.js +2 -2
- package/dist/rules/compat/no-let.js +2 -1
- package/dist/rules/compat/no-mapfile.js +4 -2
- package/dist/rules/compat/no-nameref.js +3 -3
- package/dist/rules/compat/no-negative-array-index.js +39 -9
- package/dist/rules/compat/no-nounset-empty-array.js +15 -4
- package/dist/rules/compat/no-parameter-transformation.js +2 -2
- package/dist/rules/compat/no-pipe-all.js +1 -1
- package/dist/rules/compat/no-printf-time-format.js +4 -2
- package/dist/rules/compat/no-source.js +2 -1
- package/dist/rules/compat/no-test-v.js +4 -2
- package/dist/rules/compat/no-unicode-escape.js +2 -2
- package/dist/rules/compat/no-wait-n.js +4 -2
- package/dist/rules/compat/nounset-array-proof.d.ts +8 -0
- package/dist/rules/compat/nounset-array-proof.js +563 -0
- package/dist/rules/compat/posix-absent-command.d.ts +7 -8
- package/dist/rules/compat/posix-absent-command.js +17 -15
- package/dist/rules/compat/shopt-options.js +3 -1
- package/dist/rules/compat/version-gates.d.ts +10 -10
- package/dist/rules/compat/version-gates.js +21 -13
- package/dist/rules/create-wrapper-rule.js +12 -7
- package/dist/rules/index.js +2 -0
- package/dist/rules/no-dynamic-invocation.d.ts +0 -8
- package/dist/rules/no-dynamic-invocation.js +7 -15
- package/dist/rules/no-eval.js +3 -1
- package/dist/rules/no-masked-exit-status.js +15 -8
- package/dist/rules/no-secret-env-reads.d.ts +4 -3
- package/dist/rules/no-secret-env-reads.js +37 -14
- package/dist/rules/no-secret-flags.d.ts +2 -1
- package/dist/rules/no-secret-flags.js +7 -8
- package/dist/rules/no-unchecked-cd.js +3 -1
- package/dist/rules/no-undeclared-commands.d.ts +1 -15
- package/dist/rules/no-undeclared-commands.js +3 -15
- package/dist/rules/no-unused-declarations.d.ts +1 -18
- package/dist/rules/no-unused-declarations.js +9 -34
- package/dist/rules/prefer-local.js +4 -3
- package/dist/rules/quote-expansions.js +3 -28
- package/dist/rules/require-network-wrapper.d.ts +2 -17
- package/dist/rules/require-network-wrapper.js +33 -4
- package/dist/rules/require-tty-guard.js +30 -1
- package/dist/rules/resolve-declaration-convention.d.ts +5 -6
- package/dist/rules/resolve-declaration-convention.js +5 -6
- package/dist/rules/resolve-network-wrapper.d.ts +19 -0
- package/dist/rules/resolve-network-wrapper.js +57 -26
- package/dist/rules/resolve-transparent-wrappers.d.ts +43 -0
- package/dist/rules/resolve-transparent-wrappers.js +98 -0
- package/dist/rules/set-options.d.ts +2 -1
- package/dist/rules/set-options.js +17 -5
- package/dist/rules/shebang-interpreter.js +4 -2
- package/dist/rules/transparent-wrappers.d.ts +4 -3
- package/dist/rules/transparent-wrappers.js +5 -4
- package/dist/rules/user-pattern.d.ts +5 -3
- package/dist/rules/user-pattern.js +6 -4
- package/dist/syntax/index.d.ts +4 -0
- package/dist/syntax/index.js +4 -0
- package/docs/compat.md +90 -34
- package/docs/custom-rule-tutorial.md +9 -3
- package/docs/examples/no-listed-commands-rule.ts +2 -2
- package/docs/rules/README.md +38 -5
- package/docs/rules/_template.md +2 -2
- package/docs/rules/compat/no-append-all-redirect.md +12 -12
- package/docs/rules/compat/no-associative-arrays.md +14 -14
- package/docs/rules/compat/no-brace-sequence-padding-step.md +90 -0
- package/docs/rules/compat/no-case-attributes.md +13 -13
- package/docs/rules/compat/no-case-fallthrough.md +12 -12
- package/docs/rules/compat/no-case-modification.md +11 -11
- package/docs/rules/compat/no-coproc.md +13 -13
- package/docs/rules/compat/no-declare-g.md +13 -13
- package/docs/rules/compat/no-double-bracket.md +2 -2
- package/docs/rules/compat/no-epoch-variables.md +13 -13
- package/docs/rules/compat/no-fd-variable.md +12 -12
- package/docs/rules/compat/no-globstar.md +13 -13
- package/docs/rules/compat/no-lastpipe-semantics.md +13 -13
- package/docs/rules/compat/no-let.md +2 -2
- package/docs/rules/compat/no-mapfile.md +16 -16
- package/docs/rules/compat/no-nameref.md +13 -13
- package/docs/rules/compat/no-negative-array-index.md +14 -14
- package/docs/rules/compat/no-nounset-empty-array.md +72 -17
- package/docs/rules/compat/no-parameter-transformation.md +19 -19
- package/docs/rules/compat/no-pipe-all.md +13 -13
- package/docs/rules/compat/no-printf-time-format.md +13 -13
- package/docs/rules/compat/no-source.md +2 -2
- package/docs/rules/compat/no-test-v.md +12 -12
- package/docs/rules/compat/no-unicode-escape.md +13 -13
- package/docs/rules/compat/no-wait-n.md +13 -13
- package/docs/rules/no-dynamic-invocation.md +17 -12
- package/docs/rules/no-eval.md +6 -1
- package/docs/rules/no-masked-exit-status.md +4 -0
- package/docs/rules/no-secret-env-reads.md +34 -3
- package/docs/rules/no-secret-flags.md +19 -2
- package/docs/rules/no-unchecked-cd.md +9 -2
- package/docs/rules/no-undeclared-commands.md +16 -15
- package/docs/rules/no-unused-declarations.md +17 -20
- package/docs/rules/prefer-local.md +20 -2
- package/docs/rules/quote-expansions.md +8 -5
- package/docs/rules/require-network-wrapper.md +22 -17
- package/docs/rules/require-shebang.md +10 -4
- package/docs/rules/require-strict-mode.md +6 -0
- package/docs/rules/require-tty-guard.md +4 -1
- package/docs/shellcheck.md +10 -5
- package/docs/transparent-wrappers.md +97 -0
- package/docs/untrusted-code.md +440 -0
- package/docs/wrapper-rules.md +9 -0
- package/package.json +2 -2
- package/dist/language/end-of-input-marker.d.ts +0 -29
- package/dist/language/end-of-input-marker.js +0 -88
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `sh/compat/no-coproc`
|
|
2
2
|
|
|
3
|
-
Disallow the `coproc` reserved word in scripts
|
|
3
|
+
Disallow the `coproc` reserved word in scripts that must support a shell lacking it: Bash older than 4.0,
|
|
4
4
|
including the Bash 3.2 that macOS ships as `/bin/bash`, and POSIX sh.
|
|
5
5
|
|
|
6
6
|
| Configs | Fixable | Languages |
|
|
@@ -18,19 +18,19 @@ The portable alternative is a named pipe: create it with `mkfifo`, start the cop
|
|
|
18
18
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
19
19
|
described in [version compatibility](../../compat.md):
|
|
20
20
|
|
|
21
|
-
- `
|
|
22
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
23
|
-
- `dialect: "posix"`: reports
|
|
21
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
22
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.0`.
|
|
23
|
+
- `dialect: "posix"`: reports regardless of Bash releases.
|
|
24
24
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
25
25
|
|
|
26
26
|
## Options
|
|
27
27
|
|
|
28
|
-
This rule has no options. Set the
|
|
28
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
29
29
|
|
|
30
30
|
```js
|
|
31
31
|
// eslint.config.js
|
|
32
32
|
{
|
|
33
|
-
languageOptions: { dialect: 'bash',
|
|
33
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
34
34
|
rules: {
|
|
35
35
|
'sh/compat/no-coproc': 'error',
|
|
36
36
|
},
|
|
@@ -41,9 +41,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
41
41
|
|
|
42
42
|
### Incorrect
|
|
43
43
|
|
|
44
|
-
With `
|
|
44
|
+
With `minBashVersion: "3.2"`:
|
|
45
45
|
|
|
46
|
-
<!-- example: {"dialect": "bash", "
|
|
46
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 2} -->
|
|
47
47
|
```sh
|
|
48
48
|
coproc worker { cat; }
|
|
49
49
|
coproc sort
|
|
@@ -51,9 +51,9 @@ coproc sort
|
|
|
51
51
|
|
|
52
52
|
### Correct
|
|
53
53
|
|
|
54
|
-
With `
|
|
54
|
+
With `minBashVersion: "3.2"`:
|
|
55
55
|
|
|
56
|
-
<!-- example: {"dialect": "bash", "
|
|
56
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
57
57
|
```sh
|
|
58
58
|
fifo=$(mktemp -u) && mkfifo "$fifo"
|
|
59
59
|
cat < "$fifo" &
|
|
@@ -61,16 +61,16 @@ exec 3> "$fifo"
|
|
|
61
61
|
printf '%s\n' hello >&3
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
With `
|
|
64
|
+
With `minBashVersion: "4.0"` or newer, or with no `minBashVersion`, the original forms are fine.
|
|
65
65
|
|
|
66
66
|
## When not to use it
|
|
67
67
|
|
|
68
68
|
Turn the rule off when your scripts never run on Bash older than 4.0, or leave
|
|
69
|
-
`
|
|
69
|
+
`minBashVersion` unset, which makes the rule report nothing.
|
|
70
70
|
|
|
71
71
|
## Relationship to shellcheck
|
|
72
72
|
|
|
73
73
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
74
74
|
layer. Run shellcheck beside it.
|
|
75
75
|
|
|
76
|
-
shellcheck has no check for `coproc` in a script that must run on an older Bash; it cannot
|
|
76
|
+
shellcheck has no check for `coproc` in a script that must run on an older Bash; it cannot check support for a minimum Bash version. This rule checks that support requirement.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `sh/compat/no-declare-g`
|
|
2
2
|
|
|
3
|
-
Disallow `declare -g` and `typeset -g` in scripts
|
|
3
|
+
Disallow `declare -g` and `typeset -g` in scripts that must support a shell lacking the `-g` option: Bash
|
|
4
4
|
older than 4.2, including the Bash 3.2 that macOS ships as `/bin/bash`, and POSIX sh.
|
|
5
5
|
|
|
6
6
|
| Configs | Fixable | Languages |
|
|
@@ -20,19 +20,19 @@ The message says so. For a plain `-g` (and `-gx`, which `export name=value` cove
|
|
|
20
20
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
21
21
|
described in [version compatibility](../../compat.md):
|
|
22
22
|
|
|
23
|
-
- `
|
|
24
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
25
|
-
- `dialect: "posix"`: reports
|
|
23
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
24
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.2`.
|
|
25
|
+
- `dialect: "posix"`: reports regardless of Bash releases, because POSIX sh has no `declare`.
|
|
26
26
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
27
27
|
|
|
28
28
|
## Options
|
|
29
29
|
|
|
30
|
-
This rule has no options. Set the
|
|
30
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
33
|
// eslint.config.js
|
|
34
34
|
{
|
|
35
|
-
languageOptions: { dialect: 'bash',
|
|
35
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
36
36
|
rules: {
|
|
37
37
|
'sh/compat/no-declare-g': 'error',
|
|
38
38
|
},
|
|
@@ -43,9 +43,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
43
43
|
|
|
44
44
|
### Incorrect
|
|
45
45
|
|
|
46
|
-
With `
|
|
46
|
+
With `minBashVersion: "3.2"`:
|
|
47
47
|
|
|
48
|
-
<!-- example: {"dialect": "bash", "
|
|
48
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 2} -->
|
|
49
49
|
```sh
|
|
50
50
|
f() {
|
|
51
51
|
declare -g counter=0
|
|
@@ -55,9 +55,9 @@ f() {
|
|
|
55
55
|
|
|
56
56
|
### Correct
|
|
57
57
|
|
|
58
|
-
With `
|
|
58
|
+
With `minBashVersion: "3.2"`:
|
|
59
59
|
|
|
60
|
-
<!-- example: {"dialect": "bash", "
|
|
60
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
61
61
|
```sh
|
|
62
62
|
f() {
|
|
63
63
|
counter=0
|
|
@@ -65,16 +65,16 @@ f() {
|
|
|
65
65
|
}
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
With `
|
|
68
|
+
With `minBashVersion: "4.2"` or newer, or with no `minBashVersion`, the original forms are fine.
|
|
69
69
|
|
|
70
70
|
## When not to use it
|
|
71
71
|
|
|
72
72
|
Turn the rule off when your scripts never run on Bash older than 4.2, or leave
|
|
73
|
-
`
|
|
73
|
+
`minBashVersion` unset, which makes the rule report nothing.
|
|
74
74
|
|
|
75
75
|
## Relationship to shellcheck
|
|
76
76
|
|
|
77
77
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
78
78
|
layer. Run shellcheck beside it.
|
|
79
79
|
|
|
80
|
-
shellcheck does not know which Bash a script must run on, so it cannot report `declare -g` for a Bash 3.2
|
|
80
|
+
shellcheck does not know which Bash a script must run on, so it cannot report `declare -g` for a script that must support Bash 3.2. This rule checks that support requirement.
|
|
@@ -18,12 +18,12 @@ The portable alternatives are `[ … ]` for tests and `case` for pattern matchin
|
|
|
18
18
|
|
|
19
19
|
This is a POSIX-only gate. Every Bash has `[[`, so whether the rule reports depends only on `dialect`, as described in [version compatibility](../../compat.md):
|
|
20
20
|
|
|
21
|
-
- `dialect: "posix"`: reports
|
|
21
|
+
- `dialect: "posix"`: reports regardless of Bash releases.
|
|
22
22
|
- `dialect: "bash"` (the default), `"bats"`, `"mksh"` or `"zsh"`: never reports.
|
|
23
23
|
|
|
24
24
|
## Options
|
|
25
25
|
|
|
26
|
-
This rule has no options. Set the
|
|
26
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
27
27
|
|
|
28
28
|
```js
|
|
29
29
|
// eslint.config.js
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `sh/compat/no-epoch-variables`
|
|
2
2
|
|
|
3
|
-
Disallow `$EPOCHSECONDS` and `$EPOCHREALTIME` in scripts
|
|
3
|
+
Disallow `$EPOCHSECONDS` and `$EPOCHREALTIME` in scripts that must support a shell lacking them: Bash older
|
|
4
4
|
than 5.0, including the Bash 3.2 that macOS ships as `/bin/bash`, and POSIX sh.
|
|
5
5
|
|
|
6
6
|
| Configs | Fixable | Languages |
|
|
@@ -20,19 +20,19 @@ The usual alternative is `$(date +%s)`. It is not POSIX: `%s` is an extension th
|
|
|
20
20
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
21
21
|
described in [version compatibility](../../compat.md):
|
|
22
22
|
|
|
23
|
-
- `
|
|
24
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
25
|
-
- `dialect: "posix"`: reports
|
|
23
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
24
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `5.0`.
|
|
25
|
+
- `dialect: "posix"`: reports regardless of Bash releases, because POSIX sh does not set either variable.
|
|
26
26
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
27
27
|
|
|
28
28
|
## Options
|
|
29
29
|
|
|
30
|
-
This rule has no options. Set the
|
|
30
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
33
|
// eslint.config.js
|
|
34
34
|
{
|
|
35
|
-
languageOptions: { dialect: 'bash',
|
|
35
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
36
36
|
rules: {
|
|
37
37
|
'sh/compat/no-epoch-variables': 'error',
|
|
38
38
|
},
|
|
@@ -43,9 +43,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
43
43
|
|
|
44
44
|
### Incorrect
|
|
45
45
|
|
|
46
|
-
With `
|
|
46
|
+
With `minBashVersion: "3.2"`:
|
|
47
47
|
|
|
48
|
-
<!-- example: {"dialect": "bash", "
|
|
48
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 2} -->
|
|
49
49
|
```sh
|
|
50
50
|
start=$EPOCHSECONDS
|
|
51
51
|
run_tests
|
|
@@ -54,9 +54,9 @@ echo "took $(( EPOCHSECONDS - start ))s"
|
|
|
54
54
|
|
|
55
55
|
### Correct
|
|
56
56
|
|
|
57
|
-
With `
|
|
57
|
+
With `minBashVersion: "3.2"`:
|
|
58
58
|
|
|
59
|
-
<!-- example: {"dialect": "bash", "
|
|
59
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
60
60
|
```sh
|
|
61
61
|
start=$(date +%s)
|
|
62
62
|
run_tests
|
|
@@ -64,11 +64,11 @@ echo "took $(( $(date +%s) - start ))s"
|
|
|
64
64
|
echo 'the variable is spelled $EPOCHSECONDS'
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
With `
|
|
67
|
+
With `minBashVersion: "5.0"` or newer, or with no `minBashVersion`, both variables are fine.
|
|
68
68
|
|
|
69
69
|
## When not to use it
|
|
70
70
|
|
|
71
|
-
Turn the rule off when your scripts never run on Bash older than 5.0, or leave `
|
|
71
|
+
Turn the rule off when your scripts never run on Bash older than 5.0, or leave `minBashVersion`
|
|
72
72
|
unset, which makes the rule report nothing.
|
|
73
73
|
|
|
74
74
|
## Relationship to shellcheck
|
|
@@ -76,4 +76,4 @@ unset, which makes the rule report nothing.
|
|
|
76
76
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
77
77
|
layer. Run shellcheck beside it.
|
|
78
78
|
|
|
79
|
-
shellcheck 0.11.0 reports `$EPOCHSECONDS` and `$EPOCHREALTIME` as undefined in POSIX sh (SC3028) under `-s sh`, and nothing under `-s bash`. It does not know which Bash release a script must run on, so it reports nothing for either variable in a Bash 4.4
|
|
79
|
+
shellcheck 0.11.0 reports `$EPOCHSECONDS` and `$EPOCHREALTIME` as undefined in POSIX sh (SC3028) under `-s sh`, and nothing under `-s bash`. It does not know which Bash release a script must run on, so it reports nothing for either variable in a script that must support Bash 4.4. This rule checks that support requirement.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# `sh/compat/no-fd-variable`
|
|
2
2
|
|
|
3
3
|
Disallow `{varname}` redirections, which have the shell pick a free file descriptor and store its
|
|
4
|
-
number in a variable (`exec {fd}>file`), in scripts
|
|
4
|
+
number in a variable (`exec {fd}>file`), in scripts that must support a shell lacking them: Bash older than
|
|
5
5
|
4.1, including the Bash 3.2 that macOS ships as `/bin/bash`, and POSIX sh.
|
|
6
6
|
|
|
7
7
|
| Configs | Fixable | Languages |
|
|
@@ -21,18 +21,18 @@ Under `dialect: "posix"` the parser itself rejects `{varname}` redirections, so
|
|
|
21
21
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
22
22
|
described in [version compatibility](../../compat.md):
|
|
23
23
|
|
|
24
|
-
- `
|
|
25
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
24
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
25
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.1`.
|
|
26
26
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
27
27
|
|
|
28
28
|
## Options
|
|
29
29
|
|
|
30
|
-
This rule has no options. Set the
|
|
30
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
33
|
// eslint.config.js
|
|
34
34
|
{
|
|
35
|
-
languageOptions: { dialect: 'bash',
|
|
35
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
36
36
|
rules: {
|
|
37
37
|
'sh/compat/no-fd-variable': 'error',
|
|
38
38
|
},
|
|
@@ -43,9 +43,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
43
43
|
|
|
44
44
|
### Incorrect
|
|
45
45
|
|
|
46
|
-
With `
|
|
46
|
+
With `minBashVersion: "3.2"`:
|
|
47
47
|
|
|
48
|
-
<!-- example: {"dialect": "bash", "
|
|
48
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 2} -->
|
|
49
49
|
```sh
|
|
50
50
|
exec {log}>>"$logfile"
|
|
51
51
|
echo started >&"$log"
|
|
@@ -54,20 +54,20 @@ exec {log}>&-
|
|
|
54
54
|
|
|
55
55
|
### Correct
|
|
56
56
|
|
|
57
|
-
With `
|
|
57
|
+
With `minBashVersion: "3.2"`:
|
|
58
58
|
|
|
59
|
-
<!-- example: {"dialect": "bash", "
|
|
59
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
60
60
|
```sh
|
|
61
61
|
exec 3>>"$logfile"
|
|
62
62
|
echo started >&3
|
|
63
63
|
exec 3>&-
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
With `
|
|
66
|
+
With `minBashVersion: "4.1"` or newer, or with no `minBashVersion`, `{varname}` redirections are fine.
|
|
67
67
|
|
|
68
68
|
## When not to use it
|
|
69
69
|
|
|
70
|
-
Turn the rule off when your scripts never run on Bash older than 4.1, or leave `
|
|
70
|
+
Turn the rule off when your scripts never run on Bash older than 4.1, or leave `minBashVersion`
|
|
71
71
|
unset, which makes the rule report nothing.
|
|
72
72
|
|
|
73
73
|
## Relationship to shellcheck
|
|
@@ -75,4 +75,4 @@ unset, which makes the rule report nothing.
|
|
|
75
75
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
76
76
|
layer. Run shellcheck beside it.
|
|
77
77
|
|
|
78
|
-
shellcheck reports `{varname}` redirections only for a script it treats as POSIX `sh` (its SC3xxx portability checks). It does not know which Bash release a script must run on, so it cannot report them for a Bash 3.2
|
|
78
|
+
shellcheck reports `{varname}` redirections only for a script it treats as POSIX `sh` (its SC3xxx portability checks). It does not know which Bash release a script must run on, so it cannot report them for a script that must support Bash 3.2. This rule checks that support requirement.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `sh/compat/no-globstar`
|
|
2
2
|
|
|
3
|
-
Disallow `shopt -s globstar` in scripts
|
|
3
|
+
Disallow `shopt -s globstar` in scripts that must support a shell lacking the option: Bash older than 4.0,
|
|
4
4
|
including the Bash 3.2 that macOS ships as `/bin/bash`, and POSIX sh.
|
|
5
5
|
|
|
6
6
|
| Configs | Fixable | Languages |
|
|
@@ -18,19 +18,19 @@ The portable alternative is `find`, for example `find dir -name '*.txt'`.
|
|
|
18
18
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
19
19
|
described in [version compatibility](../../compat.md):
|
|
20
20
|
|
|
21
|
-
- `
|
|
22
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
23
|
-
- `dialect: "posix"`: reports
|
|
21
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
22
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.0`.
|
|
23
|
+
- `dialect: "posix"`: reports regardless of Bash releases, because POSIX sh has no `shopt`.
|
|
24
24
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
25
25
|
|
|
26
26
|
## Options
|
|
27
27
|
|
|
28
|
-
This rule has no options. Set the
|
|
28
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
29
29
|
|
|
30
30
|
```js
|
|
31
31
|
// eslint.config.js
|
|
32
32
|
{
|
|
33
|
-
languageOptions: { dialect: 'bash',
|
|
33
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
34
34
|
rules: {
|
|
35
35
|
'sh/compat/no-globstar': 'error',
|
|
36
36
|
},
|
|
@@ -41,9 +41,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
41
41
|
|
|
42
42
|
### Incorrect
|
|
43
43
|
|
|
44
|
-
With `
|
|
44
|
+
With `minBashVersion: "3.2"`:
|
|
45
45
|
|
|
46
|
-
<!-- example: {"dialect": "bash", "
|
|
46
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 1} -->
|
|
47
47
|
```sh
|
|
48
48
|
shopt -s nullglob globstar
|
|
49
49
|
for f in src/**/*.sh; do lint "$f"; done
|
|
@@ -51,19 +51,19 @@ for f in src/**/*.sh; do lint "$f"; done
|
|
|
51
51
|
|
|
52
52
|
### Correct
|
|
53
53
|
|
|
54
|
-
With `
|
|
54
|
+
With `minBashVersion: "3.2"`:
|
|
55
55
|
|
|
56
|
-
<!-- example: {"dialect": "bash", "
|
|
56
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
57
57
|
```sh
|
|
58
58
|
find src -name '*.sh' -exec lint {} \;
|
|
59
59
|
shopt -s nullglob
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
With `
|
|
62
|
+
With `minBashVersion: "4.0"` or newer, or with no `minBashVersion`, `globstar` is fine.
|
|
63
63
|
|
|
64
64
|
## When not to use it
|
|
65
65
|
|
|
66
|
-
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `
|
|
66
|
+
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `minBashVersion`
|
|
67
67
|
unset, which makes the rule report nothing.
|
|
68
68
|
|
|
69
69
|
## Relationship to shellcheck
|
|
@@ -71,4 +71,4 @@ unset, which makes the rule report nothing.
|
|
|
71
71
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
72
72
|
layer. Run shellcheck beside it.
|
|
73
73
|
|
|
74
|
-
shellcheck reports `shopt` only for a script it treats as POSIX `sh` (its SC3xxx portability checks). It does not know which Bash release a script must run on, so it cannot report `globstar` for a Bash 3.2
|
|
74
|
+
shellcheck reports `shopt` only for a script it treats as POSIX `sh` (its SC3xxx portability checks). It does not know which Bash release a script must run on, so it cannot report `globstar` for a script that must support Bash 3.2. This rule checks that support requirement.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `sh/compat/no-lastpipe-semantics`
|
|
2
2
|
|
|
3
|
-
Disallow `shopt -s lastpipe` in scripts
|
|
3
|
+
Disallow `shopt -s lastpipe` in scripts that must support a shell lacking the option: Bash older than 4.2,
|
|
4
4
|
including the Bash 3.2 that macOS ships as `/bin/bash`, and POSIX sh.
|
|
5
5
|
|
|
6
6
|
| Configs | Fixable | Languages |
|
|
@@ -18,19 +18,19 @@ The portable alternative is process substitution: `while read -r line; do …; d
|
|
|
18
18
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
19
19
|
described in [version compatibility](../../compat.md):
|
|
20
20
|
|
|
21
|
-
- `
|
|
22
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
23
|
-
- `dialect: "posix"`: reports
|
|
21
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
22
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.2`.
|
|
23
|
+
- `dialect: "posix"`: reports regardless of Bash releases.
|
|
24
24
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
25
25
|
|
|
26
26
|
## Options
|
|
27
27
|
|
|
28
|
-
This rule has no options. Set the
|
|
28
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
29
29
|
|
|
30
30
|
```js
|
|
31
31
|
// eslint.config.js
|
|
32
32
|
{
|
|
33
|
-
languageOptions: { dialect: 'bash',
|
|
33
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
34
34
|
rules: {
|
|
35
35
|
'sh/compat/no-lastpipe-semantics': 'error',
|
|
36
36
|
},
|
|
@@ -41,9 +41,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
41
41
|
|
|
42
42
|
### Incorrect
|
|
43
43
|
|
|
44
|
-
With `
|
|
44
|
+
With `minBashVersion: "3.2"`:
|
|
45
45
|
|
|
46
|
-
<!-- example: {"dialect": "bash", "
|
|
46
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 1} -->
|
|
47
47
|
```sh
|
|
48
48
|
shopt -s lastpipe
|
|
49
49
|
cmd | while read -r line; do total=$line; done
|
|
@@ -51,23 +51,23 @@ cmd | while read -r line; do total=$line; done
|
|
|
51
51
|
|
|
52
52
|
### Correct
|
|
53
53
|
|
|
54
|
-
With `
|
|
54
|
+
With `minBashVersion: "3.2"`:
|
|
55
55
|
|
|
56
|
-
<!-- example: {"dialect": "bash", "
|
|
56
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
57
57
|
```sh
|
|
58
58
|
while read -r line; do total=$line; done < <(cmd)
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
With `
|
|
61
|
+
With `minBashVersion: "4.2"` or newer, or with no `minBashVersion`, the original forms are fine.
|
|
62
62
|
|
|
63
63
|
## When not to use it
|
|
64
64
|
|
|
65
65
|
Turn the rule off when your scripts never run on Bash older than 4.2, or leave
|
|
66
|
-
`
|
|
66
|
+
`minBashVersion` unset, which makes the rule report nothing.
|
|
67
67
|
|
|
68
68
|
## Relationship to shellcheck
|
|
69
69
|
|
|
70
70
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
71
71
|
layer. Run shellcheck beside it.
|
|
72
72
|
|
|
73
|
-
shellcheck warns that variables assigned in the last pipeline element are lost (SC2030/SC2031), and understands `shopt -s lastpipe` for that purpose, but it cannot
|
|
73
|
+
shellcheck warns that variables assigned in the last pipeline element are lost (SC2030/SC2031), and understands `shopt -s lastpipe` for that purpose, but it cannot check support for a minimum Bash version, so it cannot report the option for a script that must support Bash 3.2. This rule checks that support requirement.
|
|
@@ -27,12 +27,12 @@ The portable alternative is arithmetic expansion, `n=$((1 + 2))`. The rule offer
|
|
|
27
27
|
|
|
28
28
|
This is a POSIX-only gate. Every Bash has `let`, so whether the rule reports depends only on `dialect`, as described in [version compatibility](../../compat.md):
|
|
29
29
|
|
|
30
|
-
- `dialect: "posix"`: reports
|
|
30
|
+
- `dialect: "posix"`: reports regardless of Bash releases.
|
|
31
31
|
- `dialect: "bash"` (the default), `"bats"`, `"mksh"` or `"zsh"`: never reports.
|
|
32
32
|
|
|
33
33
|
## Options
|
|
34
34
|
|
|
35
|
-
This rule has no options. Set the
|
|
35
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
36
36
|
|
|
37
37
|
```js
|
|
38
38
|
// eslint.config.js
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `sh/compat/no-mapfile`
|
|
2
2
|
|
|
3
|
-
Disallow the `mapfile` builtin and its synonym `readarray` in scripts
|
|
3
|
+
Disallow the `mapfile` builtin and its synonym `readarray` in scripts that must support a shell lacking
|
|
4
4
|
them: Bash older than 4.0, including the Bash 3.2 that macOS ships as `/bin/bash`, and POSIX sh.
|
|
5
5
|
|
|
6
6
|
| Configs | Fixable | Languages |
|
|
@@ -16,9 +16,9 @@ never filled.
|
|
|
16
16
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
17
17
|
described in [version compatibility](../../compat.md):
|
|
18
18
|
|
|
19
|
-
- `
|
|
20
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
21
|
-
- `dialect: "posix"`: reports
|
|
19
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
20
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.0`.
|
|
21
|
+
- `dialect: "posix"`: reports regardless of Bash releases.
|
|
22
22
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
23
23
|
|
|
24
24
|
The rule reports every command whose effective command is `mapfile` or `readarray`, after
|
|
@@ -31,7 +31,7 @@ For `mapfile -t NAME` or `readarray -t NAME`, written directly (no wrapper and n
|
|
|
31
31
|
`VAR=value`) in a Bash or Bats file, the rule suggests a `while IFS= read -r` loop that fills
|
|
32
32
|
the same array the same way:
|
|
33
33
|
|
|
34
|
-
<!-- transform: {"kind": "suggestion", "dialect": "bash", "
|
|
34
|
+
<!-- transform: {"kind": "suggestion", "dialect": "bash", "minBashVersion": "3.2"} -->
|
|
35
35
|
|
|
36
36
|
```sh
|
|
37
37
|
mapfile -t lines < in.txt
|
|
@@ -57,12 +57,12 @@ assignment, a wrapper, and every file under `dialect: "posix"`.
|
|
|
57
57
|
|
|
58
58
|
## Options
|
|
59
59
|
|
|
60
|
-
This rule has no options. Set the
|
|
60
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
61
61
|
|
|
62
62
|
```js
|
|
63
63
|
// eslint.config.js
|
|
64
64
|
{
|
|
65
|
-
languageOptions: { dialect: 'bash',
|
|
65
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
66
66
|
rules: {
|
|
67
67
|
'sh/compat/no-mapfile': 'error',
|
|
68
68
|
},
|
|
@@ -73,9 +73,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
73
73
|
|
|
74
74
|
### Incorrect
|
|
75
75
|
|
|
76
|
-
With `
|
|
76
|
+
With `minBashVersion: "3.2"`:
|
|
77
77
|
|
|
78
|
-
<!-- example: {"dialect": "bash", "
|
|
78
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 3} -->
|
|
79
79
|
```sh
|
|
80
80
|
mapfile -t lines < in.txt # mapfile needs Bash 4.0
|
|
81
81
|
git ls-files | readarray -t files # readarray is the same builtin
|
|
@@ -84,9 +84,9 @@ command mapfile -t lines < in.txt # reached through the command wrapper
|
|
|
84
84
|
|
|
85
85
|
### Correct
|
|
86
86
|
|
|
87
|
-
With `
|
|
87
|
+
With `minBashVersion: "3.2"`:
|
|
88
88
|
|
|
89
|
-
<!-- example: {"dialect": "bash", "
|
|
89
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
90
90
|
```sh
|
|
91
91
|
{ lines=(); while IFS= read -r || [ -n "$REPLY" ]; do lines+=("$REPLY"); done; } < in.txt
|
|
92
92
|
|
|
@@ -95,16 +95,16 @@ while IFS= read -r line; do
|
|
|
95
95
|
done < in.txt
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
With `
|
|
98
|
+
With `minBashVersion: "4.0"` or newer, or with no `minBashVersion`:
|
|
99
99
|
|
|
100
|
-
<!-- example: {"dialect": "bash", "
|
|
100
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "4.0"} -->
|
|
101
101
|
```sh
|
|
102
102
|
mapfile -t lines < in.txt
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
## When not to use it
|
|
106
106
|
|
|
107
|
-
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `
|
|
107
|
+
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `minBashVersion`
|
|
108
108
|
unset, which makes the rule report nothing.
|
|
109
109
|
|
|
110
110
|
## Relationship to shellcheck
|
|
@@ -113,6 +113,6 @@ eslint-sh is a convention and contract linter: a policy layer, where shellcheck
|
|
|
113
113
|
layer. Run shellcheck beside it.
|
|
114
114
|
|
|
115
115
|
shellcheck reports Bash-only features in scripts it treats as POSIX sh (the SC3xxx checks), but
|
|
116
|
-
it cannot
|
|
116
|
+
it cannot check support for a minimum Bash version, so it cannot report `mapfile` in a script that must run on
|
|
117
117
|
Bash 3.2. shellcheck 0.11.0 does recommend `mapfile` or `read -a` over `a=($(cmd))` splitting (SC2207) under `-s bash`, which is
|
|
118
|
-
the opposite advice for a Bash 3.2
|
|
118
|
+
the opposite advice for a script that must support Bash 3.2. This rule checks that support requirement.
|