@eslint-sh/eslint-plugin 0.9.0 → 0.10.1

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 (69) hide show
  1. package/README.md +23 -29
  2. package/dist/api.d.ts +4 -4
  3. package/dist/command-harvest/builtins/bats.d.ts +1 -1
  4. package/dist/command-harvest/harvest-commands.d.ts +18 -7
  5. package/dist/command-harvest/harvest-commands.js +11 -10
  6. package/dist/command-harvest/wrapper-table.d.ts +1 -1
  7. package/dist/command-harvest/wrapper-table.js +1 -1
  8. package/dist/eslint-plugin-api.d.ts +71 -60
  9. package/dist/language/command-resolution.d.ts +44 -10
  10. package/dist/language/command-resolution.js +39 -13
  11. package/dist/language/shell-source-code.d.ts +31 -47
  12. package/dist/language/shell-source-code.js +47 -62
  13. package/dist/language/syntax-clone.d.ts +29 -0
  14. package/dist/language/syntax-clone.js +76 -0
  15. package/dist/language/syntax-view.d.ts +23 -2
  16. package/dist/language/syntax-view.js +166 -33
  17. package/dist/language/word-resolution.d.ts +2 -2
  18. package/dist/language/word-resolution.js +2 -2
  19. package/dist/rules/compat/declaration-options.js +2 -2
  20. package/dist/rules/compat/no-brace-sequence-padding-step.js +1 -1
  21. package/dist/rules/compat/no-mapfile.js +2 -2
  22. package/dist/rules/compat/no-negative-array-index.js +2 -2
  23. package/dist/rules/compat/no-printf-time-format.js +2 -2
  24. package/dist/rules/compat/no-test-v.js +5 -3
  25. package/dist/rules/compat/no-wait-n.js +2 -2
  26. package/dist/rules/compat/nounset-array-proof.js +16 -9
  27. package/dist/rules/compat/posix-absent-command.js +2 -2
  28. package/dist/rules/compat/shopt-options.js +2 -2
  29. package/dist/rules/create-wrapper-rule.d.ts +3 -3
  30. package/dist/rules/create-wrapper-rule.js +8 -4
  31. package/dist/rules/no-dynamic-invocation.d.ts +1 -1
  32. package/dist/rules/no-dynamic-invocation.js +12 -4
  33. package/dist/rules/no-eval.js +6 -2
  34. package/dist/rules/no-masked-exit-status.d.ts +12 -0
  35. package/dist/rules/no-masked-exit-status.js +27 -17
  36. package/dist/rules/no-secret-env-reads.js +1 -1
  37. package/dist/rules/no-unchecked-cd.js +28 -21
  38. package/dist/rules/no-undeclared-commands.js +2 -1
  39. package/dist/rules/no-unused-declarations.js +7 -2
  40. package/dist/rules/prefer-local.js +10 -8
  41. package/dist/rules/quote-expansions.js +1 -1
  42. package/dist/rules/require-network-wrapper.d.ts +1 -1
  43. package/dist/rules/require-network-wrapper.js +10 -4
  44. package/dist/rules/require-tty-guard.js +1 -1
  45. package/dist/rules/resolve-network-wrapper.d.ts +2 -2
  46. package/dist/rules/resolve-network-wrapper.js +6 -6
  47. package/dist/rules/resolve-transparent-wrappers.d.ts +1 -1
  48. package/dist/rules/resolve-transparent-wrappers.js +2 -2
  49. package/dist/rules/transparent-wrappers.d.ts +3 -3
  50. package/dist/rules/transparent-wrappers.js +1 -1
  51. package/docs/custom-rule-tutorial.md +35 -35
  52. package/docs/error-codes.md +6 -5
  53. package/docs/examples/no-backticks-rule.mjs +1 -1
  54. package/docs/examples/no-curl-in-functions-rule.mjs +2 -2
  55. package/docs/examples/no-listed-commands-rule.ts +1 -1
  56. package/docs/examples/no-rm-rf-rule.mjs +1 -1
  57. package/docs/rules/no-dynamic-invocation.md +5 -0
  58. package/docs/rules/no-undeclared-commands.md +4 -0
  59. package/docs/rules/no-unused-declarations.md +4 -0
  60. package/docs/rules/require-network-wrapper.md +1 -1
  61. package/docs/selectors.md +1 -1
  62. package/docs/wrapper-rules.md +1 -1
  63. package/package.json +12 -23
  64. package/dist/eslint-plugin-syntax-analyze.d.ts +0 -23
  65. package/dist/eslint-plugin-syntax.d.ts +0 -30
  66. package/dist/syntax/analyze.d.ts +0 -19
  67. package/dist/syntax/analyze.js +0 -21
  68. package/dist/syntax/index.d.ts +0 -26
  69. package/dist/syntax/index.js +0 -28
@@ -1,4 +1,5 @@
1
- import type { Argv0Resolution, CallExpr, CommandContext, CommandSite, ResolveArgv0Options, WordResolution } from 'sh-ast/analyze';
1
+ import type { Argv0Resolution, CommandUncertainty, CommandContext, CommandSite, ResolveArgv0Options, WordResolution } from 'sh-analysis';
2
+ import type { CallExpr } from 'sh-ast';
2
3
  import type { ShellFile, ShellNode, ShellNodeOf } from './syntax-view.js';
