@eslint-sh/eslint-plugin 0.11.0 → 0.13.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.
Files changed (84) hide show
  1. package/README.md +5 -2
  2. package/dist/api.d.ts +1 -1
  3. package/dist/command-harvest/harvest-commands.d.ts +10 -4
  4. package/dist/command-harvest/harvest-commands.js +39 -10
  5. package/dist/eslint-plugin-api.d.ts +36 -14
  6. package/dist/language/command-resolution.d.ts +16 -6
  7. package/dist/language/command-resolution.js +44 -17
  8. package/dist/language/line-breaks.d.ts +10 -4
  9. package/dist/language/line-breaks.js +14 -5
  10. package/dist/language/shell-language.d.ts +2 -0
  11. package/dist/language/shell-language.js +10 -1
  12. package/dist/language/shell-source-code.d.ts +29 -13
  13. package/dist/language/shell-source-code.js +126 -55
  14. package/dist/language/word-resolution.d.ts +18 -12
  15. package/dist/language/word-resolution.js +133 -3
  16. package/dist/rules/compat/bash-builtin-destination.d.ts +2 -0
  17. package/dist/rules/compat/bash-builtin-destination.js +4 -0
  18. package/dist/rules/compat/declaration-options.d.ts +2 -2
  19. package/dist/rules/compat/declaration-options.js +23 -17
  20. package/dist/rules/compat/no-case-attributes.js +2 -4
  21. package/dist/rules/compat/no-mapfile.js +16 -19
  22. package/dist/rules/compat/no-negative-array-index.d.ts +3 -8
  23. package/dist/rules/compat/no-negative-array-index.js +7 -30
  24. package/dist/rules/compat/no-nounset-empty-array.js +10 -7
  25. package/dist/rules/compat/no-parameter-transformation.js +2 -1
  26. package/dist/rules/compat/no-printf-time-format.js +38 -16
  27. package/dist/rules/compat/no-source.d.ts +3 -8
  28. package/dist/rules/compat/no-source.js +3 -40
  29. package/dist/rules/compat/no-test-v.js +243 -61
  30. package/dist/rules/compat/no-wait-n.js +43 -12
  31. package/dist/rules/compat/nounset-array-proof.d.ts +3 -1
  32. package/dist/rules/compat/nounset-array-proof.js +84 -63
  33. package/dist/rules/compat/posix-absent-command.js +3 -2
  34. package/dist/rules/compat/shopt-options.js +3 -2
  35. package/dist/rules/create-wrapper-rule.js +16 -9
  36. package/dist/rules/no-dynamic-invocation.js +8 -9
  37. package/dist/rules/no-eval.js +19 -8
  38. package/dist/rules/no-masked-exit-status.js +34 -46
  39. package/dist/rules/no-secret-flags.js +4 -3
  40. package/dist/rules/no-unchecked-cd.d.ts +8 -3
  41. package/dist/rules/no-unchecked-cd.js +54 -25
  42. package/dist/rules/no-unused-declarations.js +127 -30
  43. package/dist/rules/prefer-local.js +146 -52
  44. package/dist/rules/require-shebang.js +23 -21
  45. package/dist/rules/require-strict-mode.d.ts +2 -2
  46. package/dist/rules/require-strict-mode.js +28 -16
  47. package/dist/rules/require-tty-guard.d.ts +2 -0
  48. package/dist/rules/require-tty-guard.js +205 -50
  49. package/dist/rules/set-options.d.ts +5 -16
  50. package/dist/rules/set-options.js +17 -45
  51. package/dist/rules/shebang-interpreter.d.ts +33 -10
  52. package/dist/rules/shebang-interpreter.js +522 -53
  53. package/dist/rules/shebang-matches-dialect.js +4 -4
  54. package/dist/rules/strict-mode-prologue.d.ts +9 -2
  55. package/dist/rules/strict-mode-prologue.js +45 -8
  56. package/dist/rules/variable-reads.d.ts +12 -0
  57. package/dist/rules/variable-reads.js +31 -0
  58. package/docs/custom-rule-tutorial.md +19 -10
  59. package/docs/error-codes.md +6 -1
  60. package/docs/examples/no-curl-in-functions-rule.mjs +7 -5
  61. package/docs/rules/README.md +5 -5
  62. package/docs/rules/compat/no-mapfile.md +11 -20
  63. package/docs/rules/compat/no-negative-array-index.md +9 -22
  64. package/docs/rules/compat/no-nounset-empty-array.md +5 -5
  65. package/docs/rules/compat/no-printf-time-format.md +2 -1
  66. package/docs/rules/compat/no-source.md +8 -17
  67. package/docs/rules/compat/no-test-v.md +7 -1
  68. package/docs/rules/compat/no-wait-n.md +3 -1
  69. package/docs/rules/no-dynamic-invocation.md +3 -0
  70. package/docs/rules/no-eval.md +22 -1
  71. package/docs/rules/no-masked-exit-status.md +4 -1
  72. package/docs/rules/no-secret-flags.md +22 -2
  73. package/docs/rules/no-unchecked-cd.md +2 -1
  74. package/docs/rules/no-undeclared-commands.md +1 -1
  75. package/docs/rules/no-unused-declarations.md +18 -9
  76. package/docs/rules/prefer-local.md +15 -33
  77. package/docs/rules/require-network-wrapper.md +1 -1
  78. package/docs/rules/require-shebang.md +46 -3
  79. package/docs/rules/require-strict-mode.md +40 -15
  80. package/docs/rules/require-tty-guard.md +27 -4
  81. package/docs/rules/shebang-matches-dialect.md +3 -0
  82. package/docs/shellcheck.md +1 -1
  83. package/docs/wrapper-rules.md +1 -1
  84. package/package.json +4 -4
@@ -5,8 +5,9 @@
5
5
  * ESLINT_SH_STRICT_MODE_SETTING identifies a malformed project prologue fact;
6
6
  * rule-option schema failures remain ESLint responsibilities.
7
7
  */
8
+ import { describeWordAtPosition, isSingleField } from '../language/word-resolution.js';
8
9
  import { configurationMessage } from '../configuration-message.js';
9
- import { applySetOptionChanges, parseSetArguments, shebangOptionChanges } from './set-options.js';
10
+ import { applySetOptionChanges, parseSetArguments, SET_POSITIONAL_OPERAND, shebangOptionChanges, } from './set-options.js';
10
11
  /** The user-written path of the shared project fact, extended with its offending field. */
11
12
  const SETTING = 'settings.sh.strictModePrologue';
12
13
  /**
@@ -52,16 +53,48 @@ export function resolveStrictModePrologue(settings) {
52
53
  *
53
54
  * @internal
54
55
  */
