@eslint-sh/eslint-plugin 0.7.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 +14 -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 +4 -3
- package/dist/configs/posix-portable.d.ts +1 -1
- 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.js +4 -4
- 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 +9 -9
- package/dist/rules/compat/version-gates.js +13 -13
- package/dist/rules/create-wrapper-rule.js +12 -7
- 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/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 +76 -27
- package/docs/custom-rule-tutorial.md +9 -3
- package/docs/examples/no-listed-commands-rule.ts +2 -2
- package/docs/rules/README.md +36 -4
- 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 +12 -12
- 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/shellcheck.md +9 -5
- package/docs/transparent-wrappers.md +97 -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
|
@@ -28,19 +28,19 @@ The portable alternative is to count in a loop and format with `printf`, for exa
|
|
|
28
28
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
29
29
|
described in [version compatibility](../../compat.md):
|
|
30
30
|
|
|
31
|
-
- `
|
|
32
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
33
|
-
- `dialect: "posix"`: reports
|
|
31
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
32
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.0`.
|
|
33
|
+
- `dialect: "posix"`: reports regardless of Bash releases, because POSIX does not specify brace expansion.
|
|
34
34
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
35
35
|
|
|
36
36
|
## Options
|
|
37
37
|
|
|
38
|
-
This rule has no options. Set the
|
|
38
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
39
39
|
|
|
40
40
|
```js
|
|
41
41
|
// eslint.config.js
|
|
42
42
|
{
|
|
43
|
-
languageOptions: { dialect: 'bash',
|
|
43
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
44
44
|
rules: {
|
|
45
45
|
'sh/compat/no-brace-sequence-padding-step': 'error',
|
|
46
46
|
},
|
|
@@ -51,9 +51,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
51
51
|
|
|
52
52
|
### Incorrect
|
|
53
53
|
|
|
54
|
-
With `
|
|
54
|
+
With `minBashVersion: "3.2"`:
|
|
55
55
|
|
|
56
|
-
<!-- example: {"dialect": "bash", "
|
|
56
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 3} -->
|
|
57
57
|
|
|
58
58
|
```sh
|
|
59
59
|
for n in {01..12}; do echo "report-$n"; done
|
|
@@ -63,9 +63,9 @@ cp backup{a..e..2}.tar /tmp
|
|
|
63
63
|
|
|
64
64
|
### Correct
|
|
65
65
|
|
|
66
|
-
With `
|
|
66
|
+
With `minBashVersion: "3.2"`:
|
|
67
67
|
|
|
68
|
-
<!-- example: {"dialect": "bash", "
|
|
68
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
69
69
|
|
|
70
70
|
```sh
|
|
71
71
|
n=1
|
|
@@ -75,11 +75,11 @@ echo '{01..12}'
|
|
|
75
75
|
a={01..03}
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
With `
|
|
78
|
+
With `minBashVersion: "4.0"` or newer, or with no `minBashVersion`, both forms are fine.
|
|
79
79
|
|
|
80
80
|
## When not to use it
|
|
81
81
|
|
|
82
|
-
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `
|
|
82
|
+
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `minBashVersion`
|
|
83
83
|
unset, which makes the rule report nothing.
|
|
84
84
|
|
|
85
85
|
## Relationship to shellcheck
|
|
@@ -87,4 +87,4 @@ unset, which makes the rule report nothing.
|
|
|
87
87
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
88
88
|
layer. Run shellcheck beside it.
|
|
89
89
|
|
|
90
|
-
shellcheck 0.11.0 reports SC3009 (brace expansion is undefined in POSIX sh) under `-s sh` for every brace expansion, a plain `{1..3}` and `{a,b}` included. Under `-s bash` it reports nothing for these sequences. It does not know which Bash release a script must run on, so it cannot report the padded and stepped forms for a Bash 3.2
|
|
90
|
+
shellcheck 0.11.0 reports SC3009 (brace expansion is undefined in POSIX sh) under `-s sh` for every brace expansion, a plain `{1..3}` and `{a,b}` included. Under `-s bash` it reports nothing for these sequences. It does not know which Bash release a script must run on, so it cannot report the padded and stepped forms for a script that must support Bash 3.2. This rule checks that support requirement.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# `sh/compat/no-case-attributes`
|
|
2
2
|
|
|
3
3
|
Disallow the case-converting attributes `declare -l` and `declare -u` (also through `typeset` and
|
|
4
|
-
`local`) in scripts
|
|
4
|
+
`local`) in scripts that must support a shell lacking them: Bash older than 4.0, including the Bash 3.2
|
|
5
5
|
that macOS ships as `/bin/bash`, and POSIX sh.
|
|
6
6
|
|
|
7
7
|
| Configs | Fixable | Languages |
|
|
@@ -19,19 +19,19 @@ The portable alternative is to convert the value when it is assigned, with `tr`:
|
|
|
19
19
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
20
20
|
described in [version compatibility](../../compat.md):
|
|
21
21
|
|
|
22
|
-
- `
|
|
23
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
24
|
-
- `dialect: "posix"`: reports
|
|
22
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
23
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.0`.
|
|
24
|
+
- `dialect: "posix"`: reports regardless of Bash releases, because POSIX sh has no `declare`.
|
|
25
25
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
26
26
|
|
|
27
27
|
## Options
|
|
28
28
|
|
|
29
|
-
This rule has no options. Set the
|
|
29
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
30
30
|
|
|
31
31
|
```js
|
|
32
32
|
// eslint.config.js
|
|
33
33
|
{
|
|
34
|
-
languageOptions: { dialect: 'bash',
|
|
34
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
35
35
|
rules: {
|
|
36
36
|
'sh/compat/no-case-attributes': 'error',
|
|
37
37
|
},
|
|
@@ -42,9 +42,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
42
42
|
|
|
43
43
|
### Incorrect
|
|
44
44
|
|
|
45
|
-
With `
|
|
45
|
+
With `minBashVersion: "3.2"`:
|
|
46
46
|
|
|
47
|
-
<!-- example: {"dialect": "bash", "
|
|
47
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 2} -->
|
|
48
48
|
|
|
49
49
|
```sh
|
|
50
50
|
declare -l answer=$1
|
|
@@ -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
|
|
|
62
62
|
```sh
|
|
63
63
|
answer=$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')
|
|
@@ -67,11 +67,11 @@ f() {
|
|
|
67
67
|
}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
With `
|
|
70
|
+
With `minBashVersion: "4.0"` or newer, or with no `minBashVersion`, the attributes are fine.
|
|
71
71
|
|
|
72
72
|
## When not to use it
|
|
73
73
|
|
|
74
|
-
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `
|
|
74
|
+
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `minBashVersion`
|
|
75
75
|
unset, which makes the rule report nothing.
|
|
76
76
|
|
|
77
77
|
## Relationship to shellcheck
|
|
@@ -79,4 +79,4 @@ unset, which makes the rule report nothing.
|
|
|
79
79
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
80
80
|
layer. Run shellcheck beside it.
|
|
81
81
|
|
|
82
|
-
Under `-s sh`, shellcheck 0.11.0 reports the command, not the option: `declare -l` and `declare -u` draw SC3044 (`declare` is undefined in POSIX sh), and `local -l` and `local -u` draw SC3043. Under `-s bash` it reports nothing for these options. It does not know which Bash release a script must run on, so it reports nothing for `declare -l` in a Bash 3.2
|
|
82
|
+
Under `-s sh`, shellcheck 0.11.0 reports the command, not the option: `declare -l` and `declare -u` draw SC3044 (`declare` is undefined in POSIX sh), and `local -l` and `local -u` draw SC3043. Under `-s bash` it reports nothing for these options. It does not know which Bash release a script must run on, so it reports nothing for `declare -l` in a script that must support Bash 3.2. This rule checks that support requirement.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# `sh/compat/no-case-fallthrough`
|
|
2
2
|
|
|
3
3
|
Disallow the `case` terminators `;&` (run the next branch without testing its pattern) and `;;&`
|
|
4
|
-
(go on testing the next patterns) in scripts
|
|
4
|
+
(go on testing the next patterns) in scripts that must support a shell lacking them: Bash older than 4.0,
|
|
5
5
|
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 both terminators, so a POSIX
|
|
|
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.0`.
|
|
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-case-fallthrough': '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
|
case $level in
|
|
51
51
|
debug) verbose=1 ;&
|
|
@@ -59,9 +59,9 @@ esac
|
|
|
59
59
|
|
|
60
60
|
### Correct
|
|
61
61
|
|
|
62
|
-
With `
|
|
62
|
+
With `minBashVersion: "3.2"`:
|
|
63
63
|
|
|
64
|
-
<!-- example: {"dialect": "bash", "
|
|
64
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2"} -->
|
|
65
65
|
```sh
|
|
66
66
|
case $level in
|
|
67
67
|
debug) verbose=1; log=1 ;;
|
|
@@ -75,11 +75,11 @@ case $file in
|
|
|
75
75
|
esac
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
With `
|
|
78
|
+
With `minBashVersion: "4.0"` or newer, or with no `minBashVersion`, both terminators are fine.
|
|
79
79
|
|
|
80
80
|
## When not to use it
|
|
81
81
|
|
|
82
|
-
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `
|
|
82
|
+
Turn the rule off when your scripts never run on Bash older than 4.0, or leave `minBashVersion`
|
|
83
83
|
unset, which makes the rule report nothing.
|
|
84
84
|
|
|
85
85
|
## Relationship to shellcheck
|
|
@@ -87,4 +87,4 @@ unset, which makes the rule report nothing.
|
|
|
87
87
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
88
88
|
layer. Run shellcheck beside it.
|
|
89
89
|
|
|
90
|
-
Under `-s sh`, shellcheck 0.11.0 reports `;&` and `;;&` as an error, SC2127 ("To use cases with ;&, specify #!/usr/bin/env bash or ksh", or the `;;&` equivalent naming bash), not as one of its SC3xxx portability checks. It reports the same SC2127 under `-s dash`, reports `;;&` (but not `;&`) under `-s ksh`, and reports nothing under `-s bash`. It does not know which Bash release a script must run on, so it reports nothing for either operator in a Bash 3.2
|
|
90
|
+
Under `-s sh`, shellcheck 0.11.0 reports `;&` and `;;&` as an error, SC2127 ("To use cases with ;&, specify #!/usr/bin/env bash or ksh", or the `;;&` equivalent naming bash), not as one of its SC3xxx portability checks. It reports the same SC2127 under `-s dash`, reports `;;&` (but not `;&`) under `-s ksh`, and reports nothing under `-s bash`. It does not know which Bash release a script must run on, so it reports nothing for either operator in a script that must support Bash 3.2. This rule checks that support requirement.
|
|
@@ -17,19 +17,19 @@ The report is on the whole expansion, with or without a trailing pattern (`${v^^
|
|
|
17
17
|
This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
|
|
18
18
|
described in [version compatibility](../../compat.md):
|
|
19
19
|
|
|
20
|
-
- `
|
|
21
|
-
- `dialect: "bash"` (the default) or `"bats"`: reports when `
|
|
20
|
+
- `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
|
|
21
|
+
- `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.0`.
|
|
22
22
|
- `dialect: "posix"`: reports nothing in practice for this syntax, because the POSIX parser rejects it with a parse error before any rule runs.
|
|
23
23
|
- `dialect: "mksh"` or `"zsh"`: never reports.
|
|
24
24
|
|
|
25
25
|
## Options
|
|
26
26
|
|
|
27
|
-
This rule has no options. Set the
|
|
27
|
+
This rule has no options. Set the required support through `languageOptions`:
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
30
|
// eslint.config.js
|
|
31
31
|
{
|
|
32
|
-
languageOptions: { dialect: 'bash',
|
|
32
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
33
33
|
rules: {
|
|
34
34
|
'sh/compat/no-case-modification': 'error',
|
|
35
35
|
},
|
|
@@ -40,9 +40,9 @@ This rule has no options. Set the target through `languageOptions`:
|
|
|
40
40
|
|
|
41
41
|
### Incorrect
|
|
42
42
|
|
|
43
|
-
With `
|
|
43
|
+
With `minBashVersion: "3.2"`:
|
|
44
44
|
|
|
45
|
-
<!-- example: {"dialect": "bash", "
|
|
45
|
+
<!-- example: {"dialect": "bash", "minBashVersion": "3.2", "findings": 3} -->
|
|
46
46
|
```sh
|
|
47
47
|
name=${input,,} # lowercase every character
|
|
48
48
|
title=${word^} # uppercase the first character
|
|
@@ -51,24 +51,24 @@ flag=${arg^^[a-z]} # with a pattern
|
|
|
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
|
name=$(printf '%s' "$input" | tr '[:upper:]' '[:lower:]')
|
|
59
59
|
title=$(printf '%s' "${word%"${word#?}"}" | tr '[:lower:]' '[:upper:]')"${word#?}"
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
With `
|
|
62
|
+
With `minBashVersion: "4.0"` or newer, or with no `minBashVersion`, the original forms are fine.
|
|
63
63
|
|
|
64
64
|
## When not to use it
|
|
65
65
|
|
|
66
66
|
Turn the rule off when your scripts never run on Bash older than 4.0, or leave
|
|
67
|
-
`
|
|
67
|
+
`minBashVersion` unset, which makes the rule report nothing.
|
|
68
68
|
|
|
69
69
|
## Relationship to shellcheck
|
|
70
70
|
|
|
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 case-modifying expansions in scripts it treats as POSIX sh (SC3059), but it cannot
|
|
74
|
+
shellcheck reports case-modifying expansions in scripts it treats as POSIX sh (SC3059), but it cannot check support for a minimum Bash version, so it cannot report `${v,,}` in a script that must run on Bash 3.2. This rule checks that support requirement.
|
|
@@ -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.
|