3
4
  /**
4
5
  * Every command site in one parsed file, from a single `enumerateCommands`
@@ -10,19 +11,21 @@ import type { ShellFile, ShellNode, ShellNodeOf } from './syntax-view.js';
10
11
  */
11
12
  export interface CommandSiteIndex {
12
13
  readonly sites: readonly CommandSite[];
14
+ /** Opaque execution boundaries retained alongside represented commands. */
15
+ readonly uncertainties: readonly CommandUncertainty[];
13
16
  readonly byNode: ReadonlyMap<CallExpr, CommandSite>;
14
17
  }
15
18
  /**
16
19
  * One command invocation in a linted shell file, in lint-view terms: an
17
- * `sh-ast/analyze` `CommandSite` whose `node` is the `CallExpr` view node
20
+ * `sh-analysis` `CommandSite` whose `node` is the `CallExpr` view node
18
21
  * ESLint passes to rule visitors, so a rule can `context.report()` on it.
19
22
  *
20
- * The data comes from `sh-ast/analyze`'s `enumerateCommands` and is facts
23
+ * The data comes from `sh-analysis`'s `enumerateCommands` and is facts
21
24
  * only: how the command is reached and what its words resolve to, never a
22
25
  * verdict on whether running it is safe. A dynamic (`static: false`) `argv0`
23
26
  * is a normal result.
24
27
  *
25
- * Read one through `ShellSourceCode.getCommandSites()`.
28
+ * Read one through `ShellSourceCode.getCommandInventory().commands`.
26
29
  *
27
30
  * Every rule linting a file sees the same sites, so each one is deeply
28
31
  * frozen: the entry, its `context` array and every frame in it, its `argv`
@@ -43,7 +46,7 @@ export interface ShellCommandSite {
43
46
  readonly node: ShellNodeOf<'CallExpr'>;
44
47
  /**
45
48
  * The path from the file root to this command, outermost frame first,
46
- * exactly as `sh-ast/analyze` reports it. For example, `date` in
49
+ * exactly as `sh-analysis` reports it. For example, `date` in
47
50
  * `f() { echo "$(date)"; }` has
48
51
  * `[{ kind: 'function', name: 'f' }, { kind: 'cmdSubst' }]`.
49
52
  */
@@ -58,23 +61,47 @@ export interface ShellCommandSite {
58
61
  readonly argv: readonly WordResolution[];
59
62
  /**
60
63
  * Follows this command's argv0 through transparent wrappers (`env`, `sudo`,
61
- * `nohup`, `exec`, …) and returns `sh-ast/analyze`'s `resolveArgv0`
64
+ * `nohup`, `exec`, …) and returns `sh-analysis`'s `resolveArgv0`
62
65
  * result. Same answer as
63
66
  * `ShellSourceCode.resolveInvokedCommand(node, options)`; both read the
64
67
  * same per-file index.
65
68
  *
66
69
  * @param options - Forwarded to `resolveArgv0` unchanged.
67
- * `transparentWrappers` replaces `sh-ast/analyze`'s
70
+ * `transparentWrappers` replaces `sh-analysis`'s
68
71
  * `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
69
72
  * extend them instead.
70
73
  * @returns A new result on every call. Its `chain` and `chainIndices`
71
74
  * arrays belong to the caller. `chainIndices` gives each chain entry's
72
75
  * position in this site's `argv`.
73
- * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
76
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
74
77
  * `options.transparentWrappers` contains a malformed entry.
75
78
  */
76
79
  resolveInvokedCommand(options?: ResolveArgv0Options): Argv0Resolution;
77
80
  }
81
+ /**
82
+ * An opaque executable construct projected onto the original ESLint view.
83
+ * Its presence limits inventory completeness; it does not assert a hidden command.
84
+ * @public
85
+ */
86
+ export interface ShellCommandUncertainty {
87
+ /** The analysis observation, without a lint-policy interpretation. */
88
+ readonly reason: CommandUncertainty['reason'];
89
+ /** Original projected construct, with this file's UTF-16 range and location. */
90
+ readonly node: ShellNode;
91
+ /** Context reaching the opaque construct, outermost frame first. */
92
+ readonly context: readonly CommandContext[];
93
+ }
94
+ /**
95
+ * Represented commands and opaque execution boundaries in one linted file.
96
+ * Consumers requiring complete execution knowledge must consider uncertainties.
97
+ * @public
98
+ */
99
+ export interface ShellCommandInventory {
100
+ /** Known represented command sites, in source order. */
101
+ readonly commands: readonly ShellCommandSite[];
102
+ /** Opaque constructs whose executable contents cannot be enumerated. */
103
+ readonly uncertainties: readonly ShellCommandUncertainty[];
104
+ }
78
105
  /**
79
106
  * Builds the {@link CommandSiteIndex} for a whole parsed file with a single
80
107
  * `enumerateCommands` call over the file's original syntax. Each site's
@@ -86,13 +113,13 @@ export interface ShellCommandSite {
86
113
  * this bridge exists to prevent.
87
114
  *
88
115
  * The index is shared by every rule linting the file, and its data reaches
89
- * rules: `getCommandSites` exposes each site's `context`, `argv0` and `argv`.
116
+ * rules: `getCommandInventory` exposes each site's `context`, `argv0` and `argv`.
90
117
  * Analysis also shares one `context` array and its frames between
91
118
  * sibling commands. So every site is frozen in place here, before any rule
92
119
  * can see it (see {@link freezeCommandSite}).
93
120
  *
94
121
  * @throws TypeError with `ESLINT_SH_FILE_NODE` when `file` has no associated parsed syntax.
95
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
122
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when the file's
96
123
  * nesting exceeds analysis's recursion guard. It propagates unchanged: a
97
124
  * partial index would silently omit real commands, so callers fail closed.
98
125
  * @internal
@@ -114,6 +141,13 @@ export declare function buildCommandSiteIndex(file: ShellFile): CommandSiteIndex
114
141
  * @internal
115
142
  */
