@eslint-sh/eslint-plugin 0.12.0 → 0.14.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 (83) hide show
  1. package/README.md +32 -12
  2. package/dist/api.d.ts +11 -1
  3. package/dist/api.js +8 -0
  4. package/dist/command-harvest/harvest-commands.d.ts +5 -3
  5. package/dist/command-harvest/harvest-commands.js +34 -12
  6. package/dist/eslint-plugin-api.d.ts +65 -12
  7. package/dist/language/command-resolution.d.ts +24 -6
  8. package/dist/language/command-resolution.js +44 -17
  9. package/dist/language/shell-language.js +2 -0
  10. package/dist/language/shell-source-code.d.ts +29 -11
  11. package/dist/language/shell-source-code.js +35 -26
  12. package/dist/language/word-resolution.d.ts +18 -12
  13. package/dist/language/word-resolution.js +133 -3
  14. package/dist/processors/disable-justification.d.ts +20 -0
  15. package/dist/processors/disable-justification.js +124 -0
  16. package/dist/rules/compat/bash-builtin-destination.d.ts +19 -0
  17. package/dist/rules/compat/bash-builtin-destination.js +83 -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 +52 -20
  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 +55 -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 +257 -71
  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 +29 -17
  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 +65 -25
  42. package/dist/rules/no-unused-declarations.js +51 -19
  43. package/dist/rules/prefer-local.js +136 -16
  44. package/dist/rules/require-strict-mode.d.ts +2 -2
  45. package/dist/rules/require-strict-mode.js +27 -18
  46. package/dist/rules/require-tty-guard.d.ts +2 -0
  47. package/dist/rules/require-tty-guard.js +211 -45
  48. package/dist/rules/set-options.d.ts +3 -1
  49. package/dist/rules/set-options.js +5 -1
  50. package/dist/rules/strict-mode-prologue.d.ts +9 -2
  51. package/dist/rules/strict-mode-prologue.js +45 -8
  52. package/docs/custom-rule-tutorial.md +148 -155
  53. package/docs/disable-justification.md +71 -0
  54. package/docs/error-codes.md +4 -0
  55. package/docs/examples/eslint.config.js +11 -0
  56. package/docs/examples/no-curl-in-functions-rule.mjs +20 -23
  57. package/docs/examples/no-listed-commands-rule.ts +19 -19
  58. package/docs/examples/no-rm-rf-rule.mjs +33 -62
  59. package/docs/examples/no-sample-command-rule.mjs +33 -0
  60. package/docs/reading-nodes.md +26 -1
  61. package/docs/rules/README.md +4 -4
  62. package/docs/rules/compat/no-mapfile.md +14 -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 +8 -2
  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 +2 -1
  72. package/docs/rules/no-secret-flags.md +22 -2
  73. package/docs/rules/no-unchecked-cd.md +3 -1
  74. package/docs/rules/no-undeclared-commands.md +1 -1
  75. package/docs/rules/no-unused-declarations.md +10 -6
  76. package/docs/rules/prefer-local.md +4 -0
  77. package/docs/rules/require-network-wrapper.md +1 -1
  78. package/docs/rules/require-strict-mode.md +19 -11
  79. package/docs/rules/require-tty-guard.md +26 -4
  80. package/docs/rules-about-commands.md +78 -0
  81. package/docs/selectors.md +8 -4
  82. package/docs/wrapper-rules.md +1 -1
  83. package/package.json +4 -4
@@ -1,33 +1,33 @@
1
- /**
2
- * The TypeScript custom rule from the custom-rule tutorial
3
- * (`../custom-rule-tutorial.md`, step 10). This package's test suite
4
- * asserts the tutorial's code fence matches this file byte-for-byte,
5
- * type-checks it against the package's published declarations, and runs it
6
- * through a real `eslint` `Linter`.
7
- *
8
- * It reports any command named in its `commands` option, including through a
9
- * wrapper such as `sudo`. Every type comes from `@eslint-sh/eslint-plugin`:
10
- * the options and message ids passed to `defineShellRule` flow into
11
- * `context.options` and `context.report`, and `ShellRuleContext` types the
12
- * helper that reports outside `create()`.
13
- *
14
- * @see ../custom-rule-tutorial.md — the tutorial this rule backs
15
- */
16
1
  import { defineShellRule } from '@eslint-sh/eslint-plugin';
17
2
  import type { ShellCommandSite, ShellRuleContext } from '@eslint-sh/eslint-plugin';
18
3
 
19
4
  /** The rule's one options object; `commands` defaults to `[]`. */
20
5
  type Options = [{ commands?: string[] }?];
21
6
 
