@eslint-sh/eslint-plugin 0.10.1 → 0.12.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/dist/command-harvest/harvest-commands.d.ts +6 -2
- package/dist/command-harvest/harvest-commands.js +13 -6
- package/dist/eslint-plugin-api.d.ts +11 -3
- package/dist/language/line-breaks.d.ts +10 -4
- package/dist/language/line-breaks.js +14 -5
- package/dist/language/shell-language.d.ts +2 -0
- package/dist/language/shell-language.js +10 -1
- package/dist/language/shell-source-code.d.ts +11 -3
- package/dist/language/shell-source-code.js +102 -30
- package/dist/rules/no-masked-exit-status.js +5 -29
- package/dist/rules/no-unused-declarations.js +81 -16
- package/dist/rules/prefer-local.js +10 -36
- package/dist/rules/require-shebang.js +23 -21
- package/dist/rules/require-strict-mode.js +11 -8
- package/dist/rules/require-tty-guard.js +8 -5
- package/dist/rules/set-options.d.ts +2 -15
- package/dist/rules/set-options.js +12 -44
- package/dist/rules/shebang-interpreter.d.ts +33 -10
- package/dist/rules/shebang-interpreter.js +522 -53
- package/dist/rules/shebang-matches-dialect.js +4 -4
- package/dist/rules/variable-reads.d.ts +12 -0
- package/dist/rules/variable-reads.js +31 -0
- package/docs/custom-rule-tutorial.md +9 -3
- package/docs/error-codes.md +2 -1
- package/docs/rules/README.md +1 -1
- package/docs/rules/no-masked-exit-status.md +2 -0
- package/docs/rules/no-unused-declarations.md +9 -4
- package/docs/rules/prefer-local.md +11 -33
- package/docs/rules/require-shebang.md +46 -3
- package/docs/rules/require-strict-mode.md +23 -6
- package/docs/rules/require-tty-guard.md +1 -0
- package/docs/rules/shebang-matches-dialect.md +3 -0
- package/docs/shellcheck.md +1 -1
- package/package.json +3 -3
|
@@ -443,9 +443,15 @@ into an ESLint fix:
|
|
|
443
443
|
- `getPrintedReplacement(node, edited, options)` prints `edited` with sh-ast's `printSync` and
|
|
444
444
|
returns `{ range, text }`, ready for `fixer.replaceTextRange(range, text)`. The range is
|
|
445
445
|
`node.range`, or the whole file when `edited` is a `File`. `edited` must be a root `printSync`
|
|
446
|
-
accepts (`File`, `Stmt`, `Word`, `Assign`, a `Command` or a `WordPart`)
|
|
447
|
-
|
|
448
|
-
|
|
446
|
+
accepts (`File`, `Stmt`, `Word`, `Assign`, a `Command` or a `WordPart`). Output that cannot be
|
|
447
|
+
represented as UTF-8 text throws a `TypeError`. A subtree replacement must contain every
|
|
448
|
+
heredoc affected by the edit. An edited `File` can cover a deferred body after a pipeline, and
|
|
449
|
+
printing is refused even for a `File` if a carriage return may affect the heredoc boundary.
|
|
450
|
+
When the parser supplies no body extent for an empty heredoc, a later carriage return can also
|
|
451
|
+
cause refusal. The guard is conservative about literal carriage returns inside an observed
|
|
452
|
+
heredoc extent. Printing also refuses replacements that change the positions of carriage
|
|
453
|
+
returns in the replaced text, including in quoted words. When printing is refused, use a
|
|
454
|
+
targeted text edit that preserves the affected bytes or report without a fix.
|
|
449
455
|
|
|
450
456
|
`docs/examples/no-backticks-rule.mjs` reports backtick command substitution and fixes it to `$(…)`:
|
|
451
457
|
|
package/docs/error-codes.md
CHANGED
|
@@ -52,7 +52,8 @@ try {
|
|
|
52
52
|
| `ESLINT_SH_SYNTAX_VIEW` | `TypeError` | Upstream records and their position snapshot cannot produce a faithful lint view. This is a projection invariant failure, not a syntax diagnostic. |
|
|
53
53
|
| `ESLINT_SH_PRINT_ROOT` | `TypeError` | Edited syntax is missing a record type or uses an unsupported printable root. |
|
|
54
54
|
| `ESLINT_SH_PRINT_ENCODING` | `TypeError` | Printed bytes cannot become a UTF-8 text fix without loss. |
|
|
55
|
-
| `
|
|
55
|
+
| `ESLINT_SH_PRINT_HEREDOC_RANGE` | `TypeError` | The subtree replacement range cannot cover a complete original or edited heredoc. |
|
|
56
|
+
| `ESLINT_SH_PRINT_HEREDOC_TEXT` | `TypeError` | The replacement could lose a carriage return in a heredoc. Applies to whole-file and subtree printing. |
|
|
56
57
|
| `ESLINT_SH_PACKAGE_METADATA` | `Error` | The plugin package lacks a string version. Filesystem/JSON errors keep their native identity. |
|
|
57
58
|
|
|
58
59
|
Formatting/editor failures are documented by the independently maintained
|
package/docs/rules/README.md
CHANGED
|
@@ -44,7 +44,7 @@ See the [canonical quickstart](https://github.com/mike-north/eslint-sh/blob/main
|
|
|
44
44
|
| [`sh/no-unchecked-cd`](./no-unchecked-cd.md) | `recommended`, `agent-authored` | No | Yes | Require the failure of `cd`, `pushd` and `popd` to be checked. |
|
|
45
45
|
| [`sh/no-undeclared-commands`](./no-undeclared-commands.md) | `agent-authored` | No | No | Require external command usage to be declared through your convention. |
|
|
46
46
|
| [`sh/no-unused-declarations`](./no-unused-declarations.md) | `agent-authored` | Yes (when the convention provides an edit hook) | No | Remove command declarations that a fully understood script does not use. |
|
|
47
|
-
| [`sh/prefer-local`](./prefer-local.md) | `agent-authored` |
|
|
47
|
+
| [`sh/prefer-local`](./prefer-local.md) | `agent-authored` | No | No | Require variables assigned in a function to be declared `local`. |
|
|
48
48
|
| [`sh/quote-expansions`](./quote-expansions.md) | `recommended`, `agent-authored` | No | Yes | Require double quotes around expansions in words the shell splits and globs. |
|
|
49
49
|
| [`sh/require-network-wrapper`](./require-network-wrapper.md) | `agent-authored` | No | No | Require network commands to run through your configured wrapper. |
|
|
50
50
|
| [`sh/require-shebang`](./require-shebang.md) | `recommended`, `agent-authored` | Yes (missing shebang only) | No | Require a recognized shell interpreter on line 1. |
|
|
@@ -127,6 +127,8 @@ The suggestion is withheld where the split would not mean the same thing, and th
|
|
|
127
127
|
- The builtin is reached through `builtin` or `command`.
|
|
128
128
|
- An operand is an append (`x+=$(cmd)`) or has a subscript (`a[1]=$(cmd)`), or `readonly` has flags.
|
|
129
129
|
|
|
130
|
+
**Limit:** Splitting a declaration such as `export` or `readonly` can move a trailing carriage return from the value to the name used by the builtin.
|
|
131
|
+
|
|
130
132
|
Under `dialect: "posix"` the parser has no declaration clause and reads `local x=$(cmd)` as an
|
|
131
133
|
ordinary command; the rule reads it the same way and offers the same suggestion. Otherwise the rule
|
|
132
134
|
does not depend on `languageOptions`.
|
|
@@ -52,8 +52,7 @@ replace them with literal commands:
|
|
|
52
52
|
|
|
53
53
|
**Used.** Otherwise, a declared name is used when any of the following holds:
|
|
54
54
|
|
|
55
|
-
- **The script runs it as a command.**
|
|
56
|
-
`sh/no-undeclared-commands` does, so a command that rule counts as used is never reported
|
|
55
|
+
- **The script runs it as a command.** A command that `sh/no-undeclared-commands` counts as used is never reported
|
|
57
56
|
here. That covers commands anywhere in the file: the top level, loops, conditionals,
|
|
58
57
|
pipelines, and command substitutions (`$(…)` and backquotes) in any position. It also covers
|
|
59
58
|
function bodies, including a function that is never called. That is deliberately cautious: the
|
|
@@ -71,8 +70,14 @@ replace them with literal commands:
|
|
|
71
70
|
|
|
72
71
|
Not counted:
|
|
73
72
|
|
|
74
|
-
- **Builtins and
|
|
75
|
-
|
|
73
|
+
- **Builtins and calls to earlier top-level functions.** The rule excludes builtins and direct
|
|
74
|
+
top-level calls after an unconditional definition of the same name when it sees no command
|
|
75
|
+
that can remove functions. It preserves possibly external dependencies when it sees `unset`
|
|
76
|
+
that may remove functions, or Zsh’s `unfunction` or `disable -f` with operands, even inside
|
|
77
|
+
another function. Bash `unset -v` only targets variables, including with an expanded operand.
|
|
78
|
+
Calls before definitions, after conditional
|
|
79
|
+
definitions, or inside compound commands or functions can also refer to an external program.
|
|
80
|
+
`# uses: cd` is stale even in a
|
|
76
81
|
script that runs `cd`. Which names are builtins depends on `languageOptions.dialect`; see
|
|
77
82
|
[`sh/no-undeclared-commands`](./no-undeclared-commands.md#rule-details) for the lists.
|
|
78
83
|
- **Commands run on another host are not counted.** In `ssh host 'jq . f'`, the remote host
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Require variables assigned inside a function to be declared `local`, so a function does not
|
|
4
4
|
overwrite globals its callers rely on.
|
|
5
5
|
|
|
6
|
-
| Configs
|
|
7
|
-
|
|
|
8
|
-
| `agent-authored` |
|
|
6
|
+
| Configs | Fixable | Languages |
|
|
7
|
+
| --------------- | ----------- | --------- |
|
|
8
|
+
| `agent-authored` | not fixable | `sh/sh` |
|
|
9
9
|
|
|
10
10
|
## Rule details
|
|
11
11
|
|
|
@@ -36,6 +36,7 @@ What the rule does not report:
|
|
|
36
36
|
allowed.
|
|
37
37
|
- Anything in a subshell `( … )`, a command substitution `$( … )` or a process substitution, and
|
|
38
38
|
functions whose body is a subshell (`f() ( … )`): those run in a child process, so nothing leaks.
|
|
39
|
+
- Assignments in a background job, a coprocess, or a disowned job are isolated from the enclosing function.
|
|
39
40
|
- Anything in a pipeline element, such as `echo hi | read x` or `ls | while read -r line; do …; done`.
|
|
40
41
|
Pipeline elements run in subshells, so the assignment is lost rather than leaked. The exception is
|
|
41
42
|
a file that enables `shopt -s lastpipe` (anywhere in the file): the **last** element of each
|
|
@@ -49,37 +50,14 @@ rest.
|
|
|
49
50
|
`local` is not part of POSIX, so under `languageOptions: { dialect: 'posix' }` the rule reports
|
|
50
51
|
nothing.
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
Choose the variable’s scope when addressing the diagnostic. A `local` declaration changes the
|
|
54
|
+
value that an expansion or a called function can see, and it prevents the caller from observing
|
|
55
|
+
assignments after the function returns. ESLint leaves the source unchanged.
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
# after
|
|
62
|
-
f() {
|
|
63
|
-
local out
|
|
64
|
-
out=$(compute)
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
The fix does not rewrite `out=$(compute)` into `local out=$(compute)` on purpose. `local` is a
|
|
69
|
-
command, so its exit status is its own, not that of `compute`: `local out=$(false)` succeeds, and
|
|
70
|
-
`set -e` or `|| handle_error` never sees the failure (shellcheck SC2155). A separate declaration
|
|
71
|
-
keeps the assignment's exit status intact.
|
|
72
|
-
|
|
73
|
-
The fix declares a variable that was global. If the function _reads_ the global before assigning it
|
|
74
|
-
(`count=$((count + 1))`), declaring it `local` makes that read see an empty value instead, so
|
|
75
|
-
review the function before accepting the fix. Every report in a function carries the same fix, a
|
|
76
|
-
single `local` declaring all of the function's reported names, so `eslint --fix` settles the
|
|
77
|
-
function in one pass however many names it leaks (`a` then `b` becomes `local a b`). Fixes that
|
|
78
|
-
insert at the same point conflict, and ESLint applies one per pass and stops after 10, which is why
|
|
79
|
-
one fix per name would leave a function with more than 10 names unfixed. The declaration therefore
|
|
80
|
-
also covers a name whose report a user suppressed with a directive, so review the function if you
|
|
81
|
-
suppress a name in it. Each report, message and suggestion is still per name. A function whose body
|
|
82
|
-
is not a `{ … }` block (`f() if …; fi`) is reported without a fix.
|
|
57
|
+
If you choose local scope for a command substitution, a separate declaration preserves the
|
|
58
|
+
assignment’s exit status. For example, use `local out` followed by `out=$(compute)`. With
|
|
59
|
+
`local out=$(compute)`, the status belongs to `local`, which can hide a failure from `set -e`
|
|
60
|
+
or `|| handle_error` (ShellCheck SC2155).
|
|
83
61
|
|
|
84
62
|
## Options
|
|
85
63
|
|
|
@@ -21,8 +21,31 @@ This rule reads line 1 of the file and reports two problems:
|
|
|
21
21
|
accepted two ways:
|
|
22
22
|
- by absolute path: `#!/bin/bash`, `#!/usr/local/bin/bash`, with any arguments after it;
|
|
23
23
|
- through `env` named by absolute path: `#!/usr/bin/env bash`,
|
|
24
|
-
`#!/usr/bin/env -S bash -e`.
|
|
25
|
-
|
|
24
|
+
`#!/usr/bin/env -S bash -e`. Use `-S` to pass options, `NAME=value` assignments,
|
|
25
|
+
or shell arguments. Without it, `env` receives one command operand. A path such as
|
|
26
|
+
`/opt/shell tools/bash` names Bash, while `bash -e` is a literal command name. In a Linux
|
|
27
|
+
shebang, the argument delivered to `env` ends at LF or NUL. Blanks immediately before NUL
|
|
28
|
+
remain part of the argument.
|
|
29
|
+
Split-string forms support static quoting, escapes and comments, including `-vS` and
|
|
30
|
+
nested splitting with `-S` or `--split-string`. GNU env restarts option processing after
|
|
31
|
+
each split, keeping the effects of earlier options.
|
|
32
|
+
GNU `env` options such as `--argv0=shell` and `--default-signal=PIPE` can precede the shell
|
|
33
|
+
name. Unambiguous long-option abbreviations such as `--split-s=bash -e` are accepted.
|
|
34
|
+
An ambiguous abbreviation such as `--ignore` leaves the interpreter unrecognized.
|
|
35
|
+
Signal lists use Linux signal names, numbers, or GNU shell-status operands. An
|
|
36
|
+
explicit disposition for `SIGKILL` or `SIGSTOP` is rejected unless a later bare disposition
|
|
37
|
+
option replaces it. GNU env applies assignments containing a literal `=`, including
|
|
38
|
+
`=yes` and `MODE${SUFFIX}=yes`. After option processing ends, a name made only of
|
|
39
|
+
expansions, as in `-- ${NAME}=yes`, is also recognized as an assignment. While options
|
|
40
|
+
are still being read, an expanded name at the start of a word can introduce another
|
|
41
|
+
option, so the interpreter stays unrecognized. An expansion can fill an attached value,
|
|
42
|
+
as in `--argv0=shell${SUFFIX}`. An expanded `--unset` value can contain an equals sign
|
|
43
|
+
even inside quotes, so it leaves the interpreter unrecognized unless env clears the
|
|
44
|
+
environment and skips unsetting.
|
|
45
|
+
An unquoted expansion of a set variable, even an empty one, makes an adjacent `#` literal.
|
|
46
|
+
An unset variable can instead make it start a comment that ends only the current split
|
|
47
|
+
string. The rule checks both readings and recognizes the interpreter when they have usable
|
|
48
|
+
options and agree on the executable operand.
|
|
26
49
|
|
|
27
50
|
The space-separated long form `#!/usr/bin/env --split-string bash -eu` is reported:
|
|
28
51
|
GNU env receives `--split-string bash -eu` as one option name and rejects it. GNU
|
|
@@ -51,7 +74,8 @@ For `missingShebang`, the fix inserts one line above line 1. The interpreter com
|
|
|
51
74
|
| `zsh` | `#!/usr/bin/env zsh` | `#!/bin/zsh` |
|
|
52
75
|
| `bats` | `#!/usr/bin/env bats` | `#!/bin/bats` |
|
|
53
76
|
|
|
54
|
-
The inserted line
|
|
77
|
+
The inserted line starts at byte zero and ends with LF, including in a CRLF file. The fix removes
|
|
78
|
+
a leading UTF-8 byte order mark and preserves the original body and its line endings. For an empty
|
|
55
79
|
file the fix produces exactly the shebang line and a newline.
|
|
56
80
|
|
|
57
81
|
`unrecognizedInterpreter` has no fix. The file names some other interpreter, and choosing a
|
|
@@ -149,6 +173,25 @@ export default [
|
|
|
149
173
|
|
|
150
174
|
The rule does not detect sourced libraries on its own.
|
|
151
175
|
|
|
176
|
+
## Limitations
|
|
177
|
+
|
|
178
|
+
- The rules model GNU coreutils 9.7 `env` on Linux. Other implementations such as uutils differ on
|
|
179
|
+
numeric signals and option abbreviations. Re-splitting requires statically known input.
|
|
180
|
+
- The GNU env reader shares a work budget across all readings. It allows 64 work units per UTF-16
|
|
181
|
+
code unit in env's original shebang argument, with a minimum of 1,048,576 units to cover
|
|
182
|
+
nested splits within Linux's 256-byte shebang buffer. A much longer header with deeply nested
|
|
183
|
+
splits can exhaust the budget. Exhaustion leaves the interpreter unrecognized and withholds
|
|
184
|
+
shebang startup-option credit.
|
|
185
|
+
- The Linux kernel's shebang byte limit falls outside the model. Recognition uses physical
|
|
186
|
+
LF or NUL, including when the argument contains a Unicode line separator.
|
|
187
|
+
- A bare CRLF shebang such as `#!/bin/dash` or `#!/usr/bin/env dash` reports
|
|
188
|
+
`unrecognizedInterpreter`. Linux looks up `/bin/dash\r` directly in the first case and
|
|
189
|
+
passes `dash\r` to GNU `env` in the second. The diagnostic escapes whitespace that Linux
|
|
190
|
+
retains at the end of the header, such as `\r`, `\v`, `\f`, or `\u00a0`. A CR in the direct
|
|
191
|
+
interpreter path before an argument also remains part of the path.
|
|
192
|
+
- Recognition identifies the executable operand. Executable lookup, working-directory
|
|
193
|
+
availability, and what the interpreter does with its arguments depend on the runtime.
|
|
194
|
+
|
|
152
195
|
## Relationship to shellcheck
|
|
153
196
|
|
|
154
197
|
eslint-sh is a convention and contract linter: a policy layer, where shellcheck is the gotcha
|
|
@@ -63,7 +63,8 @@ set -euo pipefail
|
|
|
63
63
|
cd "$1"
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
The prologue uses the body’s line ending. With CRLF, the fix adds a trailing `#` so the shell
|
|
67
|
+
reads the carriage return as comment text. The fix is
|
|
67
68
|
offered only when inserting the prologue would satisfy the rule. For example, `set -e` followed by
|
|
68
69
|
`set +e` in the window is reported with no fix, because the `set +e` would turn `errexit` off
|
|
69
70
|
again. Decide what that `set +e` is for, then edit the file by hand.
|
|
@@ -134,10 +135,12 @@ throw a configuration error naming the shared binding when either rule loads for
|
|
|
134
135
|
with `set` statements in the window. Only spellings the operating system passes to the shell as
|
|
135
136
|
written are read:
|
|
136
137
|
- `#!/usr/bin/env -S bash -euo pipefail`: `env -S` splits the rest of the line into words, so
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
the rule reads the resulting shell arguments. This also handles GNU env options before the
|
|
139
|
+
shell, unambiguous long-option abbreviations, and nested splits of static arguments.
|
|
140
|
+
An unquoted carriage return in a split string separates arguments like a space.
|
|
141
|
+
- `#!/bin/bash -eu`: the kernel passes everything after the interpreter as **one** argument.
|
|
142
|
+
In `#!/bin/bash -e -u`, the single argument contains a space, so the rule withholds startup
|
|
143
|
+
credit.
|
|
141
144
|
- `#!/usr/bin/env bash -e` counts as nothing. Without `-S`, Linux passes `bash -e` to `env` as
|
|
142
145
|
one command name.
|
|
143
146
|
|
|
@@ -149,7 +152,21 @@ Relative interpreters such as `#!env -S bash -eu` receive no credit. Neither doe
|
|
|
149
152
|
`#!/usr/bin/env --split-string bash -eu`: GNU env rejects the space-separated long
|
|
150
153
|
option when invoked through a kernel shebang. GNU's equals form
|
|
151
154
|
`#!/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.
|
|
155
|
+
option. Use an absolute env path and `-S` for both systems. A carriage return retained in a
|
|
156
|
+
direct shell flag or inside a quoted split-string flag is passed as part of the argument.
|
|
157
|
+
The shared option parser reads the resolved arguments for every interpreter. A single argument
|
|
158
|
+
that contains whitespace would have split into separate tokens under the original shebang
|
|
159
|
+
reader, so the rule withholds startup credit for that argv. Otherwise, an uncertain or
|
|
160
|
+
unrecognized argument preserves the changes already read. GNU env
|
|
161
|
+
`-C` and `--chdir` can redirect a relative script path. GNU env `-a` and `--argv0` can
|
|
162
|
+
change startup identity. If any reading uses one of these options, the rule withholds
|
|
163
|
+
startup-option credit.
|
|
164
|
+
|
|
165
|
+
**Known limitations.** The shared parser can credit `dash -euB` even though dash rejects `-B`,
|
|
166
|
+
and it can credit options when Bash `-t` or BusyBox `sh -o nolog` prevents the body from running.
|
|
167
|
+
Valid startup switches outside the shared option syntax can end option reading before later
|
|
168
|
+
flags. For example, Bash `-O extglob -eu` receives no credit for `-eu`. The shared fixer spells
|
|
169
|
+
`notify` as `-b`, which Zsh rejects in a `set` statement.
|
|
153
170
|
|
|
154
171
|
```js
|
|
155
172
|
// eslint.config.js
|
|
@@ -50,6 +50,7 @@ The rule is honest about what it cannot see:
|
|
|
50
50
|
- **Variables are not tracked.** `is_tty=$([ -t 0 ] && echo 1)` is not a guard.
|
|
51
51
|
- **Command names are read as written.** A command reached through a wrapper (`command read x`)
|
|
52
52
|
or with a dynamic name is not matched.
|
|
53
|
+
- A CR on a delimiter-like heredoc line can make the guard suggestion end inside the body.
|
|
53
54
|
|
|
54
55
|
## Options
|
|
55
56
|
|
|
@@ -25,6 +25,9 @@ interpreter path (`#!/bin/sh`, `#!/usr/local/bin/bash`), or an absolute-path `en
|
|
|
25
25
|
it runs (`#!/usr/bin/env sh`, `#!/usr/bin/env -S bash -e`). A relative interpreter such as
|
|
26
26
|
`#!sh` is not read; `sh/require-shebang` reports it.
|
|
27
27
|
|
|
28
|
+
On Linux, a terminal carriage return on a bare interpreter name stays part of the name.
|
|
29
|
+
`sh/require-shebang` reports that unrecognized interpreter.
|
|
30
|
+
|
|
28
31
|
Nothing else is reported. A file with no shebang is clean here (that is `sh/require-shebang`'s
|
|
29
32
|
concern), as is a shebang that names another interpreter, and any file whose dialect is `mksh`,
|
|
30
33
|
`zsh` or `bats`. A shebang and dialect that already agree are clean: `#!/usr/bin/env bash` under
|
package/docs/shellcheck.md
CHANGED
|
@@ -73,7 +73,7 @@ reason given, and each rule's page has a "Relationship to shellcheck" section. T
|
|
|
73
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
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
|
-
| [`sh/prefer-local`](./rules/prefer-local.md) | SC2155 (a related check) | Requires `local` declarations
|
|
76
|
+
| [`sh/prefer-local`](./rules/prefer-local.md) | SC2155 (a related check) | Requires `local` declarations. Declare a variable on a separate line from a command substitution to avoid 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. |
|
|
78
78
|
| [`sh/compat/no-double-bracket`](./rules/compat/no-double-bracket.md), [`no-let`](./rules/compat/no-let.md), [`no-source`](./rules/compat/no-source.md) | SC3010 (`[[`), SC3039 (`let`), SC3046 (`source`), under `-s sh` only | Under `-s bash` shellcheck reports nothing for `[[` or `source`, and for `let` only SC2219, a style note that prefers `(( ))`. These rules report them for the dialect you configure, because they fail on dash and would otherwise defeat a preset named for portability. |
|
|
79
79
|
| [`sh/compat/no-test-v`](./rules/compat/no-test-v.md), [`no-wait-n`](./rules/compat/no-wait-n.md), [`no-globstar`](./rules/compat/no-globstar.md), [`no-pipe-all`](./rules/compat/no-pipe-all.md), [`no-fd-variable`](./rules/compat/no-fd-variable.md), [`no-unicode-escape`](./rules/compat/no-unicode-escape.md) | SC3016 (`test -v`, with SC3010 for `[[`), SC3045 (`wait -n`), SC3044 (`shopt`), SC3029 (`\|&`), SC3022 (`{fd}`), SC3003 (`$'…'`) | shellcheck reports these Bash features only for scripts it treats as POSIX `sh`. These rules report them for a Bash version you name. |
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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.12.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.
|
|
10
|
-
"sh-analysis": "^0.
|
|
9
|
+
"sh-ast": "^0.12.0",
|
|
10
|
+
"sh-analysis": "^0.2.0"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"eslint": "^10.14.0"
|