116
143
  export declare function viewCommandSites(file: ShellFile, index: CommandSiteIndex): readonly ShellCommandSite[];
144
+ /**
145
+ * Projects inventory limits by original syntax identity, using the same associations
146
+ * as command sites. A missing association is an adapter invariant failure, never
147
+ * permission to silently discard uncertainty or reinterpret shell source text.
148
+ * @internal
149
+ */
150
+ export declare function viewCommandInventory(file: ShellFile, index: CommandSiteIndex): ShellCommandInventory;
117
151
  /**
118
152
  * Returns the parser's own `CallExpr` behind a lint `CallExpr`.
119
153
  *
@@ -1,14 +1,14 @@
1
1
  /**
2
- * Bridges command-level questions from ESLint view identity back to faithful
3
- * syntax. `sh-ast/analyze` owns what a command invocation is and which command
4
- * it runs; this module only builds the per-file index of the `CommandSite`s
5
- * analysis reports, maps a lint `CallExpr` to its raw syntax node, and maps
6
- * each site's raw `CallExpr` forward to its lint view node, so every rule gets
7
- * the analysis answer rather than a local reinterpretation.
2
+ * Maps reusable command observations onto ESLint source identity. sh-analysis owns
3
+ * represented command sites, their context and opaque execution boundaries; this
4
+ * adapter indexes the original syntax nodes and maps every observation to its
5
+ * original lint view without interpreting source text or choosing lint policy.
8
6
  *
9
- * ESLINT_SH_FILE_NODE and ESLINT_SH_CALL_NODE reject missing syntax associations. ESLINT_SH_COMMAND_SITE_VIEW rejects a site from a different file; analysis resource and wrapper failures propagate unchanged.
7
+ * Missing source associations are invariant failures. Commands and uncertainties
8
+ * must never disappear during projection; analysis resource/configuration errors
9
+ * propagate unchanged instead of becoming partial inventories or parser errors.
10
10
  */
11
- import { enumerateCommands, resolveArgv0 } from 'sh-ast/analyze';
11
+ import { enumerateCommands, resolveArgv0 } from 'sh-analysis';
12
12
  import { syntaxForNode, viewForSyntax, withoutCrlfCarriageReturn } from './syntax-view.js';
13
13
  /**
14
14
  * Builds the {@link CommandSiteIndex} for a whole parsed file with a single
@@ -21,13 +21,13 @@ import { syntaxForNode, viewForSyntax, withoutCrlfCarriageReturn } from './synta
21
21
  * this bridge exists to prevent.
22
22
  *
23
23
  * The index is shared by every rule linting the file, and its data reaches
24
- * rules: `getCommandSites` exposes each site's `context`, `argv0` and `argv`.
24
+ * rules: `getCommandInventory` exposes each site's `context`, `argv0` and `argv`.
25
25
  * Analysis also shares one `context` array and its frames between
26
26
  * sibling commands. So every site is frozen in place here, before any rule
27
27
  * can see it (see {@link freezeCommandSite}).
28
28
  *
29
29
  * @throws TypeError with `ESLINT_SH_FILE_NODE` when `file` has no associated parsed syntax.
30
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
30
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when the file's
31
31
  * nesting exceeds analysis's recursion guard. It propagates unchanged: a
32
32
  * partial index would silently omit real commands, so callers fail closed.
33
33
  * @internal
@@ -39,8 +39,16 @@ export function buildCommandSiteIndex(file) {
39
39
  code: 'ESLINT_SH_FILE_NODE',
40
40
  });
41
41
  }
42
- const sites = Object.freeze(enumerateCommands(syntax).map((site) => freezeCommandSite(withLfArgv(site))));
43
- return { sites, byNode: new Map(sites.map((site) => [site.node, site])) };
42
+ const inventory = enumerateCommands(syntax);
43
+ const sites = Object.freeze(inventory.commands.map((site) => freezeCommandSite(withLfArgv(site))));
44
+ const uncertainties = Object.freeze(inventory.uncertainties.map((uncertainty) => {
45
+ for (const frame of uncertainty.context) {
46
+ Object.freeze(frame);
47
+ }
48
+ Object.freeze(uncertainty.context);
49
+ return Object.freeze(uncertainty);
50
+ }));
51
+ return { sites, uncertainties, byNode: new Map(sites.map((site) => [site.node, site])) };
44
52
  }
45
53
  /**
46
54
  * `site` with each argv word resolved as its LF equivalent (see
@@ -64,7 +72,7 @@ function withLfArgv(site) {
64
72
  *
65
73
  * Freezing in place, instead of copying, keeps every value identical to what
66
74
  * analysis returned. That is safe because `enumerateCommands` builds these
67
- * objects fresh on each call, and nothing in `sh-ast/analyze` writes to them
75
+ * objects fresh on each call, and nothing in `sh-analysis` writes to them
68
76
  * after it returns: `resolveArgv0` only reads a site. A frame's fields are
69
77
  * primitives or source text, so freezing each frame shallowly is complete.
70
78
  */
