@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
package/README.md CHANGED
@@ -51,7 +51,7 @@ directly. Named helpers such as `commentPragma` are properties of that same obje
51
51
  `require('@eslint-sh/eslint-plugin').default` also returns it. These helper/default properties are
52
52
  non-enumerable, so they do not change ESLint's plugin or config serialization.
53
53
  Both packages remain ESM-only and use Node's synchronous `require(ESM)` support
54
- (Node 22.13+ on the 22.x line, or Node 24+). ESM default and named imports are unchanged.
54
+ (Node 22.14+ on the 22.x line, or Node 24+). ESM default and named imports are unchanged.
55
55
 
56
56
  For TypeScript CommonJS consumers, use `import sh = require('@eslint-sh/eslint-plugin')` with
57
57
  `module: "node20"` and `moduleResolution: "node16"`, or `module: "nodenext"` and
@@ -98,7 +98,7 @@ ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'p
98
98
  `context.sourceCode`; construction belongs to the language pipeline. It extends `@eslint/plugin-kit`'s `TextSourceCodeBase`; implements `traverse()`
99
99
  (driven by the consumer's `visitorKeys`, yielding two-phase `VisitNodeStep`s), `getParent()`, and
100
100
  the disable-directive surface (`getDisableDirectives()`, `getInlineConfigNodes()`,
101
- `applyInlineConfig()`). Rule authors get helpers that delegate to `sh-ast/analyze`, so every rule
101
+ `applyInlineConfig()`). Rule authors get helpers that delegate to `sh-analysis`, so every rule
102
102
  gets the same answer: `resolveWord(word, options?)` (the full `WordResolution`) and
103
103
  `resolveWordText(word, options?)` (exactly its static text, or `null`). Both use grammar-position
104
104
  defaults: command-argument context for `CallExpr.args`, conservative tilde handling elsewhere;
@@ -123,7 +123,10 @@ ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'p
123
123
  `ShellNodeMap` maps one to the other. They are computed from `sh-ast`'s generated typings, so
124
124
  they follow the pinned mvdan/sh version. `ShellNodeField<T>` is the type of one node field
125
125
  (`ShellNodeField<ShellNodeOf<'Stmt'>['cmd']>`), for a helper that takes or returns field values.
126
- - `ShellCommandSite` / `CommandContext` / `ResolveArgv0Options` — one command in a file as `getCommandSites()` reports it:
126
+ - `ShellCommandInventory` / `ShellCommandUncertainty` — represented commands and explicit
127
+ opaque execution boundaries from `getCommandInventory()`. Each uncertainty carries its reason,
128
+ original view node, and structural context. The inventory is frozen and cached per file.
129
+ - `ShellCommandSite` / `CommandContext` / `ResolveArgv0Options` — one command in a file as `getCommandInventory().commands` reports it:
127
130
  its `CallExpr` node (`node`), the `context` path of enclosing constructs from the file root
128
131
  (each frame a `CommandContext`, discriminated by `kind`: `and`, `or`, `pipeline`, `subshell`,
129
132
  `cmdSubst`, …), its `argv0` and `argv` as `WordResolution`s, and `resolveInvokedCommand()`,
@@ -138,7 +141,7 @@ ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'p
138
141
  - `ShellDialect` — the `dialect` language option's values: `'bash'`, `'posix'`, `'mksh'`,
139
142
  `'bats'` and `'zsh'`.
140
143
  - `Argv0Resolution` — the type `ShellSourceCode.resolveInvokedCommand` returns, re-exported from
141
- `sh-ast/analyze`.
144
+ `sh-analysis`.
142
145
  - `DeclarationConvention` / `DeclaredCommand` / `commentPragma` — the extension point for how a
143
146
  project declares the external commands its scripts use, bound with
144
147
  `settings: { sh: { declarationConvention } }`. `commentPragma` is the reference convention,
@@ -183,37 +186,28 @@ ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'p
183
186
  reported, such as `curl --version` or `git clone ./x`. See