22
- /** Reports the program named by `site`, after wrappers, including interpreters running strings. */
7
+ /** Reports the effective command when its basename or full static path is listed. */
23
8
  function reportIfListed(
24
9
  context: ShellRuleContext<Options, 'listed'>,
25
10
  site: ShellCommandSite,
26
11
  listed: ReadonlySet<string>,
27
12
  ): void {
28
- const { effective } = site.resolveInvokedCommand({ embeddedCommandInterpreters: [] });
29
- if (effective.static && listed.has(effective.text)) {
30
- context.report({ node: site.node, messageId: 'listed', data: { name: effective.text } });
13
+ // The policy also matches the interpreter itself when it runs a command string.
14
+ const { effective, chainIndices } = site.resolveInvokedCommand({
15
+ embeddedCommandInterpreters: [],
16
+ });
17
+ const index = chainIndices.at(-1);
18
+ if (index === undefined || (!effective.static && chainIndices.length > 1)) return;
19
+
20
+ const facts = site.argvFacts.at(index);
21
+ if (facts?.resolution !== effective) return;
22
+
23
+ const text = effective.static ? effective.text : undefined;
24
+ const basename = facts.basename.known
25
+ ? facts.basename.text
26
+ : text?.slice(text.lastIndexOf('/') + 1);
27
+ const name = [text, basename].find((entry) => entry !== undefined && listed.has(entry));
28
+ const command = site.node.args.at(index);
29
+ if (name !== undefined && command) {
30
+ context.report({ node: command, messageId: 'listed', data: { name } });
31
31
  }
32
32
  }
33
33
 
@@ -1,40 +1,3 @@
1
- /**
2
- * The complete "flag `rm -rf`" custom rule from the custom-rule tutorial
3
- * (`../custom-rule-tutorial.md`). Plain, directly-runnable JavaScript (no
4
- * compile step) — this file *is* the tutorial's rule-module code fence,
5
- * copy-paste-verbatim; this package's test suite imports this
6
- * exact file (not a reconstruction) and asserts the markdown fence matches
7
- * it byte-for-byte, so the two can't silently drift.
8
- *
9
- * Built with `defineShellRule`, which declares `meta.languages: ['sh/sh']`
10
- * for it, so ESLint refuses to run the rule on a file of any other language.
11
- *
12
- * Built on the `:command` launch class from the selector cookbook
13
- * (`../selectors.md`) — `:command` matches calls with a command word, so `create()`
14
- * narrows further by inspecting the command word and its flag arguments,
15
- * exactly the pattern the cookbook's intro describes ("writing a rule as a
16
- * selector string rather than a `create()` full of manual type checks" —
17
- * here the selector does the node-type narrowing, `create()` only does the
18
- * domain-specific check).
19
- *
20
- * Flag words are resolved with `context.sourceCode.resolveWord`
21
- * (backed by `sh-analysis`) rather than a
22
- * hand-rolled scan: a word is only treated as a short-option cluster
23
- * when it is *statically* that string (bare or
24
- * quoted literal concatenations). Recursive (`r`/`R`) and force (`f`)
25
- * flags accumulate across words before `--`; uppercase `F` is not force.
26
- * Options are matched anywhere before `--`, GNU-style, even after operands.
27
- * This teaching example does not model long options or option precedence.
28
- * A word containing a `ParamExp`/`CmdSubst`/`ArithmExp`/
29
- * `ProcSubst` resolves to `{ static: false, reason }` (`'expansion'`,
30
- * `'tilde'`, `'glob'`, …) rather than being silently erased into a static
31
- * match — see `ShellSourceCode.resolveWord`'s API docs. The source instance
32
- * comes from ESLint, so the rule needs no separate `sh-ast` install or
33
- * dependency-hoisting reliance.
34
- *
35
- * @see ../custom-rule-tutorial.md — the tutorial this rule backs
36
- * @see ../selectors.md — the `:command` launch class
37
- */
38
1
  import { defineShellRule } from '@eslint-sh/eslint-plugin';
39
2
 
40
3
  const noRmRf = defineShellRule({
@@ -50,35 +13,43 @@ const noRmRf = defineShellRule({
50
13
  },
51
14
  create(context) {
52
15
  return {
53
- ':command'(node) {
54
- const args = node.args ?? [];
55
- const words = args.map((arg) => {
56
- const resolved = context.sourceCode.resolveWord(arg);
57
- return resolved.static ? resolved.text : null;
58
- });
16
+ File() {
17
+ for (const site of context.sourceCode.getCommandInventory().commands) {
18
+ const { effective, chainIndices } = site.resolveInvokedCommand();
19
+ const index = chainIndices.at(-1);
20
+ if (index === undefined || (!effective.static && chainIndices.length > 1)) continue;
59
21
 
60
- if (words[0] !== 'rm') {
61
- return;
62
- }
22
+ const facts = site.argvFacts.at(index);
23
+ if (facts?.resolution !== effective) continue;
24
+
25
+ const text = effective.static ? effective.text : undefined;
26
+ const name = facts.basename.known
27
+ ? facts.basename.text
28
+ : text?.slice(text.lastIndexOf('/') + 1);
29
+ const command = site.node.args.at(index);
30
+ if (name !== 'rm' || !command) continue;
31
+
32
+ const words = site.argv.slice(index + 1).map((word) => (word.static ? word.text : null));
63
33
 
64
- // `rm -- -rf` and `rm build -- -rf` are not `rm -rf` — everything
65
- // after a `--` end-of-options marker is an operand (a filename),
66
- // never a flag (POSIX Utility Syntax Guidelines, guideline 10).
67
- const endOfOptions = words.indexOf('--');
68
- const flagCandidates = words.slice(1, endOfOptions === -1 ? undefined : endOfOptions);
34
+ // `rm -- -rf` and `rm build -- -rf` are not `rm -rf` — everything
35
+ // after a `--` end-of-options marker is an operand (a filename),
36
+ // never a flag (POSIX Utility Syntax Guidelines, guideline 10).
37
+ const endOfOptions = words.indexOf('--');
38
+ const flagCandidates = words.slice(0, endOfOptions === -1 ? undefined : endOfOptions);
69
39
 
70
- // Only static short-option clusters contribute flags; operands,
71
- // long options, and unresolved words supply no evidence. Recursive
72
- // and force may occur in the same word or in separate words.
73
- const shortOptions = flagCandidates.filter(
74
- (word) => word !== null && /^-[a-zA-Z]+$/.test(word),
75
- );
76
- const hasRecursive = shortOptions.some((word) => /[rR]/.test(word));
77
- const hasForce = shortOptions.some((word) => word.includes('f'));
78
- const isRecursiveForce = hasRecursive && hasForce;
40
+ // Only static short-option clusters contribute flags; operands,
41
+ // long options, and unresolved words supply no evidence. Recursive
42
+ // and force may occur in the same word or in separate words.
43
+ const shortOptions = flagCandidates.filter(
44
+ (word) => word !== null && /^-[a-zA-Z]+$/.test(word),
45
+ );
46
+ const hasRecursive = shortOptions.some((word) => /[rR]/.test(word));
47
+ const hasForce = shortOptions.some((word) => word.includes('f'));
48
+ const isRecursiveForce = hasRecursive && hasForce;
79
49
 
80
- if (isRecursiveForce) {
81
- context.report({ node, loc: node.loc, messageId: 'rmRf' });
50
+ if (isRecursiveForce) {
51
+ context.report({ node: command, messageId: 'rmRf' });
52
+ }
82
53
  }
83
54
  },
84
55
  };
@@ -0,0 +1,33 @@
1
+ import { defineShellRule } from '@eslint-sh/eslint-plugin';
2
+
3
+ export default defineShellRule({
4
+ meta: {
5
+ type: 'suggestion',
6
+ schema: [],
7
+ messages: { match: 'This script invokes sample-tool.' },
8
+ },
9
+ create(context) {
10
+ return {
11
+ File() {
12
+ const { commands } = context.sourceCode.getCommandInventory();
13
+ for (const site of commands) {
14
+ const { effective, chainIndices } = site.resolveInvokedCommand();
15
+ const index = chainIndices.at(-1);
16
+ if (index === undefined || (!effective.static && chainIndices.length > 1)) continue;
17
+
18
+ const facts = site.argvFacts.at(index);
19
+ if (facts?.resolution !== effective) continue;
20
+
21
+ const text = effective.static ? effective.text : undefined;
22
+ const name = facts.basename.known
23
+ ? facts.basename.text
24
+ : text?.slice(text.lastIndexOf('/') + 1);
25
+ const word = site.node.args.at(index);
26
+ if (name === 'sample-tool' && word) {
27
+ context.report({ node: word, messageId: 'match' });
28
+ }
29
+ }
30
+ },
31
+ };
32
+ },
33
+ });
@@ -38,6 +38,13 @@ node type. **Narrow it on `type`** and the node's own fields appear, typed:
38
38
  union of every `type` value. Field access that does not exist is a compile error, so a typo or a
39
39
  field from another node type is caught by the compiler.
40
40
 
41
+ ## Walking to a parent
42
+
43
+ Inside a listener, `context.sourceCode.getParent(node)` returns the immediate lint-view parent,
44
+ or `undefined` for the root `File`. For example, the parent of a command argument `Word` is
45
+ its `CallExpr`. Narrow the parent on `type` before accessing fields specific to that node kind.
46
+ Call `getParent` again to walk outward one level at a time.
47
+
41
48
  ## Where the fields come from
42
49
 
43
50
  The nodes mirror [mvdan/sh](https://github.com/mvdan/sh)'s syntax tree, as `sh-ast` exposes it.
@@ -51,7 +58,7 @@ rules that turn an upstream record into a lint-view node are fixed:
51
58
  | a slice (`CallExpr.Args`) | a read-only array of nodes; **always present**, empty when none |
52
59
  | a string (`Lit.Value`) | a JavaScript `string` (decoded from Go bytes) |
53
60
  | a boolean (`Stmt.Background`) | a `boolean` |
54
- | an operator (`BinaryCmd.Op`) | a number; compare with the constants from `…/syntax` (`AndStmt`) |
61
+ | an operator (`BinaryCmd.Op`) | a number with [named constants](#operator-constants) |
55
62
  | a position (`Stmt.Semicolon`) | none: use `range` and `loc` |
56
63
 
57
64
  A child that may be absent is an **optional** property, so the compiler makes you check it before
@@ -61,6 +68,24 @@ use (`stmt.cmd?.type`). A slice is never absent and never holds a missing entry,
61
68
  To find a field, hover the narrowed node in your editor, or read the `sh-ast` record of the same
62
69
  name: its field list is the node's field list, minus positions, lowercased.
63
70
 
71
+ ## Operator constants
72
+
73
+ Import named constants from `sh-ast`. The lint view preserves their numeric values in
74
+ `BinaryCmd.op` (`BinCmdOperator`) and `Redirect.op` (`RedirOperator`). To locate an
75
+ operator in the source, see the [tutorial's operator rule](./custom-rule-tutorial.md#6-report-on-an-operator).
76
+ It reads the operator text at `OpPos` and reports on the `&&` token.
77
+
78
+ | Node | Shell tokens | Constants from `sh-ast` (in token order) |
79
+ | --- | --- | --- |
80
+ | `BinaryCmd` | `&&`, `\|\|`, `\|`, `\|&` | `AndStmt`, `OrStmt`, `Pipe`, `PipeAll` |
81
+ | `Redirect` | `>`, `>>`, `<`, `<>` | `RdrOut`, `AppOut`, `RdrIn`, `RdrInOut` |
82
+ | `Redirect` | `<&`, `>&` | `DplIn`, `DplOut` |
83
+ | `Redirect` | `>\|`, `>>\|` | `RdrClob`, `AppClob` |
84
+ | `Redirect` | `<<`, `<<-`, `<<<` | `Hdoc`, `DashHdoc`, `WordHdoc` |
85
+ | `Redirect` | `&>`, `&>\|`, `&>>`, `&>>\|` | `RdrAll`, `RdrAllClob`, `AppAll`, `AppAllClob` |
86
+
87
+ The available tokens depend on the shell dialect. For example, `>>|` is a Zsh redirect.
88
+
64
89
  ## What the view adapts
65
90
 
66
91
  The types describe the view as it is, not the raw parse:
@@ -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. |
@@ -48,13 +48,13 @@ See the [canonical quickstart](https://github.com/mike-north/eslint-sh/blob/main
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,27 @@ 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`. The suggestion is
44
+ also withheld when a `declare`, `typeset`, `local` or `readonly` in the file names
45
+ `REPLY` or has an operand that is not static: an integer `REPLY` reads as `0` at end
46
+ of input, so the loop would never end, and other attributes change what it stores.
47
+
48
+ A here-string supplies shell text. Files, pipes, process substitutions, and
49
+ inherited stdin can contain NUL bytes, which `read` and `mapfile` handle differently.
50
+ Those inputs and leading redirections get a diagnostic without a suggestion.
57
51
 
58
52
  ## Options
59
53
 
@@ -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 `--`. An expanded destination attached to a literal `-v`, as in `"-v$name"` or `"-va[$i]"`, is read the same way. Bash rejects an invalid destination such as `-v1` or `-v 'a[1][2]'` before evaluating the format, so the rule stays quiet there.
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
@@ -15,9 +15,15 @@ The `-v` test arrived in Bash 4.2 (Bash NEWS for 4.2). In Bash 4.1 and older, `[
15
15
  The rule reports the `-v` test in two places:
16
16
 
17
17
  - inside `[[ … ]]`, where the parser gives the test its own node;
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.
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, `! -v name` negates the test, and any other three arguments are a syntax error, so `test -v name trailing` is not reported; 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. Bash evaluates such an expression before it rejects arguments left over after it, so a `-v` there is still reported.
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