@@ -108,6 +116,24 @@ export function viewCommandSites(file, index) {
108
116
  });
109
117
  }));
110
118
  }
119
+ /**
120
+ * Projects inventory limits by original syntax identity, using the same associations
121
+ * as command sites. A missing association is an adapter invariant failure, never
122
+ * permission to silently discard uncertainty or reinterpret shell source text.
123
+ * @internal
124
+ */
125
+ export function viewCommandInventory(file, index) {
126
+ const uncertainties = Object.freeze(index.uncertainties.map((uncertainty) => {
127
+ const node = viewForSyntax(file, uncertainty.node);
128
+ if (node === undefined) {
129
+ throw Object.assign(new Error('command uncertainty has no node in the lint view of this file'), {
130
+ code: 'ESLINT_SH_COMMAND_UNCERTAINTY_VIEW',
131
+ });
132
+ }
133
+ return Object.freeze({ reason: uncertainty.reason, node, context: uncertainty.context });
134
+ }));
135
+ return Object.freeze({ commands: viewCommandSites(file, index), uncertainties });
136
+ }
111
137
  /**
112
138
  * Returns the parser's own `CallExpr` behind a lint `CallExpr`.
113
139
  *
@@ -10,9 +10,9 @@ import { TextSourceCodeBase } from '@eslint/plugin-kit';
10
10
  import type { ShellFile as ShFile, ShellNode as ShNode, ShellNodeOf, ShellComment } from './syntax-view.js';
11
11
  import type { Directive as IDirective, FileProblem, RulesConfig, SourceLocation, TraversalStep } from '@eslint/core';
12
12
  import type { Node as SyntaxNode, PrintOptions, SyntaxPos } from 'sh-ast';
13
- import type { Argv0Resolution, ResolveArgv0Options, ResolveWordOptions, WordResolution } from 'sh-ast/analyze';
13
+ import type { Argv0Resolution, ResolveArgv0Options, ResolveWordOptions, WordResolution } from 'sh-analysis';
14
14
  import type { ShellDialect, ShellLanguageOptions } from './shell-language-options.js';
15
- import type { ShellCommandSite } from './command-resolution.js';
15
+ import type { ShellCommandInventory } from './command-resolution.js';
16
16
  /**
17
17
  * `ShellSourceCode` — the `SourceCode` object ESLint uses to work with a
18
18
  * parsed shell file. Extends `@eslint/plugin-kit`'s `TextSourceCodeBase`, which
@@ -44,10 +44,10 @@ import type { ShellCommandSite } from './command-resolution.js';
44
44
  * from `context.sourceCode`; its constructor is internal language plumbing.
45
45
  *
46
46
  * Rule-author helpers (`resolveWord`, `resolveWordText`, `getCommandName`,
47
- * `resolveInvokedCommand`, `getCommandSites`) answer "is this word statically
47
+ * `resolveInvokedCommand`, `getCommandInventory`) answer "is this word statically
48
48
  * the string `jq`?", "which command does this invocation run?", and "which
49
49
  * commands does this file run, and where?" by delegating to
50
- * `sh-ast/analyze`. They never reinterpret words themselves, so every rule
50
+ * `sh-analysis`. They never reinterpret words themselves, so every rule
51
51
  * gets the same answer for the same syntax. `dialect` and `minBashVersion`
52
52
  * expose the file's normalized language options.
53
53
  *
@@ -123,7 +123,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
123
123
  }): number;
124
124
  /**
125
125
  * Resolves a lint-view word using its original syntax and grammar position.
126
- * `sh-ast/analyze` owns static-word interpretation and dynamic reasons; this
126
+ * `sh-analysis` owns static-word interpretation and dynamic reasons; this
127
127
  * method supplies the lint tree's position-based policy, without executing shell.
128
128
  *
129
129
  * Without explicit options, `CallExpr.args` use command-argument context, so
@@ -141,7 +141,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
141
141
  /**
142
142
  * The text-only form of {@link ShellSourceCode.resolveWord}: returns its text
143
143
  * exactly when static, otherwise `null`. Both methods share one policy path
144
- * through `sh-ast/analyze`.
144
+ * through `sh-analysis`.
145
145
  *
146
146
  * @param word - A parsed Word from the lint view.
147
147
  * @param options - Explicit analysis policy overriding grammar defaults.
@@ -157,7 +157,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
157
157
  * {@link ShellSourceCode.resolveInvokedCommand} for the command a wrapper
158
158
  * chain actually runs.
159
159
  *
160
- * Delegates to `sh-ast/analyze`: the answer is the `argv0` resolution of the
160
+ * Delegates to `sh-analysis`: the answer is the `argv0` resolution of the
161
161
  * `CommandSite` that `enumerateCommands` reports for this `CallExpr` in this
162
162
  * file. Leading `VAR=val` assignments are not part of argv, so
163
163
  * `FOO=1 jq .` yields `"jq"`. An assignment-only statement (`FOO=1`) has no
@@ -166,14 +166,14 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
166
166
  * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
167
167
  * @returns The command word's static text, or `null`.
168
168
  * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
169
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
169
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
170
170
  * nesting exceeds analysis's recursion guard; see
171
171
  * {@link ShellSourceCode.resolveInvokedCommand}.
172
172
  */