184
187
  [wrapper rules](./docs/wrapper-rules.md#local-only-invocations).
185
188
 
186
- ## Faithful syntax: `@eslint-sh/eslint-plugin/syntax`
189
+ ## Faithful syntax: `sh-ast`
187
190
 
188
- The root exports work on the plugin's lint view (`ShellNode`). A rule that edits or analyzes the
189
- parser's own records needs `sh-ast` itself: `walk`, `parseSync`, `printSync` and `PrintOptions`,
190
- the record types (`Node`, `Word`, `CallExpr`, `SyntaxPos`, `GoString`, …), and the analysis
191
- helpers. Import them from this package's subpaths, not from `sh-ast`:
191
+ The plugin root owns ESLint view types, source helpers and rule policy. For raw syntax
192
+ operations and types, install and import `sh-ast` directly. For reusable word and command
193
+ observations, install and import `sh-analysis` directly:
192
194
 
193
195
  ```js
194
- // Rules use context.sourceCode.resolveWord(word) for lint-view Word nodes.
195
196
  import { defineShellRule } from '@eslint-sh/eslint-plugin';
196
- // sh-ast's root entry point: parse, walk, and print faithful records.
197
- import { parseSync, printSync, walk } from '@eslint-sh/eslint-plugin/syntax';
198
- // sh-ast/analyze: command enumeration and wrapper resolution over faithful records.
199
- import {
200
- DEFAULT_TRANSPARENT_WRAPPERS,
201
- enumerateCommands,
202
- } from '@eslint-sh/eslint-plugin/syntax/analyze';
197
+ import { parseSync, printSync, walk } from 'sh-ast';
198
+ import { DEFAULT_TRANSPARENT_WRAPPERS, enumerateCommands } from 'sh-analysis';
203
199
  ```
204
200
 
205
- - `@eslint-sh/eslint-plugin/syntax` re-exports the complete public surface of `sh-ast`, and
206
- `@eslint-sh/eslint-plugin/syntax/analyze` re-exports `sh-ast/analyze`. Both come from the
207
- `sh-ast` this plugin depends on, the same module instance its language parses with, so you
208
- don't install `sh-ast` yourself and records always match the parser that made them. Nothing is
209
- wrapped or renamed; each name keeps `sh-ast`'s own contract and docs.
210
- - `context.sourceCode.resolveWord(word)` accepts a lint-view Word and uses grammar-position
211
- defaults. `resolveWord` in `…/syntax/analyze` accepts a faithful syntax record and retains
212
- upstream defaults. The root exports no free word-resolution function.
213
- - **Versioning.** `…/syntax` and `…/syntax/analyze` track this plugin's pinned `sh-ast` minor
214
- (currently `sh-ast@^0.10.0`). Under 0.x, a different `sh-ast` minor is a breaking change, so
215
- an `sh-ast` 0.x minor bump is a minor bump of this plugin, and the changelog entry names the
216
- new `sh-ast` version.
201
+ The supported dependency ranges are `sh-ast@^0.11.0` and `sh-analysis@^0.1.0`.
202
+ The plugin has no syntax forwarding subpaths. Raw `resolveWord` from `sh-analysis` accepts
203
+ faithful syntax records; `context.sourceCode.resolveWord` maps an ESLint Word view to its
204
+ original syntax and applies grammar-position defaults.
205
+
206
+ `context.sourceCode.getCommandInventory()` returns `{ commands, uncertainties }`, with
207
+ both command sites and opaque execution boundaries mapped to original ESLint nodes. Known
208
+ command policies may inspect `commands`. An inventory with uncertainties cannot establish
209
+ complete execution knowledge: a Zsh subscript preserved as raw text may contain executable
210
+ code even when no nested command node exists. The helper never reparses that text.
217
211
 
218
212
  Syntax failures surface as fatal lint messages at mvdan/sh's reported byte offset, converted to
219
213
  the source's UTF-16 location. Failures without a valid syntax position use a 1:1 fallback. A
package/dist/api.d.ts CHANGED
@@ -8,9 +8,9 @@ import { ShellLanguage } from './language/shell-language.js';
8
8
  export type { ShellLanguage } from './language/shell-language.js';
9
9
  export type { ShellSourceCode } from './language/shell-source-code.js';
10
10
  export type { NormalizedShellLanguageOptions, ShellLanguageOptions, ShellLanguageOptionsJSON, } from './language/shell-language-options.js';
11
- export type { Argv0Resolution } from 'sh-ast/analyze';
12
- export type { CommandContext, ResolveArgv0Options, WordResolution } from 'sh-ast/analyze';
13
- export type { ShellCommandSite } from './language/command-resolution.js';
11
+ export type { Argv0Resolution } from 'sh-analysis';
12
+ export type { CommandContext, ResolveArgv0Options, WordResolution } from 'sh-analysis';
13
+ export type { ShellCommandSite, ShellCommandInventory, ShellCommandUncertainty, } from './language/command-resolution.js';
14
14
  export type { ShellComment, ShellFile, ShellNode, ShellNodeField, ShellNodeMap, ShellNodeOf, ShellNodeType, ShellPosition, } from './language/syntax-view.js';
15
15
  export type { ShellDialect } from './language/shell-language-options.js';
16
16
  export type { DeclarationConvention, DeclaredCommand, FileDeclaredCommand, LintedFile, DescribedDeclaredCommand, ScriptDeclaredCommand, } from './declaration-conventions/declaration-convention.js';
@@ -23,7 +23,7 @@ export { defineShellRule } from './rules/define-shell-rule.js';
23
23
  export type { ShellListener, ShellRule, ShellRuleContext, ShellRuleMeta, ShellRuleSpec, ShellRuleVisitor, ShellTypedListeners, } from './rules/define-shell-rule.js';
24
24
  export { createWrapperRule } from './rules/create-wrapper-rule.js';
25
25
  export type { WrapperRuleConfig, WrapperRuleLocalInvocation, WrapperRuleLocalOperand, WrapperRuleSubcommands, } from './rules/create-wrapper-rule.js';
26
- export type { WrapperSpec } from 'sh-ast/analyze';
26
+ export type { WrapperSpec } from 'sh-analysis';
27
27
  /**
28
28
  * The `@eslint-sh/eslint-plugin` plugin object, this package's default
29
29
  * export (`import sh from '@eslint-sh/eslint-plugin'`). `languages.sh` provides
@@ -22,7 +22,7 @@
22
22
  *
23
23
  * @see https://bats-core.readthedocs.io/en/stable/writing-tests.html
24
24
  */
25
- import type { WrapperSpec } from 'sh-ast/analyze';
25
+ import type { WrapperSpec } from 'sh-analysis';
26
26
  /**
27
27
  * Every helper function bats-core provides to test files.
28
28
  *
@@ -1,5 +1,5 @@
1
- import type { WrapperSpec } from 'sh-ast/analyze';
2
- import type { ShellCommandSite } from '../language/command-resolution.js';
1
+ import type { WrapperSpec } from 'sh-analysis';
2
+ import type { ShellCommandSite, ShellCommandUncertainty } from '../language/command-resolution.js';
3
3
  import type { ShellSourceCode } from '../language/shell-source-code.js';
4
4
  import type { ShellNode } from '../language/syntax-view.js';
5
5
  /**
@@ -10,7 +10,7 @@ import type { ShellNode } from '../language/syntax-view.js';
10
10
  export interface HarvestCommandsOptions {
11
11
  /**
12
12
  * The transparent-wrapper table to follow, forwarded to
13
- * `resolveInvokedCommand` unchanged. It **replaces** `sh-ast/analyze`'s
13
+ * `resolveInvokedCommand` unchanged. It **replaces** `sh-analysis`'s
14
14
  * `DEFAULT_TRANSPARENT_WRAPPERS` (spread the defaults in to extend them).
15
15
  * Defaults to `DEFAULT_TRANSPARENT_WRAPPERS`.
16
16
  */
@@ -34,6 +34,17 @@ export interface HarvestedCommand {
34
34
  /** The command site of that first use. */
35
35
  readonly site: ShellCommandSite;
36
36
  }
37
+ /**
38
+ * Observed external dependencies and execution boundaries retained from analysis.
39
+ * The map alone is deliberately insufficient to claim complete dependencies.
40
+ * @internal
41
+ */
42
+ export interface CommandHarvest {
43
+ /** Known static external commands, keyed by name in first-use order. */
44
+ readonly commands: ReadonlyMap<string, HarvestedCommand>;
45
+ /** Opaque syntax whose dependencies remain unknown. */
46
+ readonly uncertainties: readonly ShellCommandUncertainty[];
47
+ }
37
48
  /**
38
49
  * The names of every function the file defines, anywhere in it (top level,
39
50
  * nested in another function, inside a conditional, …). Position is not read,
@@ -46,7 +57,7 @@ export interface HarvestedCommand {
46
57
  */
47
58
  export declare function definedFunctionNames(sourceCode: ShellSourceCode): ReadonlySet<string>;
48
59
  /**
49
- * Returns every external command `sourceCode` runs, keyed by name, each with
60
+ * Returns known represented external commands `sourceCode` runs, keyed by name, each with
50
61
  * its first use. The map iterates in first-use (source) order.
51
62
  *
52
63
  * A command is every static word in an invocation's wrapper chain (the
@@ -56,11 +67,11 @@ export declare function definedFunctionNames(sourceCode: ShellSourceCode): Reado
56
67
  * - builtins of the file's dialect (`sourceCode.dialect`);
57
68
  * - functions the file defines anywhere.
58
69
  *
59
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
70
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when the file's
60
71
  * nesting exceeds analysis's recursion guard: a partial harvest would miss
61
72
  * real commands.
62
- * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
73
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
63
74
  * `options.transparentWrappers` contains a malformed entry.
64
75
  * @internal
65
76
  */
66
- export declare function harvestCommands(sourceCode: ShellSourceCode, options?: HarvestCommandsOptions): ReadonlyMap<string, HarvestedCommand>;
77
+ export declare function harvestCommands(sourceCode: ShellSourceCode, options?: HarvestCommandsOptions): CommandHarvest;
@@ -6,8 +6,8 @@
6
6
  * the shell's builtins and minus functions the file defines itself, following
7
7
  * transparent wrappers so that `sudo curl …` uses both `sudo` and `curl`.
8
8
  *
9
- * Every fact comes from `sh-ast/analyze` through the `ShellSourceCode`
10
- * helpers. `getCommandSites` supplies every command in the file, wherever it
9
+ * Every fact comes from `sh-analysis` through the `ShellSourceCode`
10
+ * helpers. The inventory supplies represented commands in the file, wherever it
11
11
  * is nested (function bodies, `$(…)` in arguments, assignment values,
12
12
  * redirect targets, loop lists, case subjects, …), and each site's
13
13
  * `resolveInvokedCommand` supplies the wrapper chain. Whether a word is
@@ -23,10 +23,11 @@
23
23
  * - Commands inside strings that another program runs (`bash -c '…'`,
24
24
  * `env -S '…'`). Those are text, not syntax.
25
25
  *
26
- * This module is internal. It is shaped to move, unchanged, into a public
27
- * analysis-services package later; until then rules in this package use it.
26
+ * This module owns ESLint dependency policy: builtin/function exclusion and
27
+ * first-use report nodes. Opaque analysis boundaries travel with the harvest;
28
+ * known observations do not prove exhaustive dependencies.
28
29
  */
29
- import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-ast/analyze';
30
+ import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
30
31
  import { walkShell } from '../language/syntax-view.js';
31
32
  import { builtinsForDialect } from './builtins/index.js';
32
33
  /**
@@ -60,7 +61,7 @@ function wordNodeAt(site, index) {
60
61
  return site.node.args[index] ?? site.node;
61
62
  }
62
63
  /**
63
- * Returns every external command `sourceCode` runs, keyed by name, each with
64
+ * Returns known represented external commands `sourceCode` runs, keyed by name, each with
64
65
  * its first use. The map iterates in first-use (source) order.
65
66
  *
66
67
  * A command is every static word in an invocation's wrapper chain (the
@@ -70,10 +71,10 @@ function wordNodeAt(site, index) {
70
71
  * - builtins of the file's dialect (`sourceCode.dialect`);
71
72
  * - functions the file defines anywhere.
72
73
  *
73
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
74
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when the file's
74
75
  * nesting exceeds analysis's recursion guard: a partial harvest would miss
75
76
  * real commands.
76
- * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
77
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
77
78
  * `options.transparentWrappers` contains a malformed entry.
78
79
  * @internal
79
80
  */
@@ -82,7 +83,7 @@ export function harvestCommands(sourceCode, options = {}) {
82
83
  const builtins = builtinsForDialect(sourceCode.dialect);
83
84
  const functions = definedFunctionNames(sourceCode);
84
85
  const harvested = new Map();
85
- for (const site of sourceCode.getCommandSites()) {
86
+ for (const site of sourceCode.getCommandInventory().commands) {
86
87
  const { chain, chainIndices } = site.resolveInvokedCommand({ transparentWrappers });
87
88
  for (const [position, word] of chain.entries()) {
88
89
  if (!word.static)
@@ -93,5 +94,5 @@ export function harvestCommands(sourceCode, options = {}) {
93
94
  harvested.set(name, { name, node: wordNodeAt(site, chainIndices[position]), site });
94
95
  }
95
96
  }
96
- return harvested;
97
+ return { commands: harvested, uncertainties: sourceCode.getCommandInventory().uncertainties };
97
98
  }
@@ -1,4 +1,4 @@
1
- import type { WrapperSpec } from 'sh-ast/analyze';
1
+ import type { WrapperSpec } from 'sh-analysis';
2
2
  import type { ShellDialect } from '../language/shell-language-options.js';
3
3
  /**
4
4
  * Returns the built-in harvest scope for a dialect, including bats' in-process
@@ -3,7 +3,7 @@
3
3
  * Both declaration rules compose this dialect scope with the shared project
4
4
  * facts through resolveTransparentWrappers, so they compute the same usage.
5
5
  */
6
- import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-ast/analyze';
6
+ import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
7
7
  import { BATS_RUN_WRAPPER } from './builtins/bats.js';
8
8
  /** Wrappers a dialect runtime provides beyond sh-ast's defaults. */
9
9
  const DIALECT_WRAPPERS = {
@@ -1,5 +1,6 @@
1
- import { Argv0Resolution } from 'sh-ast/analyze';
2
- import { CommandContext } from 'sh-ast/analyze';
1
+ import { Argv0Resolution } from 'sh-analysis';
2
+ import { CommandContext } from 'sh-analysis';
3
+ import type { CommandUncertainty } from 'sh-analysis';
3
4
  import type { ConfigObject } from '@eslint/core';
4
5
  import type { Directive } from '@eslint/core';
5
6
  import type { Expansion } from 'sh-ast';
@@ -11,8 +12,8 @@ import type { OkParseResult } from '@eslint/core';
11
12
  import type { ParseResult } from '@eslint/core';
12
13
  import type { PrintOptions } from 'sh-ast';
13
14
  import type { Replace } from 'sh-ast';
14
- import { ResolveArgv0Options } from 'sh-ast/analyze';
15
- import type { ResolveWordOptions } from 'sh-ast/analyze';
15
+ import { ResolveArgv0Options } from 'sh-analysis';
16
+ import type { ResolveWordOptions } from 'sh-analysis';
16
17
  import type { RuleContext } from '@eslint/core';
17
18
  import { RuleDefinition } from '@eslint/core';
18
19
  import { RuleDefinitionTypeOptions } from '@eslint/core';
@@ -26,8 +27,8 @@ import type { SourceLocation } from '@eslint/core';
26
27
  import type { SyntaxPos } from 'sh-ast';
27
28
  import { TextSourceCodeBase } from '@eslint/plugin-kit';
28
29
  import type { TraversalStep } from '@eslint/core';
29
- import { WordResolution } from 'sh-ast/analyze';
30
- import { WrapperSpec } from 'sh-ast/analyze';
30
+ import { WordResolution } from 'sh-analysis';
31
+ import { WrapperSpec } from 'sh-analysis';
31
32
 
32
33
  export { Argv0Resolution }
33
34
 
@@ -84,7 +85,7 @@ export declare const commentPragma: Readonly<Required<DeclarationConvention>>;
84
85
  * naming the command and the wrapper. Its `meta.docs.url` and
85
86
  * `meta.docs.description` default to this package's wrapper-rules page and a
86
87
  * sentence naming the policy; `config.docs` overrides either. A listed
87
- * command is wrapped when the wrapper encloses it in `sh-ast/analyze`'s
88
+ * command is wrapped when the wrapper encloses it in `sh-analysis`'s
88
89
  * transparent-wrapper chain, so `audit-run sudo kubectl apply` is wrapped.
89
90
  * Command and wrapper words written as paths match by basename
90
91
  * (`/usr/bin/kubectl`). Commands inside `$(…)`, functions, and pipelines are
@@ -474,17 +475,29 @@ export declare interface ScriptDeclaredCommand {
474
475
  readonly range: readonly [number, number];
475
476
  }
476
477
 
478
+ /**
479
+ * Represented commands and opaque execution boundaries in one linted file.
480
+ * Consumers requiring complete execution knowledge must consider uncertainties.
481
+ * @public
482
+ */
483
+ export declare interface ShellCommandInventory {
484
+ /** Known represented command sites, in source order. */
485
+ readonly commands: readonly ShellCommandSite[];
486
+ /** Opaque constructs whose executable contents cannot be enumerated. */
487
+ readonly uncertainties: readonly ShellCommandUncertainty[];
488
+ }
489
+
477
490
  /**
478
491
  * One command invocation in a linted shell file, in lint-view terms: an
479
- * `sh-ast/analyze` `CommandSite` whose `node` is the `CallExpr` view node
492
+ * `sh-analysis` `CommandSite` whose `node` is the `CallExpr` view node
480
493
  * ESLint passes to rule visitors, so a rule can `context.report()` on it.
481
494
  *
482
- * The data comes from `sh-ast/analyze`'s `enumerateCommands` and is facts
495
+ * The data comes from `sh-analysis`'s `enumerateCommands` and is facts
483
496
  * only: how the command is reached and what its words resolve to, never a
484
497
  * verdict on whether running it is safe. A dynamic (`static: false`) `argv0`
485
498
  * is a normal result.
486
499
  *
487
- * Read one through `ShellSourceCode.getCommandSites()`.
500
+ * Read one through `ShellSourceCode.getCommandInventory().commands`.
488
501
  *
489
502
  * Every rule linting a file sees the same sites, so each one is deeply
490
503
  * frozen: the entry, its `context` array and every frame in it, its `argv`
@@ -505,7 +518,7 @@ export declare interface ShellCommandSite {
505
518
  readonly node: ShellNodeOf<'CallExpr'>;
506
519
  /**
507
520
  * The path from the file root to this command, outermost frame first,
508
- * exactly as `sh-ast/analyze` reports it. For example, `date` in
521
+ * exactly as `sh-analysis` reports it. For example, `date` in
509
522
  * `f() { echo "$(date)"; }` has
510
523
  * `[{ kind: 'function', name: 'f' }, { kind: 'cmdSubst' }]`.
511
524
  */
@@ -520,24 +533,38 @@ export declare interface ShellCommandSite {
520
533
  readonly argv: readonly WordResolution[];
521
534
  /**
522
535
  * Follows this command's argv0 through transparent wrappers (`env`, `sudo`,
523
- * `nohup`, `exec`, …) and returns `sh-ast/analyze`'s `resolveArgv0`
536
+ * `nohup`, `exec`, …) and returns `sh-analysis`'s `resolveArgv0`
524
537
  * result. Same answer as
525
538
  * `ShellSourceCode.resolveInvokedCommand(node, options)`; both read the
526
539
  * same per-file index.
527
540
  *
528
541
  * @param options - Forwarded to `resolveArgv0` unchanged.
529
- * `transparentWrappers` replaces `sh-ast/analyze`'s
542
+ * `transparentWrappers` replaces `sh-analysis`'s
530
543
  * `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
531
544
  * extend them instead.
532
545
  * @returns A new result on every call. Its `chain` and `chainIndices`
533
546
  * arrays belong to the caller. `chainIndices` gives each chain entry's
534
547
  * position in this site's `argv`.
535
- * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
548
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
536
549
  * `options.transparentWrappers` contains a malformed entry.
537
550
  */
538
551
  resolveInvokedCommand(options?: ResolveArgv0Options): Argv0Resolution;
539
552
  }
540
553
 
554
+ /**
555
+ * An opaque executable construct projected onto the original ESLint view.
556
+ * Its presence limits inventory completeness; it does not assert a hidden command.
557
+ * @public
558
+ */
559
+ export declare interface ShellCommandUncertainty {
560
+ /** The analysis observation, without a lint-policy interpretation. */
561
+ readonly reason: CommandUncertainty['reason'];
562
+ /** Original projected construct, with this file's UTF-16 range and location. */
563
+ readonly node: ShellNode;
564
+ /** Context reaching the opaque construct, outermost frame first. */
565
+ readonly context: readonly CommandContext[];
566
+ }
567
+
541
568
  /** Directive processing uses the comment text without its leading shell hash. @public */
542
569
  export declare type ShellComment = ShellNodeOf<'Comment'>;
543
570
 
@@ -938,10 +965,10 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
938
965
  * from `context.sourceCode`; its constructor is internal language plumbing.
939
966
  *
940
967
  * Rule-author helpers (`resolveWord`, `resolveWordText`, `getCommandName`,
941
- * `resolveInvokedCommand`, `getCommandSites`) answer "is this word statically
968
+ * `resolveInvokedCommand`, `getCommandInventory`) answer "is this word statically
942
969
  * the string `jq`?", "which command does this invocation run?", and "which
943
970
  * commands does this file run, and where?" by delegating to
944
- * `sh-ast/analyze`. They never reinterpret words themselves, so every rule
971
+ * `sh-analysis`. They never reinterpret words themselves, so every rule
945
972
  * gets the same answer for the same syntax. `dialect` and `minBashVersion`
946
973
  * expose the file's normalized language options.
947
974
  *
@@ -1017,7 +1044,7 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
1017
1044
  }): number;
1018
1045
  /**
1019
1046
  * Resolves a lint-view word using its original syntax and grammar position.
1020
- * `sh-ast/analyze` owns static-word interpretation and dynamic reasons; this
1047
+ * `sh-analysis` owns static-word interpretation and dynamic reasons; this
1021
1048
  * method supplies the lint tree's position-based policy, without executing shell.
1022
1049
  *
1023
1050
  * Without explicit options, `CallExpr.args` use command-argument context, so
@@ -1035,7 +1062,7 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
1035
1062
  /**
1036
1063
  * The text-only form of {@link ShellSourceCode.resolveWord}: returns its text
1037
1064
  * exactly when static, otherwise `null`. Both methods share one policy path
1038
- * through `sh-ast/analyze`.
1065
+ * through `sh-analysis`.
1039
1066
  *
1040
1067
  * @param word - A parsed Word from the lint view.
1041
1068
  * @param options - Explicit analysis policy overriding grammar defaults.
@@ -1051,7 +1078,7 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
1051
1078
  * {@link ShellSourceCode.resolveInvokedCommand} for the command a wrapper
1052
1079
  * chain actually runs.
1053
1080
  *
1054
- * Delegates to `sh-ast/analyze`: the answer is the `argv0` resolution of the
1081
+ * Delegates to `sh-analysis`: the answer is the `argv0` resolution of the
1055
1082
  * `CommandSite` that `enumerateCommands` reports for this `CallExpr` in this
1056
1083
  * file. Leading `VAR=val` assignments are not part of argv, so
1057
1084
  * `FOO=1 jq .` yields `"jq"`. An assignment-only statement (`FOO=1`) has no
@@ -1060,14 +1087,14 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
1060
1087
  * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
1061
1088
  * @returns The command word's static text, or `null`.
1062
1089
  * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
1063
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
1090
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
1064
1091
  * nesting exceeds analysis's recursion guard; see
1065
1092
  * {@link ShellSourceCode.resolveInvokedCommand}.
1066
1093
  */
1067
1094
  getCommandName(callExpr: ShellNodeOf<'CallExpr'>): string | null;
1068
1095
  /**
1069
1096
  * Follows `callExpr`'s argv0 through transparent wrappers (`env`, `sudo`,
1070
- * `nohup`, `exec`, …) and returns `sh-ast/analyze`'s full `resolveArgv0`
1097
+ * `nohup`, `exec`, …) and returns `sh-analysis`'s full `resolveArgv0`
1071
1098
  * result, or `null` for a `CallExpr` that has no `CommandSite` (an
1072
1099
  * assignment-only statement such as `FOO=1`).
1073
1100
  *
@@ -1081,7 +1108,7 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
1081
1108
  * `embedded-command`; `chain`
1082
1109
  * lists every word resolved along the way, outermost wrapper first, and
1083
1110
  * `chainIndices` gives each entry's position in the command's `argv` (as
1084
- * {@link ShellSourceCode.getCommandSites} reports it). When `effective` is
1111
+ * {@link ShellSourceCode.getCommandInventory} reports it). When `effective` is
1085
1112
  * static, the effective command's arguments are
1086
1113
  * `argv.slice(chainIndices.at(-1)! + 1)`: every entry after the effective
1087
1114
  * command's own index. For an interpreter command string the final chain
@@ -1099,49 +1126,32 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
1099
1126
  *
1100
1127
  * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
1101
1128
  * @param options - Forwarded to `resolveArgv0` unchanged.
1102
- * `transparentWrappers` replaces `sh-ast/analyze`'s
1129
+ * `transparentWrappers` replaces `sh-analysis`'s
1103
1130
  * `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
1104
1131
  * extend them instead.
1105
1132
  * @returns The resolution, or `null` when `callExpr` invokes no command.
1106
1133
  * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
1107
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
1134
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
1108
1135
  * nesting exceeds analysis's recursion guard.
1109
- * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
1136
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
1110
1137
  * `options.transparentWrappers` contains a malformed entry.
1111
1138
  */
1112
1139
  resolveInvokedCommand(callExpr: ShellNodeOf<'CallExpr'>, options?: ResolveArgv0Options): Argv0Resolution | null;
1113
1140
  /**
1114
- * Returns every command invocation in this file, one entry per
1115
- * `sh-ast/analyze` `CommandSite`, in source order. Use it when a rule needs
1116
- * the whole file's commands with their structural context, such as every
1117
- * command inside a function or inside `$(…)`, instead of visiting
1118
- * `CallExpr` nodes one by one.
1141
+ * Returns represented command sites and explicit opaque execution boundaries.
1142
+ * Both retain original node identity in this file's UTF-16 ESLint view. This
1143
+ * adapter maps sh-analysis observations without parsing text or choosing policy.
1119
1144
  *
1120
- * The data comes from `sh-ast/analyze`'s `enumerateCommands`: facts about
1121
- * how each command is reached and what its words resolve to, never a
1122
- * verdict. Each entry's `context`, `argv0`, and `argv` are analysis's own
1123
- * values, unchanged; `context` lists frames outermost first, as in sh-ast.
1124
- * Each entry's `node` is the `CallExpr` view node (`===` the node ESLint
1125
- * passes to a `CallExpr` visitor), so it can be passed to
1126
- * `context.report()`.
1145
+ * The inventory and observation data are frozen and shared across rules; view
1146
+ * nodes retain ESLint's ordinary mutable-node contract. Enumeration runs once,
1147
+ * lazily, shared with getCommandName and resolveInvokedCommand. Analysis errors
1148
+ * propagate unchanged rather than returning a partial inventory.
1127
1149
  *
1128
- * An assignment-only statement (`FOO=1`) runs no command and has no entry,
1129
- * although a command substitution in its value (`FOO=$(date)`) does.
1130
- *
1131
- * Enumeration runs at most once per file, shared with
1132
- * {@link ShellSourceCode.getCommandName} and
1133
- * {@link ShellSourceCode.resolveInvokedCommand}, and every call returns the
1134
- * same array. Because every rule shares it, the array and everything in each
1135
- * entry except `node` are deeply frozen (see `ShellCommandSite`): no rule can
1136
- * change what another rule reads. If the file's nesting exceeds `enumerateCommands`'s
1137
- * recursion guard, its `ShAnalyzeMaxDepthError` propagates unchanged, as it
1138
- * does for those helpers: a partial list would silently omit real commands.
1139
- *
1140
- * @returns This file's command sites, in source order.
1141
- * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
1142
- * nesting exceeds analysis's recursion guard.
1150
+ * A known-command policy may inspect `commands`; any assertion of execution
1151
+ * completeness must also account for `uncertainties` and its own dynamic-code
1152
+ * assumptions. Empty commands with nonempty uncertainties never proves no execution.
1143
1153
  */
1144
- getCommandSites(): readonly ShellCommandSite[];
1154
+ getCommandInventory(): ShellCommandInventory;
1145
1155
  /**
1146
1156
  * Returns the sh-ast record `node` was projected from: this file's original
1147
1157
  * parse of `node`, with every field the lint view leaves out, including
@@ -1149,7 +1159,7 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
1149
1159
  * `Redirect.OpPos`. Pass those positions to
1150
1160
  * {@link ShellSourceCode.getIndexFromSyntaxPos} or
1151
1161
  * {@link ShellSourceCode.getLocFromSyntaxPos} to report on them, or pass the
1152
- * record to an `sh-ast/analyze` function.
1162
+ * record to an `sh-analysis` function.
1153
1163
  *
1154
1164
  * The returned record is read-only by contract. It is the language's
1155
1165
  * original parse, shared by every rule and helper linting this file, and
@@ -1190,11 +1200,12 @@ export declare interface ShellRuleVisitor extends ShellTypedListeners {
1190
1200
  * was parsed from: the first half of a printed fix. Edit the copy, then pass
1191
1201
  * it to {@link ShellSourceCode.getPrintedReplacement}.
1192
1202
  *
1193
- * The copy is `structuredClone` of the record
1194
- * {@link ShellSourceCode.getSyntax} returns. sh-ast documents and tests
1195
- * ordinary `structuredClone` as the supported way to make an independent
1196
- * editable copy of a syntax subtree (sh-ast 0.7.0 README, "Editing and
1197
- * printing"), so no second parse is involved. The copy owns its records,
1203
+ * The copy is what `structuredClone` of the record
1204
+ * {@link ShellSourceCode.getSyntax} returns would be, which sh-ast documents
1205
+ * and tests as the supported way to make an independent editable copy of a
1206
+ * syntax subtree (sh-ast 0.7.0 README, "Editing and printing"), so no second
1207
+ * parse is involved. It is made without recursion per tree level, so a
1208
+ * subtree of any depth can be copied. The copy owns its records,
1198
1209
  * arrays, positions and byte buffers. Editing it leaves this file's original
1199
1210
  * syntax, its lint view, its cached traversal and the answers of view-aware
1200
1211
  * helpers such as {@link ShellSourceCode.resolveWord} and
@@ -1408,7 +1419,7 @@ export declare interface WrapperRuleConfig {
1408
1419
  /**
1409
1420
  * The wrapper the commands must be run through. A string names a wrapper
1410
1421
  * that takes no options of its own (`retry curl x`), unless it names one of
1411
- * `sh-ast/analyze`'s default transparent wrappers (`timeout`, `nice`, …),
1422
+ * `sh-analysis`'s default transparent wrappers (`timeout`, `nice`, …),
1412
1423
  * whose known option shape is used. A `WrapperSpec` declares the wrapper's
1413
1424
  * option shape, so that `retry -n 3 curl x` is recognized as `curl` run
1414
1425
  * through `retry`; any of its `names` counts as the wrapper. Like