55
- export function setStatementChanges(stmt, sourceCode) {
56
+ export function setStatementArguments(stmt, sourceCode) {
56
57
  if (stmt.background) {
57
- return [];
58
+ return undefined;
58
59
  }
59
60
  const { cmd } = stmt;
60
61
  if (cmd?.type !== 'CallExpr' || sourceCode.getCommandName(cmd) !== 'set') {
61
- return [];
62
+ return undefined;
62
63
  }
63
- const args = cmd.args.slice(1);
64
- return parseSetArguments(args.map((word) => sourceCode.resolveWordText(word))).changes;
64
+ const parsed = parseSetWords(sourceCode, cmd.args.slice(1));
65
+ if (stmt.redirs.length === 0)
66
+ return parsed;
67
+ // The redirection may fail before set runs. A successful disable can
68
+ // invalidate an earlier proof. Even a close may need a spare descriptor
69
+ // to restore the original one after set returns.
70
+ const final = new Map(parsed.changes.map((change) => [change.option, change]));
71
+ return {
72
+ changes: [...final.values()].filter((change) => !change.enable),
73
+ stoppedBy: 'unknown',
74
+ };
75
+ }
76
+ /** Reads shell set options from the proven argument shape. @internal */
77
+ export function parseSetWords(source, words) {
78
+ const args = [];
79
+ for (const word of words) {
80
+ const facts = describeWordAtPosition(source, word);
81
+ if (facts.fields.max === 0)
82
+ continue;
83
+ if (facts.resolution.static && isSingleField(facts)) {
84
+ args.push(facts.resolution.text);
85
+ }
86
+ else {
87
+ const first = facts.knownPrefix.charAt(0);
88
+ args.push(isSingleField(facts) && first !== '' && first !== '-' && first !== '+'
89
+ ? SET_POSITIONAL_OPERAND
90
+ : null);
91
+ }
92
+ }
93
+ return parseSetArguments(args);
94
+ }
95
+ /** The known option changes for a plain `set` statement. @internal */
96
+ export function setStatementChanges(stmt, sourceCode) {
97
+ return setStatementArguments(stmt, sourceCode)?.changes ?? [];
65
98
  }
66
99
  /**
67
100
  * The options enabled after applying `seed`, then each statement's `set`
@@ -84,8 +117,12 @@ export function enabledAfter(seed, statementChanges) {
84
117
  *
85
118
  * @internal
86
119
  */
87
- export function prologueEnabledOptions(file, sourceCode, config) {
120
+ export function prologueOptionState(file, sourceCode, config) {
88
121
  const shebangChanges = config.allowShebangOnly ? shebangOptionChanges(sourceCode.text) : [];
89
122
  const statements = file.stmts.slice(0, config.withinStatements);
90
- return enabledAfter(shebangChanges, statements.map((stmt) => setStatementChanges(stmt, sourceCode)));
123
+ const argumentsByStatement = statements.map((stmt) => setStatementArguments(stmt, sourceCode));
124
+ return {
125
+ enabled: enabledAfter(shebangChanges, argumentsByStatement.map((args) => args?.changes ?? [])),
126
+ hasUnknownOptions: argumentsByStatement.some((args) => args?.stoppedBy === 'unknown'),
127
+ };
91
128
  }
@@ -0,0 +1,12 @@
1
+ import type { ShellNode } from '../language/syntax-view.js';
2
+ import type { ShellSourceCode } from '../language/shell-source-code.js';
3
+ /**
4
+ * Whether `text` mentions `name` as a whole identifier.
5
+ * @internal
6
+ */
7
+ export declare function mentionsIdentifier(text: string, name: string): boolean;
8
+ /**
9
+ * Whether evaluating a single syntax node can read any of the given names.
10
+ * @internal
11
+ */
12
+ export declare function readsNameHere(node: ShellNode, names: readonly string[], sourceCode: ShellSourceCode): boolean;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Whether `text` mentions `name` as a whole identifier.
3
+ * @internal
4
+ */
5
+ export function mentionsIdentifier(text, name) {
6
+ return new RegExp(`(?<![A-Za-z0-9_])${name}(?![A-Za-z0-9_])`, 'u').test(text);
7
+ }
8
+ /**
9
+ * Whether evaluating a single syntax node can read any of the given names.
10
+ * @internal
11
+ */
12
+ export function readsNameHere(node, names, sourceCode) {
13
+ if (node.type === 'ParamExp') {
14
+ if (node.excl)
15
+ return true;
16
+ const param = node.param?.value;
17
+ if (param !== undefined && names.includes(param))
18
+ return true;
19
+ if (node.index !== undefined) {
20
+ const indexText = sourceCode.text.slice(node.index.range[0], node.index.range[1]);
21
+ if (names.some((name) => mentionsIdentifier(indexText, name)))
22
+ return true;
23
+ }
24
+ }
25
+ if (node.type === 'ArithmExp' || node.type === 'ArithmCmd') {
26
+ const arithmetic = sourceCode.text.slice(node.range[0], node.range[1]);
27
+ if (names.some((name) => mentionsIdentifier(arithmetic, name)))
28
+ return true;
29
+ }
30
+ return false;
31
+ }
@@ -230,7 +230,8 @@ entry has:
230
230
  - `node`: the `CallExpr` node, the same object a `CallExpr` listener receives, so you can report
231
231
  on it.
232
232
  - `context`: the frames that lead to the command, outermost first. `date` in
233
- `f() { echo "$(date)"; }` has `[{ kind: 'function', name: 'f' }, { kind: 'cmdSubst' }]`.
233
+ `f() { echo "$(date)"; }` has `[{ kind: 'function', names: ['f'] }, { kind: 'cmdSubst' }]`.
234
+ Function frames list names in declaration order. Anonymous functions have an empty list.
234
235
  - `argv0` and `argv`: the command's words, resolved like `resolveWord` resolves them.
235
236
  - `resolveInvokedCommand()`: the command that actually runs after transparent wrappers such as
236
237
  `sudo` or `env`. Its `chainIndices` say where each word of that chain sits in the site's `argv`,
@@ -268,6 +269,7 @@ const noCurlInFunctions = defineShellRule({
268
269
  schema: [],
269
270
  messages: {
270
271
  curlInFunction: 'Function `{{name}}` runs `curl`; fetch data before calling it.',
272
+ curlInUnnamedFunction: 'This function runs `curl`; fetch data before calling it.',
271
273
  },
272
274
  },
273
275
  create(context) {
@@ -283,11 +285,12 @@ const noCurlInFunctions = defineShellRule({
283
285
  // function that directly contains this command.
284
286
  const fn = site.context.findLast((frame) => frame.kind === 'function');
285
287
  if (fn) {
286
- context.report({
287
- node: site.node,
288
- messageId: 'curlInFunction',
289
- data: { name: fn.name },
290
- });
288
+ const [name] = fn.names;
289
+ if (typeof name === 'string') {
290
+ context.report({ node: site.node, messageId: 'curlInFunction', data: { name } });
291
+ } else {
292
+ context.report({ node: site.node, messageId: 'curlInUnnamedFunction' });
293
+ }
291
294
  }
292
295
  }
293
296
  },
@@ -413,7 +416,7 @@ import { walk, printSync, type Node, type PrintOptions } from 'sh-ast';
413
416
  import { enumerateCommands, resolveArgv0, type CommandInventory } from 'sh-analysis';
414
417
  ```
415
418
 
416
- The supported dependency ranges are `sh-ast@^0.11.0` and `sh-analysis@^0.1.0`.
419
+ The supported dependency ranges are `sh-ast@^0.13.0` and `sh-analysis@^0.4.0`.
417
420
  There are no plugin or umbrella syntax forwarding subpaths. Keep using source helpers when you
418
421
  need ESLint nodes, UTF-16 locations or fixes: they map the original syntax by identity.
419
422
 
@@ -443,9 +446,15 @@ into an ESLint fix:
443
446
  - `getPrintedReplacement(node, edited, options)` prints `edited` with sh-ast's `printSync` and
444
447
  returns `{ range, text }`, ready for `fixer.replaceTextRange(range, text)`. The range is
445
448
  `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`), and output that is not
447
- valid UTF-8 or edited syntax containing literal vertical tabs or form feeds throws a `TypeError`
448
- instead of becoming a fix. A `File`'s `Name` is unprinted metadata and does not trigger that refusal.
449
+ accepts (`File`, `Stmt`, `Word`, `Assign`, a `Command` or a `WordPart`). Output that cannot be
450
+ represented as UTF-8 text throws a `TypeError`. A subtree replacement must contain every
451
+ heredoc affected by the edit. An edited `File` can cover a deferred body after a pipeline, and
452
+ printing is refused even for a `File` if a carriage return may affect the heredoc boundary.
453
+ When the parser supplies no body extent for an empty heredoc, a later carriage return can also
454
+ cause refusal. The guard is conservative about literal carriage returns inside an observed
455
+ heredoc extent. Printing also refuses replacements that change the positions of carriage
456
+ returns in the replaced text, including in quoted words. When printing is refused, use a
457
+ targeted text edit that preserves the affected bytes or report without a fix.
449
458
 
450
459
  `docs/examples/no-backticks-rule.mjs` reports backtick command substitution and fixes it to `$(…)`:
451
460
 
@@ -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
- | `ESLINT_SH_PRINT_UNSAFE_TEXT` | `TypeError` | Edited syntax contains literal vertical tabs or form feeds the printer changes. |
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
@@ -66,6 +67,10 @@ plugin's source helpers also preserve analysis resource/invalid-wrapper failures
66
67
  and printed replacements preserve upstream printer errors. Returning a partial
67
68
  command inventory on a depth refusal would silently omit real commands.
68
69
 
70
+ Match dependency failures by `code`. An analysis helper can throw an error from
71
+ the `sh-ast` version installed under `sh-analysis`, so constructor identity can
72
+ differ from the version imported by a rule or by the plugin.
73
+
69
74
  | Dependency code | Meaning |
70
75
  | --- | --- |
71
76
  | `SH_AST_SYNTAX_PARSE` | Invalid shell source. The language presents fatal diagnostics; raw syntax calls retain the error. |
@@ -23,6 +23,7 @@ const noCurlInFunctions = defineShellRule({
23
23
  schema: [],
24
24
  messages: {
25
25
  curlInFunction: 'Function `{{name}}` runs `curl`; fetch data before calling it.',
26
+ curlInUnnamedFunction: 'This function runs `curl`; fetch data before calling it.',
26
27
  },
27
28
  },
28
29
  create(context) {
@@ -38,11 +39,12 @@ const noCurlInFunctions = defineShellRule({
38
39
  // function that directly contains this command.
39
40
  const fn = site.context.findLast((frame) => frame.kind === 'function');
40
41
  if (fn) {
41
- context.report({
42
- node: site.node,
43
- messageId: 'curlInFunction',
44
- data: { name: fn.name },
45
- });
42
+ const [name] = fn.names;
43
+ if (typeof name === 'string') {
44
+ context.report({ node: site.node, messageId: 'curlInFunction', data: { name } });
45
+ } else {
46
+ context.report({ node: site.node, messageId: 'curlInUnnamedFunction' });
47
+ }
46
48
  }
47
49
  }
48
50
  },
@@ -26,12 +26,12 @@ See the [canonical quickstart](https://github.com/mike-north/eslint-sh/blob/main
26
26
  | [`sh/compat/no-let`](./compat/no-let.md) | `posix-portable` | No | No | Disallow `let` when the target shell is POSIX sh, pointing at arithmetic expansion. |
27
27
  | [`sh/compat/no-mapfile`](./compat/no-mapfile.md) | `bash-3.2`, `posix-portable` | No | Yes | Disallow `mapfile` / `readarray` when the target shell lacks them, suggesting a read loop. |
28
28
  | [`sh/compat/no-nameref`](./compat/no-nameref.md) | `bash-3.2`, `posix-portable` | No | No | Disallow namerefs (`declare -n`, `local -n`) when the target shell lacks them. |
29
- | [`sh/compat/no-negative-array-index`](./compat/no-negative-array-index.md) | `bash-3.2`, `posix-portable` | No | Yes | Disallow negative array subscripts when the target shell lacks them, suggesting a length-based index. |
29
+ | [`sh/compat/no-negative-array-index`](./compat/no-negative-array-index.md) | `bash-3.2`, `posix-portable` | No | No | Disallow negative array subscripts when the target shell lacks them. |
30
30
  | [`sh/compat/no-nounset-empty-array`](./compat/no-nounset-empty-array.md) | None (opt-in) | No | Yes | Disallow whole-array expansions under `set -u` when the target shell aborts on an empty array, suggesting a guarded form. |
31
31
  | [`sh/compat/no-parameter-transformation`](./compat/no-parameter-transformation.md) | `bash-3.2`, `posix-portable` | No | No | Disallow `${v@op}` transformations when the target shell lacks the operator. |
32
32
  | [`sh/compat/no-pipe-all`](./compat/no-pipe-all.md) | `bash-3.2`, `posix-portable` | No | Yes | Disallow the stderr-merging pipe (pipe-ampersand) when the target shell lacks it, suggesting an explicit `2>&1` before the pipe. |
33
33
  | [`sh/compat/no-printf-time-format`](./compat/no-printf-time-format.md) | `bash-3.2`, `posix-portable` | No | No | Disallow `printf`'s `%(fmt)T` date format when the target shell lacks it. |
34
- | [`sh/compat/no-source`](./compat/no-source.md) | `posix-portable` | No | Yes | Disallow `source` when the target shell is POSIX sh, suggesting `.`. |
34
+ | [`sh/compat/no-source`](./compat/no-source.md) | `posix-portable` | No | No | Disallow `source` when the target shell is POSIX sh. |
35
35
  | [`sh/compat/no-test-v`](./compat/no-test-v.md) | `bash-3.2`, `posix-portable` | No | No | Disallow the `-v name` test (`[[ -v x ]]`, `test -v x`) when the target shell lacks it. |
36
36
  | [`sh/compat/no-unicode-escape`](./compat/no-unicode-escape.md) | `bash-3.2`, `posix-portable` | No | No | Disallow `\u` / `\U` escapes in `$'…'` when the target shell does not decode them to UTF-8. |
37
37
  | [`sh/compat/no-wait-n`](./compat/no-wait-n.md) | `bash-3.2`, `posix-portable` | No | No | Disallow `wait -n` when the target shell lacks it. |
@@ -44,17 +44,17 @@ 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` | Yes (declaration inserted at the top of the function body) | No | Require variables assigned in a function to be declared `local`. |
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. |
51
- | [`sh/require-strict-mode`](./require-strict-mode.md) | `recommended`, `agent-authored` | Yes (when insertion satisfies the rule) | No | Require strict-mode options near the start of the script. |
51
+ | [`sh/require-strict-mode`](./require-strict-mode.md) | `recommended`, `agent-authored` | No | Yes | Require strict-mode options near the start of the script. |
52
52
  | [`sh/require-tty-guard`](./require-tty-guard.md) | `agent-authored` | No | Yes | Require `read`, `select` and configured interactive commands to be guarded by a TTY test or supplied input. |
53
53
  | [`sh/shebang-matches-dialect`](./shebang-matches-dialect.md) | `recommended`, `agent-authored`, `posix-portable` | No | No | Require the shebang to name the same kind of shell (bash or POSIX) as `languageOptions.dialect`. |
54
54
 
55
55
  `recommended` enables `no-secret-flags` and `quote-expansions` at `warn` and its other rules at
56
56
  `error`. `agent-authored` enables every rule above except the gated `compat/*` rules, all at `error`. `compat/no-append-all-redirect`, `compat/no-mapfile`,
57
- `compat/no-negative-array-index`, `compat/no-nounset-empty-array`, `compat/no-pipe-all`, `compat/no-source`, `no-masked-exit-status`, `no-unchecked-cd`, `quote-expansions` and `require-tty-guard`
57
+ `compat/no-nounset-empty-array`, `compat/no-pipe-all`, `no-masked-exit-status`, `no-unchecked-cd`, `quote-expansions`, `require-strict-mode` and `require-tty-guard`
58
58
  offer editor suggestions, which you apply one at a time from your editor; the Autofix column
59
59
  describes edits available through `eslint --fix`. `quote-expansions` suggests quoting instead of
60
60
  fixing because only the script's author knows whether the splitting was intended.
@@ -27,33 +27,24 @@ command.
27
27
 
28
28
  ### Suggestion
29
29
 
30
- For `mapfile -t NAME` or `readarray -t NAME`, written directly (no wrapper and no leading
31
- `VAR=value`) in a Bash or Bats file, the rule suggests a `while IFS= read -r` loop that fills
32
- the same array the same way:
30
+ For a direct `mapfile -t [NAME]` or `readarray -t [NAME]` in Bash or Bats, the rule
31
+ can suggest a read loop when a single trailing here-string feeds stdin.
33
32
 
34
33
  <!-- transform: {"kind": "suggestion", "dialect": "bash", "minBashVersion": "3.2"} -->
35
34
 
36
35
  ```sh
37
- mapfile -t lines < in.txt
36
+ mapfile -t lines <<< "$text"
38
37
  # becomes
39
- { lines=(); while IFS= read -r || [ -n "$REPLY" ]; do lines+=("$REPLY"); done; } < in.txt
38
+ { lines=(); while IFS= read -r || [ -n "$REPLY" ]; do lines+=("$REPLY"); done; } <<< "$text"
40
39
  ```
41
40
 
42
- - `|| [ -n "$REPLY" ]` keeps a last line that has no trailing newline, as `mapfile -t` does.
43
- - Reading with no variable name keeps each line unchanged, including leading and trailing
44
- spaces and backslashes. The tradeoff is that `read` stores each line in `REPLY`, which
45
- `mapfile` does not touch. After the loop, `REPLY` is the empty string, whatever it held
46
- before. `REPLY` is `read`'s own default variable, so this overwrites less than a named loop
47
- variable such as `line` would. If your script uses `REPLY` across this command, save it
48
- first or edit the loop.
49
- - The brace group keeps the replacement a single command, so a redirection (`< in.txt`,
50
- `<<< "$text"`, `< <(cmd)`) or a pipeline (`cmd | mapfile -t lines`) still feeds the loop.
51
- - With no `NAME`, `mapfile` fills `MAPFILE`, and so does the loop.
52
-
53
- Other forms are reported without a suggestion, because no loop reproduces them exactly or the
54
- target has no arrays at all: `mapfile` without `-t` (each element keeps its newline), any other
55
- option (`-d`, `-n`, `-O`, `-s`, `-u`, `-C`), an array name that is not static, a leading
56
- assignment, a wrapper, and every file under `dialect: "posix"`.
41
+ The loop intentionally leaves `REPLY` set to the empty string. Use the suggestion
42
+ when that change is acceptable. With no array name, both forms fill `MAPFILE`.
43
+ The destination must be a static array name other than `REPLY`.
44
+
45
+ A here-string supplies shell text. Files, pipes, process substitutions, and
46
+ inherited stdin can contain NUL bytes, which `read` and `mapfile` handle differently.
47
+ Those inputs and leading redirections get a diagnostic without a suggestion.
57
48
 
58
49
  ## Options
59
50
 
@@ -6,35 +6,22 @@ whose target shell lacks them: Bash older than 4.3, including the Bash 3.2 that
6
6
 
7
7
  | Configs | Fixable | Languages |
8
8
  | ------- | ------- | --------- |
9
- | `bash-3.2`, `posix-portable` | suggestions | `sh/sh` |
9
+ | `bash-3.2`, `posix-portable` | not fixable | `sh/sh` |
10
10
 
11
11
  ## Rule details
12
12
 
13
13
  Negative subscripts count back from the end of an indexed array. Bash NEWS for 4.3 introduces assigning, referencing and unsetting elements this way; Bash 4.2 already reads `${arr[-1]}`, but rejects the element length `${#arr[-1]}`, assigning and unsetting with `bad array subscript` (see the [evidence table](../../compat.md#evidence)). The rule uses 4.3, the first release where every use works, so a plain `${arr[-1]}` read at `minBashVersion: "4.2"` is reported although 4.2 accepts it. Bash 3.2 fails with `bad array subscript`.
14
14
 
15
- The rule reports a subscript that is a minus sign followed by a nonzero static integer (decimal, octal, hexadecimal, or Bash `base#digits` for bases 2–64), on an expansion (`${arr[-1]}`, `${#arr[-1]}`) or on an assignment (`arr[-1]=x`). It also reports unsetting an element, `unset arr[-1]` (quoted or not, also after options such as `-v` and after `--`), which Bash NEWS for 4.3 covers; that form has no suggestion. It does not evaluate arithmetic expressions or machine-integer overflow. Invalid integer spellings such as `08`, `2#2`, or a leading-zero base prefix (`02#1`, `08#1`) are not evidence of a negative index. It does not report zero in any base (`-0`, `-00`, `-0x0`, `-2#0`, which Bash 3.2 accepts), `${v: -1}` (a substring offset, not a subscript), a computed `-$n`, or a parenthesized `-(1)`. An associative array's `-1` key is a plain string; the rule cannot tell and reports it, but associative arrays need Bash 4.0 anyway.
15
+ The rule reports a subscript that is a minus sign followed by a nonzero static integer (decimal, octal, hexadecimal, or Bash `base#digits` for bases 2–64), on an expansion (`${arr[-1]}`, `${#arr[-1]}`) or on an assignment (`arr[-1]=x`). It also reports unsetting an element, `unset arr[-1]` (quoted or not, also after options such as `-v` and after `--`), which Bash NEWS for 4.3 covers. It does not evaluate arithmetic expressions or machine-integer overflow. Invalid integer spellings such as `08`, `2#2`, or a leading-zero base prefix (`02#1`, `08#1`) are not evidence of a negative index. It does not report zero in any base (`-0`, `-00`, `-0x0`, `-2#0`, which Bash 3.2 accepts), `${v: -1}` (a substring offset, not a subscript), a computed `-$n`, or a parenthesized `-(1)`. An associative array's `-1` key is a plain string; the rule cannot tell and reports it, but associative arrays need Bash 4.0 anyway.
16
16
 
17
- ### Suggestion
17
+ ### Choosing a portable index
18
18
 
19
- For a bare `${NAME[-N]}` read, the rule suggests counting from the length:
20
-
21
- <!-- transform: {"kind": "suggestion", "dialect": "bash", "minBashVersion": "3.2"} -->
22
-
23
- ```sh
24
- echo "${arr[-1]}"
25
- # becomes
26
- echo "${arr[$((${#arr[@]}-1))]}"
27
- ```
28
-
29
- Negative subscripts count back from the highest assigned index plus one, while `${#arr[@]}` counts set elements, so the two agree only for an array without holes. Other forms are reported without a suggestion.
30
-
31
- This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
32
- described in [version compatibility](../../compat.md):
33
-
34
- - `minBashVersion` unset: no Bash version constraint, so no report under `bash` or `bats`.
35
- - `dialect: "bash"` (the default) or `"bats"`: reports when `minBashVersion` is older than `4.3`.
36
- - `dialect: "posix"`: reports nothing in practice, because POSIX sh has no arrays, because the POSIX parser rejects it with a parse error before any rule runs.
37
- - `dialect: "mksh"` or `"zsh"`: never reports.
19
+ A negative subscript counts back from the highest assigned index plus one.
20
+ For a dense zero-based array, that value equals the array length, so
21
+ `${arr[$((${#arr[@]}-1))]}` is equivalent to `${arr[-1]}`. For a sparse array
22
+ such as `arr=([0]=first [9]=last)`, the length is two and the last assigned
23
+ index is nine. The rule cannot prove density and leaves the choice of a
24
+ replacement index to the author.
38
25
 
39
26
  ## Options
40
27
 
@@ -19,16 +19,16 @@ The rule considers an expansion when both of these hold:
19
19
 
20
20
  The rule suppresses a report only when a narrow local proof establishes safety:
21
21
 
22
- - a preceding static `set +u` or `set +o nounset` leaves nounset off;
23
- - an ordinary assignment such as `a=(x)` or `a=("")` guarantees a member. `FUNCNAME` is excluded because it does not obey ordinary assignment semantics. Every element must be a static word; quoted empty strings count, while computed words and unquoted globs do not;
22
+ - a preceding `set +u` or `set +o nounset` leaves nounset off. A later word with a fixed non-option prefix and one field ends option processing;
23
+ - an ordinary assignment such as `a=(x)` or `a=("")` guarantees a member. `FUNCNAME` is excluded because it does not obey ordinary assignment semantics. At least one element must be guaranteed to yield a field, and the assignment must preserve interpreter state. Quoted empty strings and locale-dependent ANSI-C quotes count; an unmatched glob with `nullglob` can supply zero fields;
24
24
  - `[ "${#a[@]}" -eq 0 ] && return` exits the current function on the empty path, or the same zero-length check uses `exit`. `test` and `[[ ... ]]` spellings are also recognized. With `[` or `test`, the length operand must be an ordinary double-quoted word: unquoted counts can split under a changed `IFS`, making the test fail without proving the array non-empty. An optional literal numeric return/exit status is allowed;
25
25
  - the expansion is in the then arm of a single positive length test: `[ "${#a[@]}" -gt 0 ]`, `[[ ${#a[@]} -ne 0 ]]`, or `(( ${#a[@]} ))`, for example.
26
26
 
27
- Facts stay in one sequential statement list. A simple assignment invalidates the fact for its target, so `a=(x); a=()` still reports. Static `set` commands apply option changes in order, so re-enabling nounset removes the off proof. Other calls, including function calls, `unset`, and `shopt`, and compound statements discard facts. Assignments and option changes in a function, loop, branch, or subshell do not establish facts in the surrounding list. A loop's word list can use facts from immediately before the loop; its body starts afresh. Redirections, background statements, prefix assignments on the expanding command, arithmetic expansions, indirect expansions, localized strings, or other potentially mutating argument expansions prevent a proof.
27
+ Facts stay in one sequential statement list. A simple assignment invalidates the fact for its target, so `a=(x); a=()` still reports. Static `set` commands apply option changes in order, so re-enabling nounset removes the off proof. An inert `test` or `[` with proven single-field operands preserves facts. Other calls, including function calls, `unset`, and `shopt`, and compound statements discard facts. Assignments and option changes in a function, loop, branch, or subshell do not establish facts in the surrounding list. A loop's word list can use facts from immediately before the loop; its body starts afresh. Redirections, background statements, prefix assignments on the expanding command, arithmetic expansions, indirect expansions, localized strings, or other potentially mutating argument expansions prevent a proof.
28
28
 
29
29
  A top-level `return` is not an exit proof: when the script is executed rather than sourced, Bash rejects it and continues to the expansion. For example, `set -u; a=(); [ "${#a[@]}" -eq 0 ] && return; echo "${a[@]}"` still reports. Put that guard inside a function or use `exit` when the intended behavior is to exit the script.
30
30
 
31
- The rule does not interpret function bodies at call sites, follow sourced files, or prove data returned by other commands. Dynamic command names, actual calls to `eval`, `source`, `.`, `trap`, `alias`, `unalias`, `enable`, `fc`, `read`, `mapfile`, `readarray`, `getopts`, `unset`, or `let`, indirect expansions (including key/name forms), localized strings, writes or `for`/`select` bindings to special `BASH_*` variables, the executable `PS4` trace prefix, or writable intrinsic integers (`OPTIND`, `RANDOM`, `SECONDS`), definitions overriding proof builtins, function names outside plain shell identifiers, and unrecognized wrapper flags disable local proofs for the file, including when reached through `builtin` or `command` wrappers. Wrapped declaration commands, and declarations using readonly, integer, associative-array or reference attributes or unmodeled arguments, disable local proofs for the file. A reference or integer variable can write interpreter arrays indirectly, so a later `set +u` is not trusted either. Ordinary `local a` and `local -a a` declarations do not block a subsequent literal assignment proof. Unmodeled arithmetic (including numeric `[[ ... ]]` operands, array indices, slices and `let`), `[[ -v ... ]]`, and coprocesses also disable local proofs because they can evaluate variable text or change special arrays. Direct array lengths and literal nonnegative integers remain supported in arithmetic tests. A `printf` call is considered inert only with a static format made of literal text, `%%`, and the simple string conversions `%s`, `%b`, `%q`, or `%c`; `-v` requires a plain ordinary variable name. Other formats, interpreter-backed or unknown destinations and `%n` can write interpreter state, so they disable local proofs, including through wrappers. Command-based `[` and `test` forms require fixed non-name-lookup operators and operands known to be one word (static or a single double-quoted scalar word). `-v`/`-R`, unknown operators, multiword expansions and unmodeled compound tests disable local proofs: their argument parsing can reach arithmetic variable-name evaluation. These restrictions avoid trusting an assignment that can fail, write through a reference, or run under changed interpreter behavior. Ordinary builtin behavior and ordinary variables are assumed when the file contains no evidence to the contrary; this is not a model of arbitrary startup or sourced-caller state.
31
+ The rule does not interpret function bodies at call sites, follow sourced files, or prove data returned by other commands. Dynamic command names, actual calls to `eval`, `source`, `.`, `trap`, `alias`, `unalias`, `enable`, `fc`, `read`, `mapfile`, `readarray`, `getopts`, `unset`, or `let`, indirect expansions (including key/name forms), localized strings, writes or `for`/`select` bindings to special `BASH_*` variables, the executable `PS4` trace prefix, or writable intrinsic integers (`OPTIND`, `RANDOM`, `SECONDS`), definitions overriding proof builtins, function names outside plain shell identifiers, and unrecognized wrapper flags disable local proofs for the file, including when reached through `builtin` or `command` wrappers. Wrapped declaration commands, and declarations using readonly, integer, associative-array or reference attributes or unmodeled arguments, disable local proofs for the file. A reference or integer variable can write interpreter arrays indirectly, so a later `set +u` is not trusted either. Ordinary `local a` and `local -a a` declarations do not block a subsequent literal assignment proof. Unmodeled arithmetic (including numeric `[[ ... ]]` operands, array indices, slices and `let`), `[[ -v ... ]]`, and coprocesses also disable local proofs because they can evaluate variable text or change special arrays. Direct array lengths and literal nonnegative integers remain supported in arithmetic tests. A `printf` call is considered inert only with a static format made of literal text, `%%`, and the simple string conversions `%s`, `%b`, `%q`, or `%c`; `-v` requires a plain ordinary variable name. Other formats, interpreter-backed or unknown destinations and `%n` can write interpreter state, so they disable local proofs, including through wrappers. Command-based `[` and `test` forms require fixed non-name-lookup operators and operands guaranteed to produce one field. `-v`/`-R`, unknown operators, multiword expansions and unmodeled compound tests disable local proofs: their argument parsing can reach arithmetic variable-name evaluation. These restrictions avoid trusting an assignment that can fail, write through a reference, or run under changed interpreter behavior. Ordinary builtin behavior and ordinary variables are assumed when the file contains no evidence to the contrary; this is not a model of arbitrary startup or sourced-caller state.
32
32
 
33
33
  Consequently, guarded code can still report where the proof would require another execution path, an intervening call, a caller contract, or one of the excluded constructs. The message says the expansion is not proven safe and remains conditional on the array actually being empty and nounset being on.
34
34
 
@@ -39,7 +39,7 @@ The rule offers a guarded spelling as a suggestion when the word is exactly the
39
39
  - `"${a[@]}"` becomes `${a[@]+"${a[@]}"}`, which gives no words for an empty array and the same words otherwise;
40
40
  - `"${a[*]}"` becomes `"${a[*]-}"`, which gives the one empty word that `"${a[*]}"` gives for an empty array on Bash 4.4, and the same joined word otherwise.
41
41
 
42
- An unquoted expansion, or one inside a longer word, reports with no suggestion. POSIX sh has no arrays; under `dialect: "posix"` the parser rejects array syntax, so this rule never sees one there.
42
+ An unquoted expansion, one inside a longer word, or an expansion whose local proof is blocked solely by locale or tilde uncertainty reports with no suggestion. POSIX sh has no arrays; under `dialect: "posix"` the parser rejects array syntax, so this rule never sees one there.
43
43
 
44
44
  This is a version-compat rule. Whether it reports depends only on `languageOptions`, as
45
45
  described in [version compatibility](../../compat.md):
@@ -11,7 +11,8 @@ Disallow `printf`'s `%(fmt)T` date format in scripts that must support a shell l
11
11
 
12
12
  The `%(fmt)T` directive arrived in Bash 4.2 (Bash NEWS for 4.2). Bash 4.1 rejects it with ``printf: `(': invalid format character``, so the timestamp is never printed.
13
13
 
14
- The rule reads `printf` commands (also through `builtin` or `command`). The format is the first argument after an optional `-v name` and `--`; when it is a static word, the rule scans it as `printf` does: `%%` is a literal percent sign, and a directive may carry flags, a width and a precision before the `(`. A format with a `%(…)T` directive reports, on the format word. A format that is not static (`printf "$fmt"`) cannot be read, and the same text as another argument or in another command (`echo '%(%Y)T'`) is not a format, so neither reports.
14
+ The rule reads `printf` commands, including through `builtin` or `command`. The format is the first argument after an optional `-v name` or `-vname` and an optional `--`. Bash rejects a literal invalid destination such as `-v1` before evaluating the format.
15
+ The rule reads the exact text or the known literal edges of a proven single format field. For locale- or tilde-dependent formats it can recognize a time directive in a literal suffix such as `$'\u00e9''%(%F)T'`. Its format scan handles `%%`, flags, width, and precision within the known text. An unresolved prefix may affect how `printf` reads the first directive in a suffix. A fully computed format such as `printf "$fmt"` provides no literal directive to check.
15
16
 
16
17
  The portable alternative for the current time is `date '+fmt'`, which takes the same `strftime` format. `printf '%(fmt)T' N` formats an arbitrary epoch time `N`, which has no portable `date` spelling (GNU `date -d @N` and BSD `date -r N` differ), so convert those by hand.
17
18
 
@@ -4,7 +4,7 @@ Disallow the `source` builtin in scripts that target POSIX sh, where the portabl
4
4
 
5
5
  | Configs | Fixable | Languages |
6
6
  | ------- | ------- | --------- |
7
- | `posix-portable` | suggestions | `sh/sh` |
7
+ | `posix-portable` | not fixable | `sh/sh` |
8
8
 
9
9
  ## Rule details
10
10
 
@@ -23,23 +23,14 @@ A function named `source` anywhere in the file exempts a call that names it dire
23
23
 
24
24
  A call through a wrapper gets no exemption and is reported. `command source ./lib.sh` skips the function and fails with status 127, as does `env source ./lib.sh`, and dash has no `builtin` at all.
25
25
 
26
- The portable alternative is the `.` special built-in. The rule offers it as a suggestion only where the two read the same file with the same effect, which needs all of these:
26
+ The portable alternative is to use the POSIX `.` special built-in with a path containing `/`.
27
+ In dash, this changes a failed command lookup into execution of a readable shell file in the
28
+ current shell. The rule reports without an edit because it cannot establish that the file is
29
+ readable at runtime. Before replacing `source ./lib.sh` with `. ./lib.sh`, check that the file is
30
+ readable, the path expands to one field, and the script does not rely on extra positional arguments
31
+ or on the scope of a leading assignment.
27
32
 
28
- - The command is written directly, with no wrapper.
29
- - It has no leading assignment. `FOO=1 . ./lib.sh` leaves `FOO` set afterwards on a POSIX shell, while Bash outside POSIX mode scopes `FOO=1 source ./lib.sh` to that command.
30
- - It has exactly one operand. dash ignores further operands of `.`, where `source` would set the positional parameters.
31
- - The operand has a literal `/`, outside any expansion. With no slash, `.` searches `PATH` and does not look in the current directory.
32
-
33
- <!-- transform: {"kind": "suggestion", "dialect": "posix"} -->
34
- ```sh
35
- source ./lib.sh
36
- # becomes
37
- . ./lib.sh
38
- ```
39
-
40
- Other forms get the report without a suggestion.
41
-
42
- Those conditions do not cover a file that cannot be read, where the rewrite behaves differently. POSIX says a non-interactive shell aborts when [`.`](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#dot) finds no readable file. `. ./missing || echo fallback` ends the script with status 2 on dash and BusyBox ash and status 1 under `bash --posix`, and the fallback never runs. Bash outside POSIX mode returns status 1 from `source` and runs the fallback, and on dash `source ./missing || echo fallback` also runs it, because `source` is not found. To keep a fallback, test first:
33
+ POSIX says a non-interactive shell aborts when [`.`](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#dot) finds no readable file. `. ./missing || echo fallback` ends the script with status 2 on dash and BusyBox ash and status 1 under `bash --posix`, and the fallback never runs. Bash outside POSIX mode returns status 1 from `source` and runs the fallback, and on dash `source ./missing || echo fallback` also runs it, because `source` is not found. To keep a fallback, test first:
43
34
 
44
35
  ```sh
45
36
  if [ -r ./lib.sh ]; then . ./lib.sh; else echo fallback; fi
@@ -17,7 +17,13 @@ The rule reports the `-v` test in two places:
17
17
  - inside `[[ … ]]`, where the parser gives the test its own node;
18
18
  - in a `test` or `[` command (also through `builtin` or `command`), where `-v` is an ordinary argument. The rule reads the arguments the way Bash's `test` does: with two arguments a leading `-v` is the operator; with three, the middle one is a binary operator if it can be one, and `! -v name` negates the test; with four, a leading `!` or surrounding parentheses peel off; anything longer goes through `test`'s own precedence rules, where `-v` is the operator only where a primary is expected and another argument follows it.
19
19
 
20
- So `-v` as an operand does not report: `[ "$a" = -v ]`, `[ -n -v ]`, a lone `[ -v ]`, and `[[ $a == -v ]]` are clean, and so is `-v` of another command (`grep -v`) and any `-v` in quotes. A double-quoted expansion (`"$name"`) always makes exactly one argument, so it counts as an operand; an unquoted one may split into several arguments or none, so reading stops there. The report is on the `[[` test or on the `-v` word.
20
+ A `-v` used as an operand stays clean, as in `[ "$a" = -v ]`, `[ -n -v ]`, or `[[ $a == -v ]]`. A single field can still spell an operator. The rule reports a literal `-v` when its operator role is established across the possible argument spellings. Known text such as the prefix in `PATH=a:~/bin` can rule out operators. The report points to the `[[` test or the `-v` word.
21
+
22
+ In a straight-line prologue, a plain `set --` establishes that a separate `"$@"` argument
23
+ contributes zero fields. The proof ends at a statement that can evaluate code, including an
24
+ array subscript, a command substitution, a `printf -v` destination, or an opaque command.
25
+ In longer tests, the rule stops at an earlier operand that could make Bash reject the test.
26
+ Unresolved fields after a proven unary expression leave that operator's role unchanged.
21
27
 
22
28
  The portable alternative is `[ -n "${name+set}" ]`. `${name+set}` expands to `set` when the variable is set, even to the empty string, and to nothing when it is unset, and it is safe under `set -u`. Under `dialect: "posix"` the parser does not read `[[` as a test, so only `test` and `[` report there; `[[` itself in a POSIX script is outside this rule.
23
29
 
@@ -11,7 +11,9 @@ Bash 3.2 that macOS ships as `/bin/bash`, and POSIX sh.
11
11
 
12
12
  `wait -n`, which waits for the next job to finish, arrived in Bash 4.3 (Bash NEWS for 4.3). Bash 4.2 and older reject the option with `wait: -n: invalid option` and return 2 at once. A job pool that throttles itself with `wait -n` therefore stops waiting, and every job runs at the same time, with no error that stops the script.
13
13
 
14
- The rule reads `wait` commands (also through `builtin` or `command`). It reports an option word, up to the first operand or `--`, that is a cluster containing `n` (`-n`, `-fn`); the report is on that word. The value after `-p` (Bash 5.1's `wait -p var`) is that option's operand, not an option. `-n` of another command (`echo -n`) and an `-n` after an operand are not read.
14
+ The rule reads `wait` commands (also through `builtin` or `command`). It reports an option word, up to the first operand or `--`, that is a cluster containing `n` (`-n`, `-fn`); the report is on that word. The rule checks the option cluster and any literal destination for validity before reporting
15
+ `-n`. For example, Bash rejects `wait -n!` and `wait -p1 -n`. Bash 5.1 introduced `-p` with a destination variable. Both `-p var` and `-pvar` consume that name as data. When a later expansion can supply more than
16
+ one field, the rule keeps a finding on an already recognized `-n`. `-n` of another command (`echo -n`) and an `-n` after an operand are not read.
15
17
 
16
18
  A script that defines its own `wait` function still reports: the rule reads the name `wait` and does not follow shell function definitions.
17
19
 
@@ -77,6 +77,9 @@ See [migration](../transparent-wrappers.md#migration).
77
77
  }
78
78
  ```
79
79
 
80
+ Zsh's multi-name function declarations match any configured name after quote removal.
81
+ For example, `function one tw\o { "$@"; }` matches `allowInFunctions: ['two']`.
82
+
80
83
  ## Examples
81
84
 
82
85
  ### Incorrect
@@ -45,7 +45,7 @@ The rule deliberately ignores:
45
45
  - a command word that is itself dynamic (`"$cmd" args`), and command strings passed to another
46
46
  shell (`bash -c "$x"`, `sh -c …`).
47
47
 
48
- It does not depend on `languageOptions`.
48
+ The rule uses the selected shell dialect when analyzing command words.
49
49
 
50
50
  ## Options
51
51
 
@@ -60,6 +60,27 @@ This rule has no options.
60
60
  }
61
61
  ```
62
62
 
63
+ ## Analysis limits
64
+
65
+ In mksh mode, the analyzer conservatively treats command arguments with unquoted
66
+ `=` as potentially subject to tilde expansion. Dash and default Zsh pass
67
+ `PATH=a:~/bin` literally in this position. The Zsh result assumes
68
+ `MAGIC_EQUAL_SUBST` is off.
69
+
70
+ With `dialect: 'zsh'`, this command can report `dynamicSource` even though Zsh uses the literal filename `file(.)`.
71
+
72
+ ```zsh
73
+ unsetopt GLOB; . ./file(.)
74
+ ```
75
+
76
+ The plugin has no per-command shell option state for this rule. The analyzer treats the parentheses as possible glob syntax even after Zsh disables filename generation.
77
+
78
+ In Bash, the following script can report `dynamicSource`. When Bash starts in `C.UTF-8`, it reads `./é/lib.sh`. Bash parses the line before executing the assignment, so the escape can produce different bytes when the shell starts in `C`. The analyzer treats the path as locale-dependent.
79
+
80
+ ```bash
81
+ LC_ALL=C.UTF-8; . ./$'\u00e9'/lib.sh
82
+ ```
83
+
63
84
  ## Examples
64
85
 
65
86
  ### Incorrect
@@ -89,7 +89,8 @@ The suggestion is withheld where the split would not mean the same thing, and th
89
89
  would read the new, empty local after the split. `export PATH="$(…):$PATH"` is safe to split,
90
90
  because `export` creates no new scope. For every builtin it also includes the other operands of
91
91
  the same declaration. Any mention of such a name in the value counts, because a command can read a
92
- variable by name: `local x=$([ -v x ] && echo set)`, `local x=$(declare -p x)` and
92
+ variable by name. An unresolved operand can name it too, as in `local x=$(test -v "$key" && echo set)`.
93
+ `local x=$([ -v x ] && echo set)`, `local x=$(declare -p x)` and
93
94
  `export A=1 B=$(printenv A)` are withheld. So can an unrelated word, as in
94
95
  `local name=$(git config user.name)`. Under `-i` the builtin evaluates each value as arithmetic,
95
96
  so this reaches the values without a substitution too: `local -i a=$(cmd) b=a+1` is withheld. So
@@ -127,6 +128,8 @@ The suggestion is withheld where the split would not mean the same thing, and th
127
128
  - The builtin is reached through `builtin` or `command`.
128
129
  - An operand is an append (`x+=$(cmd)`) or has a subscript (`a[1]=$(cmd)`), or `readonly` has flags.
129
130
 
131
+ **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.
132
+
130
133
  Under `dialect: "posix"` the parser has no declaration clause and reads `local x=$(cmd)` as an
131
134
  ordinary command; the rule reads it the same way and offers the same suggestion. Otherwise the rule
132
135
  does not depend on `languageOptions`.
@@ -25,8 +25,7 @@ recognizes two forms:
25
25
 
26
26
  A value is literal only when its whole word is static. Any parameter expansion, command
27
27
  substitution, or other dynamic part makes the value fine: `--token="$TOKEN"` and
28
- `--password=$(cat f)` are the correct pattern. Static-ness is decided by the plugin's shared word
29
- resolution (`ShellSourceCode#resolveWordText`), so quoting that resolves to fixed text
28
+ `--password=$(cat f)` are the correct pattern. The plugin resolves each word in its AST position, so quoting that resolves to fixed text
30
29
  (`"--password"='hunter2'`) is still literal.
31
30
 
32
31
  Only command arguments are matched. Assignment values (`X="--token=abc"`, `export`, `local`),
@@ -56,6 +55,27 @@ with the `additionalPatterns` option.
56
55
  Expect some false positives: a name such as `--token-type` still matches. Suppress a single false
57
56
  positive with a disable comment that says why, or narrow the `patterns` option for your project.
58
57
 
58
+ ## Analysis limits
59
+
60
+ With `dialect: 'zsh'`, this command can miss `secretFlag` even though Zsh passes the literal value `secret(.)`.
61
+
62
+ ```zsh
63
+ unsetopt GLOB; printf '%s\n' --token secret(.)
64
+ ```
65
+
66
+ The plugin has no per-command shell option state for this rule. The analyzer treats the parentheses as possible glob syntax even after Zsh disables filename generation.
67
+
68
+ In mksh mode, the analyzer conservatively treats command arguments with unquoted
69
+ `=` as potentially subject to tilde expansion. Dash and default Zsh pass
70
+ `PATH=a:~/bin` literally in this position. The Zsh result assumes
71
+ `MAGIC_EQUAL_SUBST` is off.
72
+
73
+ In Bash, the following script can miss `secretFlag`. When Bash starts in `C.UTF-8`, it passes the literal UTF-8 value `é`. Bash parses the line before executing the assignment, so the escape can produce different bytes when the shell starts in `C`. The analyzer treats the value as locale-dependent.
74
+
75
+ ```bash
76
+ LC_ALL=C.UTF-8; printf '%s\n' --token $'\u00e9'
77
+ ```
78
+
59
79
  ## Options
60
80
 
61
81
  - `patterns` (`string[]`). Regular-expression sources tested against each flag's