173
173
  getCommandName(callExpr: ShellNodeOf<'CallExpr'>): string | null;
174
174
  /**
175
175
  * Follows `callExpr`'s argv0 through transparent wrappers (`env`, `sudo`,
176
- * `nohup`, `exec`, …) and returns `sh-ast/analyze`'s full `resolveArgv0`
176
+ * `nohup`, `exec`, …) and returns `sh-analysis`'s full `resolveArgv0`
177
177
  * result, or `null` for a `CallExpr` that has no `CommandSite` (an
178
178
  * assignment-only statement such as `FOO=1`).
179
179
  *
@@ -187,7 +187,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
187
187
  * `embedded-command`; `chain`
188
188
  * lists every word resolved along the way, outermost wrapper first, and
189
189
  * `chainIndices` gives each entry's position in the command's `argv` (as
190
- * {@link ShellSourceCode.getCommandSites} reports it). When `effective` is
190
+ * {@link ShellSourceCode.getCommandInventory} reports it). When `effective` is
191
191
  * static, the effective command's arguments are
192
192
  * `argv.slice(chainIndices.at(-1)! + 1)`: every entry after the effective
193
193
  * command's own index. For an interpreter command string the final chain
@@ -205,49 +205,32 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
205
205
  *
206
206
  * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
207
207
  * @param options - Forwarded to `resolveArgv0` unchanged.
208
- * `transparentWrappers` replaces `sh-ast/analyze`'s
208
+ * `transparentWrappers` replaces `sh-analysis`'s
209
209
  * `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
210
210
  * extend them instead.
211
211
  * @returns The resolution, or `null` when `callExpr` invokes no command.
212
212
  * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
213
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
213
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
214
214
  * nesting exceeds analysis's recursion guard.
215
- * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
215
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
216
216
  * `options.transparentWrappers` contains a malformed entry.
217
217
  */
218
218
  resolveInvokedCommand(callExpr: ShellNodeOf<'CallExpr'>, options?: ResolveArgv0Options): Argv0Resolution | null;
219
219
  /**
220
- * Returns every command invocation in this file, one entry per
221
- * `sh-ast/analyze` `CommandSite`, in source order. Use it when a rule needs
222
- * the whole file's commands with their structural context, such as every
223
- * command inside a function or inside `$(…)`, instead of visiting
224
- * `CallExpr` nodes one by one.
220
+ * Returns represented command sites and explicit opaque execution boundaries.
221
+ * Both retain original node identity in this file's UTF-16 ESLint view. This
222
+ * adapter maps sh-analysis observations without parsing text or choosing policy.
225
223
  *
226
- * The data comes from `sh-ast/analyze`'s `enumerateCommands`: facts about
227
- * how each command is reached and what its words resolve to, never a
228
- * verdict. Each entry's `context`, `argv0`, and `argv` are analysis's own
229
- * values, unchanged; `context` lists frames outermost first, as in sh-ast.
230
- * Each entry's `node` is the `CallExpr` view node (`===` the node ESLint
231
- * passes to a `CallExpr` visitor), so it can be passed to
232
- * `context.report()`.
224
+ * The inventory and observation data are frozen and shared across rules; view
225
+ * nodes retain ESLint's ordinary mutable-node contract. Enumeration runs once,
226
+ * lazily, shared with getCommandName and resolveInvokedCommand. Analysis errors
227
+ * propagate unchanged rather than returning a partial inventory.
233
228
  *
234
- * An assignment-only statement (`FOO=1`) runs no command and has no entry,
235
- * although a command substitution in its value (`FOO=$(date)`) does.
236
- *
237
- * Enumeration runs at most once per file, shared with
238
- * {@link ShellSourceCode.getCommandName} and
239
- * {@link ShellSourceCode.resolveInvokedCommand}, and every call returns the
240
- * same array. Because every rule shares it, the array and everything in each
241
- * entry except `node` are deeply frozen (see `ShellCommandSite`): no rule can
242
- * change what another rule reads. If the file's nesting exceeds `enumerateCommands`'s
243
- * recursion guard, its `ShAnalyzeMaxDepthError` propagates unchanged, as it
244
- * does for those helpers: a partial list would silently omit real commands.
245
- *
246
- * @returns This file's command sites, in source order.
247
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
248
- * nesting exceeds analysis's recursion guard.
229
+ * A known-command policy may inspect `commands`; any assertion of execution
230
+ * completeness must also account for `uncertainties` and its own dynamic-code
231
+ * assumptions. Empty commands with nonempty uncertainties never proves no execution.
249
232
  */
