@eslint-sh/eslint-plugin 0.7.0 → 0.9.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 +53 -40
- package/dist/api.d.ts +92 -0
- package/dist/api.js +83 -0
- 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/harvest-commands.d.ts +2 -2
- package/dist/command-harvest/harvest-commands.js +2 -2
- 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 +7 -11
- package/dist/configs/posix-portable.js +4 -6
- package/dist/configuration-message.d.ts +14 -0
- package/dist/configuration-message.js +33 -0
- package/dist/declaration-conventions/get-declared-commands.d.ts +41 -0
- package/dist/declaration-conventions/{read-declared-commands.js → get-declared-commands.js} +43 -43
- package/dist/eslint-plugin-api.d.ts +1506 -0
- package/dist/eslint-plugin-syntax-analyze.d.ts +3 -3
- package/dist/eslint-plugin-syntax.d.ts +7 -4
- package/dist/eslint-plugin.d.ts +16 -1514
- package/dist/index.d.ts +14 -78
- package/dist/index.js +22 -74
- package/dist/language/command-resolution.d.ts +5 -5
- package/dist/language/command-resolution.js +11 -7
- package/dist/language/selector-classes.d.ts +7 -3
- package/dist/language/selector-classes.js +13 -4
- package/dist/language/shell-language-options.d.ts +21 -18
- package/dist/language/shell-language-options.js +41 -39
- package/dist/language/shell-language.d.ts +13 -10
- package/dist/language/shell-language.js +23 -45
- package/dist/language/shell-source-code.d.ts +74 -49
- package/dist/language/shell-source-code.js +135 -68
- package/dist/language/source-coordinates.d.ts +2 -0
- package/dist/language/source-coordinates.js +8 -4
- package/dist/language/syntax-view.js +19 -7
- package/dist/language/word-resolution.d.ts +2 -1
- package/dist/language/word-resolution.js +8 -3
- 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.d.ts +1 -1
- package/dist/rules/create-wrapper-rule.js +23 -16
- package/dist/rules/define-shell-rule.js +1 -1
- 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.d.ts +4 -3
- package/dist/rules/no-masked-exit-status.js +18 -10
- package/dist/rules/no-secret-env-reads.d.ts +6 -3
- package/dist/rules/no-secret-env-reads.js +49 -15
- package/dist/rules/no-secret-flags.d.ts +4 -1
- package/dist/rules/no-secret-flags.js +21 -11
- package/dist/rules/no-unchecked-cd.js +6 -3
- package/dist/rules/no-undeclared-commands.d.ts +1 -15
- package/dist/rules/no-undeclared-commands.js +11 -18
- package/dist/rules/no-unused-declarations.d.ts +1 -18
- package/dist/rules/no-unused-declarations.js +15 -36
- package/dist/rules/prefer-local.d.ts +3 -2
- package/dist/rules/prefer-local.js +7 -4
- package/dist/rules/quote-expansions.js +3 -28
- package/dist/rules/require-network-wrapper.d.ts +3 -18
- package/dist/rules/require-network-wrapper.js +43 -10
- package/dist/rules/require-strict-mode.d.ts +5 -46
- package/dist/rules/require-strict-mode.js +17 -107
- package/dist/rules/require-tty-guard.d.ts +2 -0
- package/dist/rules/require-tty-guard.js +8 -1
- package/dist/rules/resolve-declaration-convention.d.ts +9 -89
- package/dist/rules/resolve-declaration-convention.js +19 -72
- package/dist/rules/resolve-network-wrapper.d.ts +20 -2
- package/dist/rules/resolve-network-wrapper.js +71 -36
- package/dist/rules/resolve-transparent-wrappers.d.ts +38 -0
- package/dist/rules/resolve-transparent-wrappers.js +108 -0
- package/dist/rules/set-options.d.ts +3 -2
- package/dist/rules/set-options.js +18 -6
- package/dist/rules/shebang-interpreter.js +4 -2
- package/dist/rules/strict-mode-prologue.d.ts +43 -0
- package/dist/rules/strict-mode-prologue.js +91 -0
- package/dist/rules/transparent-wrappers.d.ts +4 -3
- package/dist/rules/transparent-wrappers.js +5 -4
- package/dist/rules/user-pattern.d.ts +9 -6
- package/dist/rules/user-pattern.js +16 -12
- package/dist/shell-dialect.d.ts +8 -0
- package/dist/shell-dialect.js +22 -0
- package/dist/syntax/analyze.d.ts +3 -3
- package/dist/syntax/analyze.js +3 -3
- package/dist/syntax/index.d.ts +7 -4
- package/dist/syntax/index.js +7 -4
- package/dist/version.js +2 -1
- package/docs/compat.md +81 -33
- package/docs/custom-rule-tutorial.md +31 -21
- package/docs/declaration-conventions.md +20 -23
- package/docs/error-codes.md +93 -0
- package/docs/examples/no-listed-commands-rule.ts +2 -2
- package/docs/examples/no-rm-rf-rule.mjs +8 -10
- package/docs/examples/sorted-declarations-rule.mjs +6 -9
- package/docs/examples/tsconfig.json +10 -0
- package/docs/rules/README.md +46 -6
- 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 +6 -2
- package/docs/rules/no-secret-env-reads.md +46 -5
- package/docs/rules/no-secret-flags.md +32 -6
- package/docs/rules/no-unchecked-cd.md +22 -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 +26 -21
- package/docs/rules/require-shebang.md +10 -4
- package/docs/rules/require-strict-mode.md +31 -23
- package/docs/rules/require-tty-guard.md +12 -3
- package/docs/selectors.md +7 -2
- package/docs/shellcheck.md +9 -5
- package/docs/transparent-wrappers.md +97 -0
- package/docs/wrapper-rules.md +11 -0
- package/package.json +3 -3
- package/dist/declaration-conventions/read-declared-commands.d.ts +0 -70
- package/dist/language/end-of-input-marker.d.ts +0 -29
- package/dist/language/end-of-input-marker.js +0 -88
|
@@ -88,9 +88,11 @@ This rule takes one options object:
|
|
|
88
88
|
- `allow` (`string[]`, default `[]`): variable names that may be assigned in a function without
|
|
89
89
|
`local`.
|
|
90
90
|
- `allowPattern` (`string`, default `"^[A-Z][A-Z0-9_]*$"`): a regular expression, compiled with the
|
|
91
|
-
`u` flag, that exempts every name it matches. A value that is not a valid regular expression is a
|
|
91
|
+
`u` flag (Unicode, case-sensitive), that exempts every name it matches. A value that is not a valid regular expression is a
|
|
92
92
|
configuration error. Setting it replaces the default, so `allowPattern: '^g_'` stops exempting
|
|
93
|
-
UPPER_CASE names.
|
|
93
|
+
UPPER_CASE names. For example, `'^g_'` exempts `g_cache` but not `G_cache`.
|
|
94
|
+
See [regular-expression options](./README.md#regular-expression-options) for the shared
|
|
95
|
+
compilation and configuration-error contract.
|
|
94
96
|
|
|
95
97
|
```js
|
|
96
98
|
// eslint.config.js
|
|
@@ -104,6 +106,22 @@ This rule takes one options object:
|
|
|
104
106
|
}
|
|
105
107
|
```
|
|
106
108
|
|
|
109
|
+
Regex syntax errors fail when this rule first runs on a file, naming the rule, option and
|
|
110
|
+
pattern. `--print-config` will not catch any regex syntax errors. See the
|
|
111
|
+
[shared compilation contract](./README.md#regular-expression-options).
|
|
112
|
+
|
|
113
|
+
### Matching examples
|
|
114
|
+
|
|
115
|
+
These examples use only this rule; a finding means the assignment needs `local`.
|
|
116
|
+
Option values below are JSON.
|
|
117
|
+
|
|
118
|
+
| Option value | Shell input | Findings |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| `{"allowPattern":"^g_"}` | `f(){ g_cache=1; }` | 0 |
|
|
121
|
+
| `{"allowPattern":"^g_"}` | `f(){ G_cache=1; }` | 1 |
|
|
122
|
+
| `{"allowPattern":"^\\p{Lu}+$"}` | `f(){ CACHE=1; }` | 0 |
|
|
123
|
+
| `{"allowPattern":"^\\p{Lu}+$"}` | `f(){ cache=1; }` | 1 |
|
|
124
|
+
|
|
107
125
|
### Patterns run against script-controlled text
|
|
108
126
|
|
|
109
127
|
`allowPattern` is tested against every variable name the linted script assigns in a function, and
|
|
@@ -137,7 +137,8 @@ exec "$@" # "$@" keeps every argument intact
|
|
|
137
137
|
|
|
138
138
|
## When not to use it
|
|
139
139
|
|
|
140
|
-
Disable the rule if you run shellcheck
|
|
140
|
+
Disable the rule if you run shellcheck and want to avoid double reports. This also drops
|
|
141
|
+
its checks in command-name position and `for … in` lists, which SC2086 does not report
|
|
141
142
|
(see below). For one line that relies on splitting on purpose, such as passing `$CFLAGS` to a
|
|
142
143
|
compiler, disable it on that line (`# eslint-disable-next-line sh/quote-expansions`) or rewrite
|
|
143
144
|
the value as an array (`"${cflags[@]}"`).
|
|
@@ -147,11 +148,13 @@ the value as an array (`"${cflags[@]}"`).
|
|
|
147
148
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
148
149
|
layer. Run shellcheck beside it.
|
|
149
150
|
|
|
150
|
-
This rule is one of eslint-sh's
|
|
151
|
+
This rule is one of eslint-sh's
|
|
152
|
+
[deliberate overlaps with shellcheck](../shellcheck.md#deliberate-overlaps). It covers the same
|
|
151
153
|
problem as SC2086 (double quote to prevent globbing and word splitting), and SC2068 for unquoted
|
|
152
154
|
`$@`. It exists for teams that run eslint-sh without shellcheck, so that this common mistake is
|
|
153
|
-
still caught. **
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
still caught. **Disabling this rule when you run shellcheck avoids double reports**, but also
|
|
156
|
+
drops checks in command-name position (`$cmd arg`) and `for … in` lists (`for x in $LIST`),
|
|
157
|
+
which SC2086 never reports. The rule does not try to match SC2086's heuristics: shellcheck skips
|
|
158
|
+
some expansions it can prove are safe, such as a variable it saw assigned a number, and this rule reports them
|
|
156
159
|
because it does no dataflow analysis. That is why `recommended` enables it at `warn` instead of
|
|
157
160
|
`error`.
|
|
@@ -62,7 +62,7 @@ It does not depend on `languageOptions`.
|
|
|
62
62
|
## Options
|
|
63
63
|
|
|
64
64
|
- `wrapper` (`string` or `WrapperSpec` object, no default): the wrapper network commands must be
|
|
65
|
-
run through. When it is unset, the rule uses `settings
|
|
65
|
+
run through. When it is unset, the rule uses `settings: { sh: { networkWrapper: 'with-retry' } }` (below); with
|
|
66
66
|
neither, the rule reports nothing. A string names a wrapper that takes no options
|
|
67
67
|
(or one of the default transparent wrappers, such as `timeout`, whose options are known). An
|
|
68
68
|
object declares the wrapper's options so the command after them is found:
|
|
@@ -72,44 +72,49 @@ It does not depend on `languageOptions`.
|
|
|
72
72
|
`assignmentOperands`, as in `sh-ast/analyze`'s `WrapperSpec`.
|
|
73
73
|
- `commands` (`string[]`, default `["curl", "wget", "nc", "ssh", "scp", "rsync", "git"]`): the
|
|
74
74
|
network commands. Setting it replaces the default list. `git` keeps its subcommand restriction
|
|
75
|
-
wherever it is listed.
|
|
76
|
-
- `
|
|
77
|
-
to its default).
|
|
75
|
+
wherever it is listed. An empty list removes all built-in commands.
|
|
76
|
+
- `additionalCommands` (`string[]`, default `[]`): more commands to check, added to `commands` (or
|
|
77
|
+
to its default). An empty addition changes nothing; overlapping names report only once.
|
|
78
78
|
|
|
79
79
|
```js
|
|
80
80
|
// eslint.config.js
|
|
81
81
|
{
|
|
82
82
|
rules: {
|
|
83
|
-
'sh/require-network-wrapper': ['error', { wrapper: 'retry',
|
|
83
|
+
'sh/require-network-wrapper': ['error', { wrapper: 'retry', additionalCommands: ['aws'] }],
|
|
84
84
|
},
|
|
85
85
|
}
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
### Declaring the wrapper once
|
|
88
|
+
### Declaring the wrapper once
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
`wrapper` option is invisible to them, and an undeclared `curl` behind it goes unreported.
|
|
94
|
-
|
|
95
|
-
Set the wrapper in shared settings instead, and all three rules read it:
|
|
90
|
+
Set the network policy in shared settings so every wrapper-following rule sees the
|
|
91
|
+
same command chain, including the declaration rules, `sh/no-eval`, and
|
|
92
|
+
`sh/no-dynamic-invocation`:
|
|
96
93
|
|
|
97
94
|
```js
|
|
98
95
|
// eslint.config.js
|
|
99
96
|
{
|
|
100
97
|
settings: { sh: { declarationConvention: commentPragma, networkWrapper: 'with-retry' } },
|
|
101
|
-
rules: { 'sh/require-network-wrapper': 'error' },
|
|
98
|
+
rules: { 'sh/require-network-wrapper': 'error' },
|
|
102
99
|
}
|
|
103
100
|
```
|
|
104
101
|
|
|
105
|
-
`networkWrapper`
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
with
|
|
102
|
+
`networkWrapper` accepts a name or a JSON-expressible `WrapperSpec` object, like the
|
|
103
|
+
`wrapper` rule option. A custom spec for a default wrapper name takes effect in every
|
|
104
|
+
consumer. Absolute and relative utility wrapper paths match by basename:
|
|
105
|
+
`/opt/bin/with-retry curl x` and `./bin/with-retry curl x` both run `curl` through
|
|
106
|
+
`with-retry`, and an undeclared `curl` is reported by the declaration rule.
|
|
107
|
+
|
|
108
|
+
A `wrapper` option that disagrees with the shared network policy now throws a clear
|
|
109
|
+
configuration error. Equivalent values are accepted; there is no silent override.
|
|
110
|
+
A wrapper set only as a rule option remains local to this network policy because other
|
|
111
|
+
rules cannot read its options. Prefer the shared setting. Malformed settings also stop linting.
|
|
109
112
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
`
|
|
113
|
+
Other project wrappers belong in
|
|
114
|
+
`settings: { sh: { transparentWrappers: ['with-lock'] } }`. This factory-based rule
|
|
115
|
+
reads those facts too, so `with-lock curl x` cannot hide an unwrapped network call.
|
|
116
|
+
[Shared transparent wrappers](../transparent-wrappers.md) documents the common resolver,
|
|
117
|
+
conflicting specs, path matching, and migration from the removed per-rule options.
|
|
113
118
|
|
|
114
119
|
## Examples
|
|
115
120
|
|
|
@@ -159,7 +164,7 @@ wget() { :; }; wget x # a function the file defines, not the clie
|
|
|
159
164
|
Leave the rule off if your project has no single wrapper for network calls, or if network
|
|
160
165
|
resilience is handled outside your scripts (for example by a proxy or by the CI runner). For a
|
|
161
166
|
policy about commands other than network clients, define your own rule with
|
|
162
|
-
[`createWrapperRule`](../wrapper-rules.md) rather than overloading `
|
|
167
|
+
[`createWrapperRule`](../wrapper-rules.md) rather than overloading `additionalCommands`.
|
|
163
168
|
|
|
164
169
|
## Relationship to shellcheck
|
|
165
170
|
|
|
@@ -24,6 +24,11 @@ This rule reads line 1 of the file and reports two problems:
|
|
|
24
24
|
`#!/usr/bin/env -S bash -e`. The rule skips `env` options, their arguments and
|
|
25
25
|
`NAME=value` assignments to find the command `env` runs.
|
|
26
26
|
|
|
27
|
+
The space-separated long form `#!/usr/bin/env --split-string bash -eu` is reported:
|
|
28
|
+
GNU env receives `--split-string bash -eu` as one option name and rejects it. GNU
|
|
29
|
+
`--split-string=bash -eu` is accepted here, but macOS env does not support the long form;
|
|
30
|
+
use `-S` across both systems.
|
|
31
|
+
|
|
27
32
|
A relative interpreter such as `#!bash` or `#!env bash` is reported, because the kernel
|
|
28
33
|
resolves it against the caller's working directory, not `PATH`.
|
|
29
34
|
|
|
@@ -150,8 +155,9 @@ eslint-sh is a convention and contract linter: a policy layer, where shellcheck
|
|
|
150
155
|
layer. Run shellcheck beside it.
|
|
151
156
|
|
|
152
157
|
shellcheck's SC2148 ("Tips depend on target shell and yours is unknown") fires when a file has
|
|
153
|
-
no shebang and
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
no shebang and it cannot otherwise infer the shell. A `.bash`, `.bats` or `.ksh` extension,
|
|
159
|
+
a `# shellcheck shell=bash` directive or a `--shell` flag supplies that information and
|
|
160
|
+
silences SC2148. This rule requires the script itself to name its interpreter, so it still
|
|
161
|
+
reports a missing shebang in those files. It also autofixes the missing line from your configured
|
|
162
|
+
dialect.
|
|
157
163
|
shellcheck's SC1008 ("This shebang was unrecognized") overlaps `unrecognizedInterpreter`.
|
|
@@ -5,7 +5,7 @@ Require a script to turn on its strict-mode shell options (`set -euo pipefail` b
|
|
|
5
5
|
|
|
6
6
|
| Configs | Fixable | Languages |
|
|
7
7
|
| ------- | ------- | --------- |
|
|
8
|
-
| `recommended`, `agent-authored
|
|
8
|
+
| `recommended`, `agent-authored` | autofix | `sh/sh` |
|
|
9
9
|
|
|
10
10
|
## Rule details
|
|
11
11
|
|
|
@@ -70,7 +70,7 @@ again. Decide what that `set +e` is for, then edit the file by hand.
|
|
|
70
70
|
|
|
71
71
|
### Dialects
|
|
72
72
|
|
|
73
|
-
When `
|
|
73
|
+
When `requiredOptions` is not configured, the required prologue depends on `languageOptions.dialect`:
|
|
74
74
|
|
|
75
75
|
| `dialect` | Default prologue |
|
|
76
76
|
| -------------------------------------------- | ------------------- |
|
|
@@ -82,7 +82,7 @@ still reject `set -o pipefail`. An autofix that inserted it would break a workin
|
|
|
82
82
|
on those shells, so under `posix` the default requires and inserts only `set -eu`. A `posix` file
|
|
83
83
|
may still turn `pipefail` on; the rule just doesn't require it.
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
Configured `requiredOptions` always win, whatever the dialect. To require `pipefail` in POSIX scripts too,
|
|
86
86
|
configure it (see below).
|
|
87
87
|
|
|
88
88
|
The dialect comes from `languageOptions`, not from the shebang. A `#!/bin/sh` file linted under the
|
|
@@ -94,20 +94,14 @@ shebang by [`sh/shebang-matches-dialect`](./shebang-matches-dialect.md); set
|
|
|
94
94
|
|
|
95
95
|
This rule takes one options object:
|
|
96
96
|
|
|
97
|
-
- `
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
list. Options with a one-letter flag go into one cluster in list order. The first option with no
|
|
106
|
-
letter is attached to that cluster with `o`, and any others follow as `-o <name>`. So
|
|
107
|
-
`["errexit", "nounset", "pipefail"]` inserts `set -euo pipefail` and `["errexit", "nounset"]`
|
|
108
|
-
inserts `set -eu`.
|
|
109
|
-
|
|
110
|
-
<!-- transform: {"kind": "fix", "options": {"mode": ["errexit", "nounset", "pipefail"]}} -->
|
|
97
|
+
- `requiredOptions` (`string[]`, dialect-aware default above): a nonempty list of unique
|
|
98
|
+
long option names from the supported `set -o` domain (`errexit`, `nounset`, `pipefail`,
|
|
99
|
+
`noclobber`, …). ESLint rejects strings, empty lists, duplicates, unknown names and short
|
|
100
|
+
aliases as configuration errors. The autofix always builds a `set` command from this list:
|
|
101
|
+
options with a one-letter flag go into one cluster in list order, the first long-only option
|
|
102
|
+
follows that cluster with `o`, and any others follow as `-o <name>`.
|
|
103
|
+
|
|
104
|
+
<!-- transform: {"kind": "fix", "options": {"requiredOptions": ["errexit", "nounset", "pipefail"]}} -->
|
|
111
105
|
|
|
112
106
|
```sh
|
|
113
107
|
echo hi
|
|
@@ -116,7 +110,7 @@ This rule takes one options object:
|
|
|
116
110
|
echo hi
|
|
117
111
|
```
|
|
118
112
|
|
|
119
|
-
<!-- transform: {"kind": "fix", "options": {"
|
|
113
|
+
<!-- transform: {"kind": "fix", "options": {"requiredOptions": ["errexit", "nounset"]}} -->
|
|
120
114
|
|
|
121
115
|
```sh
|
|
122
116
|
echo hi
|
|
@@ -124,6 +118,15 @@ This rule takes one options object:
|
|
|
124
118
|
set -eu
|
|
125
119
|
echo hi
|
|
126
120
|
```
|
|
121
|
+
|
|
122
|
+
### Shared prologue definition
|
|
123
|
+
|
|
124
|
+
Both this rule and [`sh/no-unchecked-cd`](./no-unchecked-cd.md) read
|
|
125
|
+
`settings: { sh: { strictModePrologue: { allowShebangOnly: false, withinStatements: 5 } } }`.
|
|
126
|
+
These fields are shared settings, not rule options. Only an absent value uses defaults;
|
|
127
|
+
malformed objects, unknown fields, non-boolean flags and non-positive or non-integer windows
|
|
128
|
+
throw a configuration error naming the shared binding when either rule loads for a file.
|
|
129
|
+
|
|
127
130
|
- `withinStatements` (integer ≥ 1, default `5`): how many top-level statements from the top of the
|
|
128
131
|
file the prologue may take to appear.
|
|
129
132
|
- `allowShebangOnly` (`boolean`, default `false`): when `true`, options passed to the shell on the
|
|
@@ -142,14 +145,19 @@ This rule takes one options object:
|
|
|
142
145
|
`bash script.sh`, so a `set` line is the only prologue that applies however the script is
|
|
143
146
|
started.
|
|
144
147
|
|
|
148
|
+
Relative interpreters such as `#!env -S bash -eu` receive no credit. Neither does
|
|
149
|
+
`#!/usr/bin/env --split-string bash -eu`: GNU env rejects the space-separated long
|
|
150
|
+
option when invoked through a kernel shebang. GNU's equals form
|
|
151
|
+
`#!/usr/bin/env --split-string=bash -eu` receives credit; macOS env does not support that long
|
|
152
|
+
option. Use an absolute env path and `-S` for both systems.
|
|
153
|
+
|
|
145
154
|
```js
|
|
146
155
|
// eslint.config.js
|
|
147
156
|
{
|
|
157
|
+
settings: { sh: { strictModePrologue: { allowShebangOnly: false, withinStatements: 5 } } },
|
|
148
158
|
rules: {
|
|
149
159
|
'sh/require-strict-mode': ['error', {
|
|
150
|
-
|
|
151
|
-
withinStatements: 5,
|
|
152
|
-
allowShebangOnly: false,
|
|
160
|
+
requiredOptions: ['errexit', 'nounset', 'pipefail'],
|
|
153
161
|
}],
|
|
154
162
|
},
|
|
155
163
|
}
|
|
@@ -163,7 +171,7 @@ For POSIX `sh` scripts that only run on shells with `pipefail` support, and shou
|
|
|
163
171
|
files: ['**/*.sh'],
|
|
164
172
|
languageOptions: { dialect: 'posix' },
|
|
165
173
|
rules: {
|
|
166
|
-
'sh/require-strict-mode': ['error', {
|
|
174
|
+
'sh/require-strict-mode': ['error', { requiredOptions: ['errexit', 'nounset', 'pipefail'] }],
|
|
167
175
|
},
|
|
168
176
|
}
|
|
169
177
|
```
|
|
@@ -230,7 +238,7 @@ set -e
|
|
|
230
238
|
<!-- example: {"dialect": "posix"} -->
|
|
231
239
|
```sh
|
|
232
240
|
#!/bin/sh
|
|
233
|
-
# with languageOptions: { dialect: 'posix' } and no configured
|
|
241
|
+
# with languageOptions: { dialect: 'posix' } and no configured requiredOptions
|
|
234
242
|
set -eu
|
|
235
243
|
```
|
|
236
244
|
|
|
@@ -11,7 +11,7 @@ have their input supplied explicitly.
|
|
|
11
11
|
|
|
12
12
|
A prompt that waits on the terminal hangs forever when a script runs without one: in CI, from
|
|
13
13
|
cron, or from an agent's tool call. In automation it also reads whatever happens to be on stdin.
|
|
14
|
-
This rule reports `read` and `select` (and any command you add with `
|
|
14
|
+
This rule reports `read` and `select` (and any command you add with `additionalCommands`) that are not
|
|
15
15
|
guarded.
|
|
16
16
|
|
|
17
17
|
The check is **purely syntactic**. The rule never follows data or control flow, so what it treats
|
|
@@ -55,18 +55,27 @@ The rule is honest about what it cannot see:
|
|
|
55
55
|
|
|
56
56
|
- `commands` (`string[]`, default `['read', 'select']`): the interactive commands to check. A
|
|
57
57
|
configured list **replaces** the default, as with `sh/require-network-wrapper`; include `read`
|
|
58
|
-
and `select` to keep them. `select` is parsed as a loop, not a command, and is checked whenever
|
|
58
|
+
and `select` to keep them. An empty list removes all defaults. `select` is parsed as a loop, not a command, and is checked whenever
|
|
59
59
|
the list contains `select`.
|
|
60
60
|
|
|
61
|
+
- `additionalCommands` (`string[]`, default `[]`): commands added to `commands`, or to
|
|
62
|
+
`read` and `select` when `commands` is omitted. An empty addition changes nothing;
|
|
63
|
+
overlapping names report only once.
|
|
64
|
+
|
|
61
65
|
```js
|
|
62
66
|
// eslint.config.js
|
|
63
67
|
{
|
|
64
68
|
rules: {
|
|
65
|
-
'sh/require-tty-guard': ['error', {
|
|
69
|
+
'sh/require-tty-guard': ['error', { additionalCommands: ['confirm'] }],
|
|
66
70
|
},
|
|
67
71
|
}
|
|
68
72
|
```
|
|
69
73
|
|
|
74
|
+
This configuration checks `read`, `select` and `confirm`.
|
|
75
|
+
`{ commands: ['ask'], additionalCommands: ['confirm'] }` checks `ask` and `confirm`,
|
|
76
|
+
leaving `read` and `select` alone. `{ commands: [], additionalCommands: ['confirm'] }`
|
|
77
|
+
checks only `confirm`.
|
|
78
|
+
|
|
70
79
|
## Suggestion
|
|
71
80
|
|
|
72
81
|
The rule offers one suggestion per report: wrap the statement in `if [ -t 0 ]; then … fi`:
|
package/docs/selectors.md
CHANGED
|
@@ -16,13 +16,18 @@ Looking for a complete, runnable `create()` that uses one of these selectors —
|
|
|
16
16
|
|
|
17
17
|
| Class | Matches |
|
|
18
18
|
| -------------- | ---------------------------------------------------- |
|
|
19
|
-
| `:command` | `CallExpr`
|
|
19
|
+
| `:command` | `CallExpr` with a command word (nonempty `args`) |
|
|
20
20
|
| `:loop` | `ForClause`, `WhileClause` |
|
|
21
21
|
| `:conditional` | `IfClause`, `CaseClause` |
|
|
22
22
|
| `:expansion` | `ParamExp`, `CmdSubst`, `ArithmExp`, `ProcSubst` |
|
|
23
23
|
| `:quoted` | `SglQuoted`, `DblQuoted` |
|
|
24
24
|
| `:function` | `FuncDecl` |
|
|
25
25
|
|
|
26
|
+
`:command` matches exactly the calls with an entry in `sourceCode.getCommandSites()`.
|
|
27
|
+
An assignment-only statement such as `FOO=1` has no command site and does not match.
|
|
28
|
+
`FOO=1 jq .`, `true`, `:`, and dynamic invocations such as `"$tool" file` do match.
|
|
29
|
+
Select `CallExpr` directly when you want every call node, including assignment-only calls.
|
|
30
|
+
|
|
26
31
|
`:loop` deliberately does **not** include `CStyleLoop` — that node is `ForClause.loop`'s nested
|
|
27
32
|
C-style arithmetic header (`init`/`cond`/`post`), not a loop statement in its own right. A
|
|
28
33
|
`for ((i=0;i<3;i++))` loop's outer node is still `ForClause`, so `:loop` already reaches it.
|
|
@@ -54,7 +59,7 @@ behind rules like "forbid calling `curl` directly, use the wrapped helper instea
|
|
|
54
59
|
:function :command
|
|
55
60
|
```
|
|
56
61
|
|
|
57
|
-
A descendant combinator: any
|
|
62
|
+
A descendant combinator: any command site that has a `FuncDecl` ancestor. Useful for rules that only
|
|
58
63
|
apply to commands run from within a shell function (e.g. "functions must not shell out to `sudo`").
|
|
59
64
|
|
|
60
65
|
### Match every command nested inside a conditional
|
package/docs/shellcheck.md
CHANGED
|
@@ -32,8 +32,8 @@ For a complete GitHub Actions job, exit codes, a pre-commit hook and editor setu
|
|
|
32
32
|
[`eslint-sh` README](https://github.com/mike-north/eslint-sh/blob/main/packages/eslint-sh/README.md#continuous-integration).
|
|
33
33
|
|
|
34
34
|
Give them the same target shell, since each reads its own configuration. shellcheck takes it
|
|
35
|
-
from the shebang
|
|
36
|
-
`languageOptions.dialect` and `languageOptions.
|
|
35
|
+
from the shebang, a `# shellcheck shell=…` directive, or a `.bash`, `.bats` or `.ksh` extension;
|
|
36
|
+
eslint-sh takes it from `languageOptions.dialect` and `languageOptions.minBashVersion`. The `bash-3.2` and
|
|
37
37
|
`posix-portable` presets set the latter for you, and
|
|
38
38
|
[`sh/shebang-matches-dialect`](./rules/shebang-matches-dialect.md) reports a
|
|
39
39
|
shebang that disagrees with the configured dialect, so the two tools do not end up advising for
|
|
@@ -68,10 +68,10 @@ reason given, and each rule's page has a "Relationship to shellcheck" section. T
|
|
|
68
68
|
|
|
69
69
|
| eslint-sh rule | Overlapping shellcheck code | Why the rule exists anyway |
|
|
70
70
|
| -------------- | --------------------------- | -------------------------- |
|
|
71
|
-
| [`sh/quote-expansions`](./rules/quote-expansions.md) | SC2086, SC2068 | Makes unquoted expansions a project policy with a severity you choose, and offers a quoting suggestion. It is `warn` in `recommended`;
|
|
71
|
+
| [`sh/quote-expansions`](./rules/quote-expansions.md) | SC2086, SC2068 | Makes unquoted expansions a project policy with a severity you choose, and offers a quoting suggestion. It is `warn` in `recommended`; disabling it when you enforce SC2086 avoids double reports, but also drops checks in command-name position and `for … in` lists, which SC2086 never reports. |
|
|
72
72
|
| [`sh/no-eval`](./rules/no-eval.md) | SC2294 (`eval` on arrays), SC1090 (non-literal `source`) | shellcheck flags `eval` only in specific misuse patterns. The rule treats every `eval` and every non-literal `source` as a reviewable exception. |
|
|
73
|
-
| [`sh/no-unchecked-cd`](./rules/no-unchecked-cd.md) | SC2164 |
|
|
74
|
-
| [`sh/require-shebang`](./rules/require-shebang.md) | SC2148, SC1008 |
|
|
73
|
+
| [`sh/no-unchecked-cd`](./rules/no-unchecked-cd.md) | SC2164 | Offers a suggestion and covers `pushd` and `popd` too. shellcheck suppresses SC2164 for shebang errexit flags; `ignoreWhenErrexit` reads only prologue `set` statements, so the rule still reports those unchecked directory changes. |
|
|
74
|
+
| [`sh/require-shebang`](./rules/require-shebang.md) | SC2148, SC1008 | Requires a recognized shebang even when shellcheck infers the shell from a `.bash`, `.bats` or `.ksh` extension, a directive or a command-line flag and emits no SC2148. |
|
|
75
75
|
| [`sh/no-masked-exit-status`](./rules/no-masked-exit-status.md) | SC2155 | `require-strict-mode` makes `set -euo pipefail` a contract, and `local x=$(cmd)` is the most common way a script that honours it still swallows a failure. shellcheck offers no fix; the rule offers the split as an editor suggestion and can be limited to files where errexit is on. It is not in `recommended`, because that preset runs beside shellcheck. |
|
|
76
76
|
| [`sh/prefer-local`](./rules/prefer-local.md) | SC2155 (a related check) | Requires `local` declarations, and its fix declares the variable on a separate line, which avoids SC2155. |
|
|
77
77
|
| [`sh/compat/no-associative-arrays`](./rules/compat/no-associative-arrays.md), [`no-case-modification`](./rules/compat/no-case-modification.md), [`no-negative-array-index`](./rules/compat/no-negative-array-index.md), [`no-mapfile`](./rules/compat/no-mapfile.md) | SC3044 (the `declare` or `mapfile` command, not the `-A` option), SC3043 (`local -A`), SC3054 (`${a[-1]}`), SC3059 (case modification) | shellcheck reports these only for scripts it treats as POSIX `sh`. These rules report them for a Bash version you name. |
|
|
@@ -85,3 +85,7 @@ reason given, and each rule's page has a "Relationship to shellcheck" section. T
|
|
|
85
85
|
| [`sh/compat/no-lastpipe-semantics`](./rules/compat/no-lastpipe-semantics.md) | SC2030, SC2031 | shellcheck explains the subshell effect of lastpipe; the rule reports `shopt -s lastpipe` on a Bash that lacks it. |
|
|
86
86
|
| [`sh/shebang-matches-dialect`](./rules/shebang-matches-dialect.md) | SC3xxx | shellcheck judges the syntax against the shebang. This rule compares the shebang with your configured dialect, a different question. |
|
|
87
87
|
| [`sh/require-strict-mode`](./rules/require-strict-mode.md) | none directly (SC2164, an unchecked `cd`, is one consequence) | shellcheck has no check that requires strict mode. |
|
|
88
|
+
|
|
89
|
+
`sh/compat/no-nounset-empty-array` requires explicit opt-in for `bash-3.2`. Enable it when a
|
|
90
|
+
script runs with `set -u` on Bash below 4.4 and its arrays can really be empty. Local checks
|
|
91
|
+
cannot prove safety across every caller or helper contract. `posix-portable` still enables it.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Shared transparent wrappers
|
|
2
|
+
|
|
3
|
+
A transparent wrapper runs a command named in its arguments. Declare that project fact
|
|
4
|
+
once so every wrapper-following rule sees the same command chain:
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
{
|
|
8
|
+
settings: {
|
|
9
|
+
sh: {
|
|
10
|
+
transparentWrappers: ['with-retry', { names: ['audit-run'], argFlags: ['--ticket'] }],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Entries are non-empty names or JSON-expressible `WrapperSpec` objects. A name preserves
|
|
17
|
+
the known option shape of a default wrapper such as `timeout`; an unfamiliar name
|
|
18
|
+
takes no flags. A spec can declare `names`, `noArgFlags`, `argFlags`,
|
|
19
|
+
`unresolvableFlags`, `stopsChainFlags`, `positionalOperandsBeforeCommand`,
|
|
20
|
+
`assignmentOperands` (`shell-identifier`, `env`, or `sudo`), and `shellBuiltin`.
|
|
21
|
+
`names` is required and non-empty. Regex fields and functions are not accepted.
|
|
22
|
+
An unknown flag stops analysis rather than guessing which operand is the command.
|
|
23
|
+
|
|
24
|
+
Project specs precede each rule's built-in table, including when a project spec names a
|
|
25
|
+
default wrapper. Replaced names are removed from lower-priority entries while their
|
|
26
|
+
unrelated aliases remain available; a builtin override cannot regain utility path semantics.
|
|
27
|
+
Duplicate project names and malformed entries are configuration errors.
|
|
28
|
+
The shared network policy, for example
|
|
29
|
+
`settings: { sh: { networkWrapper: 'with-retry' } }`, also supplies a transparent-wrapper
|
|
30
|
+
fact. Overlapping names must have the same option shape; extra transparent aliases do
|
|
31
|
+
not become approved network wrappers. Different option shapes for shared names are
|
|
32
|
+
configuration errors. A network rule's `wrapper` option must agree with both the option
|
|
33
|
+
shape and the full approved name set of a configured shared network policy. It cannot
|
|
34
|
+
override that policy silently. Omitted flag lists and empty flag lists are equivalent;
|
|
35
|
+
object key order and flag-list order do not matter.
|
|
36
|
+
|
|
37
|
+
Both comparisons use the published matcher's effective grammar: omitted flag lists
|
|
38
|
+
are empty, `shellBuiltin: false` means utility matching, and
|
|
39
|
+
`positionalOperandsBeforeCommand: 0` consumes no positional operand. Assignment
|
|
40
|
+
handling uses the selected grammar; the internal legacy alias means
|
|
41
|
+
`shell-identifier` only when no explicit grammar was supplied. Expanded built-in
|
|
42
|
+
flag patterns compare by source and flags, including presence versus absence.
|
|
43
|
+
This is structural grammar comparison, not arbitrary regex-language equivalence.
|
|
44
|
+
Explicit specs remain complete replacements: a patternless `nice` spec does not
|
|
45
|
+
inherit the built-in numeric-priority pattern, and conflicts with the string default
|
|
46
|
+
when both are configured for the same name. Internal regex fields remain forbidden
|
|
47
|
+
in settings; the accepted JSON fields above are unchanged.
|
|
48
|
+
|
|
49
|
+
Utility wrappers invoked by absolute or relative path match by basename:
|
|
50
|
+
`/opt/bin/with-retry curl x` and `./bin/with-retry curl x` both run `curl`.
|
|
51
|
+
An explicit path spec takes precedence over a basename fallback in either list order.
|
|
52
|
+
Path aliases are also built for a rule's built-in table when no shared setting is present.
|
|
53
|
+
The written wrapper path remains a dependency in declaration harvesting. Specs with
|
|
54
|
+
`shellBuiltin: true` require exact names: `/tmp/command` cannot acquire the shell
|
|
55
|
+
builtin's semantics. Unused-declaration completeness uses the resolved table too,
|
|
56
|
+
without restoring overridden built-in path semantics. These are syntactic declarations; no wrapper or corpus script is
|
|
57
|
+
executed or inspected to infer its behavior.
|
|
58
|
+
|
|
59
|
+
Every built-in that follows wrappers reads these facts: `no-undeclared-commands`,
|
|
60
|
+
`no-unused-declarations`, `no-dynamic-invocation`, `no-eval`, `no-unchecked-cd`,
|
|
61
|
+
`no-secret-env-reads`, `no-masked-exit-status`, and the command-based compatibility
|
|
62
|
+
rules. `require-network-wrapper` and rules made with `createWrapperRule` do too.
|
|
63
|
+
Rules retain their own built-in scopes and reporting policies. `quote-expansions`
|
|
64
|
+
checks expansion positions directly and does not follow wrappers.
|
|
65
|
+
|
|
66
|
+
Allowed-secret-sink exemptions apply only to argument words after the final resolved
|
|
67
|
+
command. In `with-retry --log "$API_TOKEN" sink`, the secret is owned by the wrapper
|
|
68
|
+
and is checked normally, even if `sink` is approved. In
|
|
69
|
+
`with-retry --log audit.log sink "$API_TOKEN"`, it is an actual sink argument and can
|
|
70
|
+
be exempt. The same boundary applies to default wrappers such as `env -u`.
|
|
71
|
+
|
|
72
|
+
## Migration
|
|
73
|
+
|
|
74
|
+
Remove the `transparentWrappers` option from `no-undeclared-commands` and
|
|
75
|
+
`no-unused-declarations`, and remove `allowWrappers` from `no-dynamic-invocation`.
|
|
76
|
+
Move the list to `settings: { sh: { transparentWrappers: ['with-retry'] } }`.
|
|
77
|
+
Removed rule options fail ESLint schema validation; no per-rule override exists.
|
|
78
|
+
|
|
79
|
+
`allowWrappers` added checks: it made the rule follow the wrapper and report a
|
|
80
|
+
dynamic operand such as `with-retry "$cmd"`. Moving its list preserves that check
|
|
81
|
+
and makes every other wrapper-following rule see it too. To suppress a dynamic
|
|
82
|
+
dispatcher, use `allowInFunctions` or a justified ESLint disable comment.
|
|
83
|
+
|
|
84
|
+
Findings can change on unchanged scripts once project wrappers are configured:
|
|
85
|
+
wrapped `eval`, unchecked `cd`, dynamic invocations, compatibility features, and
|
|
86
|
+
unwrapped network commands become visible. An allowed secret sink behind a project
|
|
87
|
+
wrapper can become recognized, and incomplete usage behind a wrapper can prevent an
|
|
88
|
+
unsafe unused-declaration fix.
|
|
89
|
+
|
|
90
|
+
## Rule packs
|
|
91
|
+
|
|
92
|
+
Call `resolveTransparentWrappers(context, builtIns)` from a rule's `create()` and
|
|
93
|
+
pass its result as the analysis `transparentWrappers` table. Omit `builtIns` to use
|
|
94
|
+
the default table. The resolver composes shared facts with that scope, validates
|
|
95
|
+
configuration, and adds path spellings from the linted file without mutating inputs.
|
|
96
|
+
Both `eslint-sh` and `@eslint-sh/eslint-plugin` export it and
|
|
97
|
+
`TransparentWrappersBindingContext`.
|
package/docs/wrapper-rules.md
CHANGED
|
@@ -9,6 +9,10 @@ Which commands need a wrapper, and which wrapper, is your project's policy. This
|
|
|
9
9
|
wrapper name. You bind both, either in a rule pack with `createWrapperRule` or in your config
|
|
10
10
|
with [`sh/require-network-wrapper`](./rules/require-network-wrapper.md)'s `wrapper` option.
|
|
11
11
|
|
|
12
|
+
Project wrapper facts are shared through
|
|
13
|
+
`settings: { sh: { transparentWrappers: ['with-retry'] } }`. This rule follows
|
|
14
|
+
those wrappers and the shared network wrapper; see [shared transparent wrappers](./transparent-wrappers.md).
|
|
15
|
+
|
|
12
16
|
## `createWrapperRule`
|
|
13
17
|
|
|
14
18
|
```ts
|
|
@@ -204,3 +208,10 @@ command runs after its own options, located the way a wrapped command is located
|
|
|
204
208
|
`noArgFlags` and `argFlags` are skipped, and an option in `stopsChainFlags` means no subcommand
|
|
205
209
|
runs. The message names the command with its subcommand: `` `git fetch` must be run through
|
|
206
210
|
`retry`. ``
|
|
211
|
+
|
|
212
|
+
A `WrapperSpec` may set `shellBuiltin: true` for a wrapper that runs inside the current shell.
|
|
213
|
+
Such entries match exact names: an executable such as `/tmp/command` is not the `command`
|
|
214
|
+
builtin and its argument words remain opaque. Omitted or false retains utility-wrapper path
|
|
215
|
+
matching. The same boolean field is accepted in the network-wrapper option and setting.
|
|
216
|
+
|
|
217
|
+
See [error codes](error-codes.md) for stable configuration and helper failure identities.
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-sh/eslint-plugin",
|
|
3
3
|
"description": "Shell script linting for ESLint, with built-in policy rules, shared presets, and custom rules over a typed shell AST",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"author": "Mike North <michael.l.north@gmail.com>",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@eslint/core": "^1.2.1",
|
|
8
8
|
"@eslint/plugin-kit": "^0.7.2",
|
|
9
|
-
"sh-ast": "^0.
|
|
9
|
+
"sh-ast": "^0.10.0"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"eslint": "^10.7.0"
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"directory": "packages/eslint-plugin"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
|
-
"build": "tsc -p tsconfig.json && node ../../scripts/rollup-declarations.mjs api-extractor.json syntax/api-extractor.json syntax/analyze/api-extractor.json",
|
|
80
|
+
"build": "node ../../scripts/materialize-shared-source.mjs && tsc -p tsconfig.json && node ../../scripts/rollup-declarations.mjs api-extractor.json syntax/api-extractor.json syntax/analyze/api-extractor.json && cp types/eslint-plugin.d.ts dist/eslint-plugin.d.ts",
|
|
81
81
|
"check": "concurrently -n lint,types,api-report \"pnpm run check:lint-ts\" \"pnpm run check:typecheck\" \"pnpm run check:api-report\"",
|
|
82
82
|
"check:api-report": "api-extractor run && api-extractor run --config syntax/api-extractor.json && api-extractor run --config syntax/analyze/api-extractor.json",
|
|
83
83
|
"check:lint-ts": "eslint .",
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The one path by which a rule reads a bound convention's declarations for
|
|
3
|
-
* the file it is linting. The built-in consumers (`sh/no-undeclared-commands`,
|
|
4
|
-
* `sh/no-unused-declarations`) and a pack's own rules all call
|
|
5
|
-
* {@link readDeclaredCommands}, so they hand the convention the same
|
|
6
|
-
* {@link LintedFile} and trust only declarations that passed the same checks.
|
|
7
|
-
*
|
|
8
|
-
* The checks exist because a declaration's kind decides where a report goes
|
|
9
|
-
* and whether a fix is offered. A declaration of an unknown kind, one missing
|
|
10
|
-
* its kind's fields, or a script range outside the text would otherwise be
|
|
11
|
-
* reported at a made-up location, crash deep inside a rule, or be silently
|
|
12
|
-
* accepted by a rule that only reads names. Failing with the declaration and
|
|
13
|
-
* the setting in the message makes the convention's bug the thing the user
|
|
14
|
-
* sees.
|
|
15
|
-
*/
|
|
16
|
-
import type { ShellSourceCode } from '../language/shell-source-code.js';
|
|
17
|
-
import type { DeclarationConvention, DeclaredCommand, LintedFile } from './declaration-convention.js';
|
|
18
|
-
/**
|
|
19
|
-
* What {@link readDeclaredCommands} reads from a rule's context: the linted
|
|
20
|
-
* file and its source code. Any shell rule's `context` satisfies it.
|
|
21
|
-
*
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export interface DeclarationReadContext extends LintedFile {
|
|
25
|
-
/** The source code of the file being linted. */
|
|
26
|
-
readonly sourceCode: ShellSourceCode;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* The only view of the linted file a convention's hooks receive: `filename`,
|
|
30
|
-
* `physicalFilename` and `cwd`, frozen. A rule's `context` must never reach a
|
|
31
|
-
* hook, because it would let a convention report, read options or reach other
|
|
32
|
-
* rule state.
|
|
33
|
-
*
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
export declare function toLintedFile(context: LintedFile): LintedFile;
|
|
37
|
-
/**
|
|
38
|
-
* Returns the declarations `convention` makes for the file `context` is
|
|
39
|
-
* linting, after checking each one against its kind. Call it from a rule's
|
|
40
|
-
* listener with the convention `resolveDeclarationConvention` returned and
|
|
41
|
-
* the rule's own `context`.
|
|
42
|
-
*
|
|
43
|
-
* The convention receives a frozen {@link LintedFile} holding only
|
|
44
|
-
* `filename`, `physicalFilename` and `cwd`, never the whole context, so it
|
|
45
|
-
* sees which file it is reading and nothing it could report through.
|
|
46
|
-
*
|
|
47
|
-
* Throws an `Error` that names the setting, starting
|
|
48
|
-
* `Invalid settings.sh.declarationConvention:`, and shows the offending value when
|
|
49
|
-
* `declaredCommands` does not return an array, or returns a declaration with
|
|
50
|
-
* a missing or unknown `kind`, without its kind's fields, or with a `range`
|
|
51
|
-
* outside the linted text.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* const convention = resolveDeclarationConvention(context);
|
|
56
|
-
* if (convention === null) return {};
|
|
57
|
-
* return {
|
|
58
|
-
* File() {
|
|
59
|
-
* for (const declared of readDeclaredCommands(convention, context)) {
|
|
60
|
-
* if (declared.kind === 'script') {
|
|
61
|
-
* // declared.range is an offset pair into context.sourceCode.text
|
|
62
|
-
* }
|
|
63
|
-
* }
|
|
64
|
-
* },
|
|
65
|
-
* };
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* @public
|
|
69
|
-
*/
|
|
70
|
-
export declare function readDeclaredCommands(convention: DeclarationConvention, context: DeclarationReadContext): DeclaredCommand[];
|