250
- getCommandSites(): readonly ShellCommandSite[];
233
+ getCommandInventory(): ShellCommandInventory;
251
234
  /**
252
235
  * Returns the sh-ast record `node` was projected from: this file's original
253
236
  * parse of `node`, with every field the lint view leaves out, including
@@ -255,7 +238,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
255
238
  * `Redirect.OpPos`. Pass those positions to
256
239
  * {@link ShellSourceCode.getIndexFromSyntaxPos} or
257
240
  * {@link ShellSourceCode.getLocFromSyntaxPos} to report on them, or pass the
258
- * record to an `sh-ast/analyze` function.
241
+ * record to an `sh-analysis` function.
259
242
  *
260
243
  * The returned record is read-only by contract. It is the language's
261
244
  * original parse, shared by every rule and helper linting this file, and
@@ -296,11 +279,12 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
296
279
  * was parsed from: the first half of a printed fix. Edit the copy, then pass
297
280
  * it to {@link ShellSourceCode.getPrintedReplacement}.
298
281
  *
299
- * The copy is `structuredClone` of the record
300
- * {@link ShellSourceCode.getSyntax} returns. sh-ast documents and tests
301
- * ordinary `structuredClone` as the supported way to make an independent
302
- * editable copy of a syntax subtree (sh-ast 0.7.0 README, "Editing and
303
- * printing"), so no second parse is involved. The copy owns its records,
282
+ * The copy is what `structuredClone` of the record
283
+ * {@link ShellSourceCode.getSyntax} returns would be, which sh-ast documents
284
+ * and tests as the supported way to make an independent editable copy of a
285
+ * syntax subtree (sh-ast 0.7.0 README, "Editing and printing"), so no second
286
+ * parse is involved. It is made without recursion per tree level, so a
287
+ * subtree of any depth can be copied. The copy owns its records,
304
288
  * arrays, positions and byte buffers. Editing it leaves this file's original
305
289
  * syntax, its lint view, its cached traversal and the answers of view-aware
306
290
  * helpers such as {@link ShellSourceCode.resolveWord} and
@@ -7,11 +7,12 @@
7
7
  * their classes, codes and causes.
8
8
  */
9
9
  import { ConfigCommentParser, Directive, TextSourceCodeBase, VisitNodeStep, } from '@eslint/plugin-kit';
10
- import { childNodes, isShellComment, projectedComments, projectedCoordinates, syntaxForNode, viewForSyntax, walkShell, } from './syntax-view.js';
10
+ import { isShellComment, projectedComments, projectedCoordinates, syntaxForNode, traverseShell, viewForSyntax, walkShell, } from './syntax-view.js';
11
+ import { cloneSyntax } from './syntax-clone.js';
11
12
  import { SourceCoordinates } from './source-coordinates.js';
12
13
  import { SYNTAX_INTERFACES, printSync } from 'sh-ast';
13
- import { resolveArgv0 } from 'sh-ast/analyze';
14
- import { buildCommandSiteIndex, rawCallExprFor, viewCommandSites } from './command-resolution.js';
14
+ import { resolveArgv0 } from 'sh-analysis';
15
+ import { buildCommandSiteIndex, rawCallExprFor, viewCommandInventory, } from './command-resolution.js';
15
16
  import { resolveWord } from './word-resolution.js';
16
17
  /**
17
18
  * Refuses edited syntax whose string or byte values the upstream printer treats as layout.
@@ -339,10 +340,10 @@ function withUnusedDirectiveFixRange(comment, text) {
339
340
  * from `context.sourceCode`; its constructor is internal language plumbing.
340
341
  *
341
342
  * Rule-author helpers (`resolveWord`, `resolveWordText`, `getCommandName`,
342
- * `resolveInvokedCommand`, `getCommandSites`) answer "is this word statically
343
+ * `resolveInvokedCommand`, `getCommandInventory`) answer "is this word statically
343
344
  * the string `jq`?", "which command does this invocation run?", and "which
344
345
  * commands does this file run, and where?" by delegating to
345
- * `sh-ast/analyze`. They never reinterpret words themselves, so every rule
346
+ * `sh-analysis`. They never reinterpret words themselves, so every rule
346
347
  * gets the same answer for the same syntax. `dialect` and `minBashVersion`
347
348
  * expose the file's normalized language options.
348
349
  *
@@ -415,7 +416,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
415
416
  */
416
417
  #commandSites;
417
418
  /**
418
- * {@link ShellSourceCode.getCommandSites}'s answer: the index's sites in
419
+ * {@link ShellSourceCode.getCommandInventory}'s answer: the index's sites in
419
420
  * view terms, built once from `#commandSites` so every caller shares one
420
421
  * frozen array.
421
422
  */
@@ -501,7 +502,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
501
502
  }
502
503
  /**
503
504
  * Resolves a lint-view word using its original syntax and grammar position.
504
- * `sh-ast/analyze` owns static-word interpretation and dynamic reasons; this
505
+ * `sh-analysis` owns static-word interpretation and dynamic reasons; this
505
506
  * method supplies the lint tree's position-based policy, without executing shell.
506
507
  *
507
508
  * Without explicit options, `CallExpr.args` use command-argument context, so
@@ -521,7 +522,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
521
522
  /**
522
523
  * The text-only form of {@link ShellSourceCode.resolveWord}: returns its text
523
524
  * exactly when static, otherwise `null`. Both methods share one policy path
524
- * through `sh-ast/analyze`.
525
+ * through `sh-analysis`.
525
526
  *
526
527
  * @param word - A parsed Word from the lint view.
527
528
  * @param options - Explicit analysis policy overriding grammar defaults.
@@ -550,7 +551,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
550
551
  * {@link ShellSourceCode.resolveInvokedCommand} for the command a wrapper
551
552
  * chain actually runs.
552
553
  *
553
- * Delegates to `sh-ast/analyze`: the answer is the `argv0` resolution of the
554
+ * Delegates to `sh-analysis`: the answer is the `argv0` resolution of the
554
555
  * `CommandSite` that `enumerateCommands` reports for this `CallExpr` in this
555
556
  * file. Leading `VAR=val` assignments are not part of argv, so
556
557
  * `FOO=1 jq .` yields `"jq"`. An assignment-only statement (`FOO=1`) has no
@@ -559,7 +560,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
559
560
  * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
560
561
  * @returns The command word's static text, or `null`.
561
562
  * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
562
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
563
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
563
564
  * nesting exceeds analysis's recursion guard; see
564
565
  * {@link ShellSourceCode.resolveInvokedCommand}.
565
566
  */
@@ -569,7 +570,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
569
570
  }
570
571
  /**
571
572
  * Follows `callExpr`'s argv0 through transparent wrappers (`env`, `sudo`,
572
- * `nohup`, `exec`, …) and returns `sh-ast/analyze`'s full `resolveArgv0`
573
+ * `nohup`, `exec`, …) and returns `sh-analysis`'s full `resolveArgv0`
573
574
  * result, or `null` for a `CallExpr` that has no `CommandSite` (an
574
575
  * assignment-only statement such as `FOO=1`).
575
576
  *
@@ -583,7 +584,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
583
584
  * `embedded-command`; `chain`
584
585
  * lists every word resolved along the way, outermost wrapper first, and
585
586
  * `chainIndices` gives each entry's position in the command's `argv` (as
586
- * {@link ShellSourceCode.getCommandSites} reports it). When `effective` is
587
+ * {@link ShellSourceCode.getCommandInventory} reports it). When `effective` is
587
588
  * static, the effective command's arguments are
588
589
  * `argv.slice(chainIndices.at(-1)! + 1)`: every entry after the effective
589
590
  * command's own index. For an interpreter command string the final chain
@@ -601,14 +602,14 @@ export class ShellSourceCode extends TextSourceCodeBase {
601
602
  *
602
603
  * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
603
604
  * @param options - Forwarded to `resolveArgv0` unchanged.
604
- * `transparentWrappers` replaces `sh-ast/analyze`'s
605
+ * `transparentWrappers` replaces `sh-analysis`'s
605
606
  * `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
606
607
  * extend them instead.
607
608
  * @returns The resolution, or `null` when `callExpr` invokes no command.
608
609
  * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
609
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
610
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
610
611
  * nesting exceeds analysis's recursion guard.
611
- * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
612
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
612
613
  * `options.transparentWrappers` contains a malformed entry.
613
614
  */
614
615
  resolveInvokedCommand(callExpr, options) {
@@ -616,38 +617,21 @@ export class ShellSourceCode extends TextSourceCodeBase {
616
617
  return site ? resolveArgv0(site, options) : null;
617
618
  }
618
619
  /**
619
- * Returns every command invocation in this file, one entry per
620
- * `sh-ast/analyze` `CommandSite`, in source order. Use it when a rule needs
621
- * the whole file's commands with their structural context, such as every
622
- * command inside a function or inside `$(…)`, instead of visiting
623
- * `CallExpr` nodes one by one.
620
+ * Returns represented command sites and explicit opaque execution boundaries.
621
+ * Both retain original node identity in this file's UTF-16 ESLint view. This
622
+ * adapter maps sh-analysis observations without parsing text or choosing policy.
624
623
  *
625
- * The data comes from `sh-ast/analyze`'s `enumerateCommands`: facts about
626
- * how each command is reached and what its words resolve to, never a
627
- * verdict. Each entry's `context`, `argv0`, and `argv` are analysis's own
628
- * values, unchanged; `context` lists frames outermost first, as in sh-ast.
629
- * Each entry's `node` is the `CallExpr` view node (`===` the node ESLint
630
- * passes to a `CallExpr` visitor), so it can be passed to
631
- * `context.report()`.
624
+ * The inventory and observation data are frozen and shared across rules; view
625
+ * nodes retain ESLint's ordinary mutable-node contract. Enumeration runs once,
626
+ * lazily, shared with getCommandName and resolveInvokedCommand. Analysis errors
627
+ * propagate unchanged rather than returning a partial inventory.
632
628
  *
633
- * An assignment-only statement (`FOO=1`) runs no command and has no entry,
634
- * although a command substitution in its value (`FOO=$(date)`) does.
635
- *
636
- * Enumeration runs at most once per file, shared with
637
- * {@link ShellSourceCode.getCommandName} and
638
- * {@link ShellSourceCode.resolveInvokedCommand}, and every call returns the
639
- * same array. Because every rule shares it, the array and everything in each
640
- * entry except `node` are deeply frozen (see `ShellCommandSite`): no rule can
641
- * change what another rule reads. If the file's nesting exceeds `enumerateCommands`'s
642
- * recursion guard, its `ShAnalyzeMaxDepthError` propagates unchanged, as it
643
- * does for those helpers: a partial list would silently omit real commands.
644
- *
645
- * @returns This file's command sites, in source order.
646
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
647
- * nesting exceeds analysis's recursion guard.
629
+ * A known-command policy may inspect `commands`; any assertion of execution
630
+ * completeness must also account for `uncertainties` and its own dynamic-code
631
+ * assumptions. Empty commands with nonempty uncertainties never proves no execution.
648
632
  */
649
- getCommandSites() {
650
- this.#commandSiteViews ??= viewCommandSites(this.ast, this.#getCommandSiteIndex());
633
+ getCommandInventory() {
634
+ this.#commandSiteViews ??= viewCommandInventory(this.ast, this.#getCommandSiteIndex());
651
635
  return this.#commandSiteViews;
652
636
  }
653
637
  /**
@@ -657,7 +641,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
657
641
  * `Redirect.OpPos`. Pass those positions to
658
642
  * {@link ShellSourceCode.getIndexFromSyntaxPos} or
659
643
  * {@link ShellSourceCode.getLocFromSyntaxPos} to report on them, or pass the
660
- * record to an `sh-ast/analyze` function.
644
+ * record to an `sh-analysis` function.
661
645
  *
662
646
  * The returned record is read-only by contract. It is the language's
663
647
  * original parse, shared by every rule and helper linting this file, and
@@ -704,11 +688,12 @@ export class ShellSourceCode extends TextSourceCodeBase {
704
688
  * was parsed from: the first half of a printed fix. Edit the copy, then pass
705
689
  * it to {@link ShellSourceCode.getPrintedReplacement}.
706
690
  *
707
- * The copy is `structuredClone` of the record
708
- * {@link ShellSourceCode.getSyntax} returns. sh-ast documents and tests
709
- * ordinary `structuredClone` as the supported way to make an independent
710
- * editable copy of a syntax subtree (sh-ast 0.7.0 README, "Editing and
711
- * printing"), so no second parse is involved. The copy owns its records,
691
+ * The copy is what `structuredClone` of the record
692
+ * {@link ShellSourceCode.getSyntax} returns would be, which sh-ast documents
693
+ * and tests as the supported way to make an independent editable copy of a
694
+ * syntax subtree (sh-ast 0.7.0 README, "Editing and printing"), so no second
695
+ * parse is involved. It is made without recursion per tree level, so a
696
+ * subtree of any depth can be copied. The copy owns its records,
712
697
  * arrays, positions and byte buffers. Editing it leaves this file's original
713
698
  * syntax, its lint view, its cached traversal and the answers of view-aware
714
699
  * helpers such as {@link ShellSourceCode.resolveWord} and
@@ -728,7 +713,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
728
713
  * file, or an object that did not come from the parser.
729
714
  */
730
715
  getEditableSyntax(node) {
731
- return structuredClone(this.#originalSyntaxFor(node));
716
+ return cloneSyntax(this.#originalSyntaxFor(node));
732
717
  }
733
718
  /**
734
719
  * Prints `edited` with sh-ast's `printSync` and pairs the text with the
@@ -896,17 +881,17 @@ export class ShellSourceCode extends TextSourceCodeBase {
896
881
  }
897
882
  const steps = [];
898
883
  this.#steps = steps;
899
- const visit = (node, parent) => {
900
- if (parent) {
901
- this.#parents.set(node, parent);
902
- }
903
- steps.push(new VisitNodeStep({ target: node, phase: 1, args: [node, parent] }));
904
- for (const child of childNodes(node)) {
905
- visit(child, node);
906
- }
907
- steps.push(new VisitNodeStep({ target: node, phase: 2, args: [node, parent] }));
908
- };
909
- visit(this.ast, undefined);
884
+ traverseShell(this.ast, {
885
+ enter: (node, parent) => {
886
+ if (parent) {
887
+ this.#parents.set(node, parent);
888
+ }
889
+ steps.push(new VisitNodeStep({ target: node, phase: 1, args: [node, parent] }));
890
+ },
891
+ exit: (node, parent) => {
892
+ steps.push(new VisitNodeStep({ target: node, phase: 2, args: [node, parent] }));
893
+ },
894
+ });
910
895
  return steps.values();
911
896
  }
912
897
  /**
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Deep copy of sh-ast syntax records that does not recurse once per tree level.
3
+ *
4
+ * `structuredClone` recurses natively, so V8 overflows its stack on a record
5
+ * graph nested a thousand or so levels deep, such as the left-nested records of
6
+ * a long `a && b && …` list. {@link cloneSyntax} gives the same result for the
7
+ * values a syntax tree is made of, walking the graph with an explicit work list
8
+ * so depth costs heap, not call stack.
9
+ */
10
+ /**
11
+ * Returns an independent deep copy of `value` with `structuredClone`'s
12
+ * semantics for syntax records: plain objects and arrays are copied entry by
13
+ * entry (own enumerable string keys, array holes and length preserved),
14
+ * `Uint8Array` byte strings are copied into fresh memory (a `Buffer` or an
15
+ * offset view does not share storage with the copy), a record reachable twice
16
+ * is copied once so shared and cyclic references keep their shape, and
17
+ * prototypes are not carried over. A function or symbol value fails with
18
+ * `structuredClone`'s `DataCloneError`.
19
+ *
20
+ * Supported input is what sh-ast records contain: plain objects, arrays,
21
+ * primitives and `Uint8Array`s. Any other object is handed to `structuredClone`
22
+ * as a whole, so a `Map` or `Set` is copied by it (records shared with the
23
+ * surrounding graph are duplicated) and a `Proxy` is copied as a plain object.
24
+ *
25
+ * No depth limit applies other than available memory.
26
+ *
27
+ * @internal
28
+ */
29
+ export declare function cloneSyntax<T>(value: T): T;