@eslint-sh/eslint-plugin 0.7.0 → 0.9.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 (182) hide show
  1. package/README.md +53 -40
  2. package/dist/api.d.ts +92 -0
  3. package/dist/api.js +83 -0
  4. package/dist/command-harvest/builtins/bash.d.ts +1 -1
  5. package/dist/command-harvest/builtins/bash.js +1 -1
  6. package/dist/command-harvest/builtins/bats.d.ts +2 -0
  7. package/dist/command-harvest/builtins/bats.js +3 -0
  8. package/dist/command-harvest/harvest-commands.d.ts +2 -2
  9. package/dist/command-harvest/harvest-commands.js +2 -2
  10. package/dist/command-harvest/wrapper-table.d.ts +3 -19
  11. package/dist/command-harvest/wrapper-table.js +8 -38
  12. package/dist/configs/bash-3-2.d.ts +7 -6
  13. package/dist/configs/bash-3-2.js +4 -3
  14. package/dist/configs/posix-portable.d.ts +7 -11
  15. package/dist/configs/posix-portable.js +4 -6
  16. package/dist/configuration-message.d.ts +14 -0
  17. package/dist/configuration-message.js +33 -0
  18. package/dist/declaration-conventions/get-declared-commands.d.ts +41 -0
  19. package/dist/declaration-conventions/{read-declared-commands.js → get-declared-commands.js} +43 -43
  20. package/dist/eslint-plugin-api.d.ts +1506 -0
  21. package/dist/eslint-plugin-syntax-analyze.d.ts +3 -3
  22. package/dist/eslint-plugin-syntax.d.ts +7 -4
  23. package/dist/eslint-plugin.d.ts +16 -1514
  24. package/dist/index.d.ts +14 -78
  25. package/dist/index.js +22 -74
  26. package/dist/language/command-resolution.d.ts +5 -5
  27. package/dist/language/command-resolution.js +11 -7
  28. package/dist/language/selector-classes.d.ts +7 -3
  29. package/dist/language/selector-classes.js +13 -4
  30. package/dist/language/shell-language-options.d.ts +21 -18
  31. package/dist/language/shell-language-options.js +41 -39
  32. package/dist/language/shell-language.d.ts +13 -10
  33. package/dist/language/shell-language.js +23 -45
  34. package/dist/language/shell-source-code.d.ts +74 -49
  35. package/dist/language/shell-source-code.js +135 -68
  36. package/dist/language/source-coordinates.d.ts +2 -0
  37. package/dist/language/source-coordinates.js +8 -4
  38. package/dist/language/syntax-view.js +19 -7
  39. package/dist/language/word-resolution.d.ts +2 -1
  40. package/dist/language/word-resolution.js +8 -3
  41. package/dist/rules/bash-variable-semantics.d.ts +22 -0
  42. package/dist/rules/bash-variable-semantics.js +41 -0
  43. package/dist/rules/compat/create-compat-rule.js +1 -1
  44. package/dist/rules/compat/declaration-options.d.ts +2 -2
  45. package/dist/rules/compat/declaration-options.js +5 -2
  46. package/dist/rules/compat/no-append-all-redirect.js +1 -1
  47. package/dist/rules/compat/no-associative-arrays.js +2 -2
  48. package/dist/rules/compat/no-brace-sequence-padding-step.js +4 -4
  49. package/dist/rules/compat/no-case-attributes.js +3 -3
  50. package/dist/rules/compat/no-case-fallthrough.js +2 -2
  51. package/dist/rules/compat/no-case-modification.js +2 -2
  52. package/dist/rules/compat/no-coproc.js +1 -1
  53. package/dist/rules/compat/no-declare-g.js +3 -3
  54. package/dist/rules/compat/no-double-bracket.js +2 -2
  55. package/dist/rules/compat/no-epoch-variables.js +2 -2
  56. package/dist/rules/compat/no-fd-variable.js +1 -1
  57. package/dist/rules/compat/no-globstar.js +1 -1
  58. package/dist/rules/compat/no-lastpipe-semantics.js +2 -2
  59. package/dist/rules/compat/no-let.js +2 -1
  60. package/dist/rules/compat/no-mapfile.js +4 -2
  61. package/dist/rules/compat/no-nameref.js +3 -3
  62. package/dist/rules/compat/no-negative-array-index.js +39 -9
  63. package/dist/rules/compat/no-nounset-empty-array.js +15 -4
  64. package/dist/rules/compat/no-parameter-transformation.js +2 -2
  65. package/dist/rules/compat/no-pipe-all.js +1 -1
  66. package/dist/rules/compat/no-printf-time-format.js +4 -2
  67. package/dist/rules/compat/no-source.js +2 -1
  68. package/dist/rules/compat/no-test-v.js +4 -2
  69. package/dist/rules/compat/no-unicode-escape.js +2 -2
  70. package/dist/rules/compat/no-wait-n.js +4 -2
  71. package/dist/rules/compat/nounset-array-proof.d.ts +8 -0
  72. package/dist/rules/compat/nounset-array-proof.js +563 -0
  73. package/dist/rules/compat/posix-absent-command.d.ts +7 -8
  74. package/dist/rules/compat/posix-absent-command.js +17 -15
  75. package/dist/rules/compat/shopt-options.js +3 -1
  76. package/dist/rules/compat/version-gates.d.ts +9 -9
  77. package/dist/rules/compat/version-gates.js +13 -13
  78. package/dist/rules/create-wrapper-rule.d.ts +1 -1
  79. package/dist/rules/create-wrapper-rule.js +23 -16
  80. package/dist/rules/define-shell-rule.js +1 -1
  81. package/dist/rules/no-dynamic-invocation.d.ts +0 -8
  82. package/dist/rules/no-dynamic-invocation.js +7 -15
  83. package/dist/rules/no-eval.js +3 -1
  84. package/dist/rules/no-masked-exit-status.d.ts +4 -3
  85. package/dist/rules/no-masked-exit-status.js +18 -10
  86. package/dist/rules/no-secret-env-reads.d.ts +6 -3
  87. package/dist/rules/no-secret-env-reads.js +49 -15
  88. package/dist/rules/no-secret-flags.d.ts +4 -1
  89. package/dist/rules/no-secret-flags.js +21 -11
  90. package/dist/rules/no-unchecked-cd.js +6 -3
  91. package/dist/rules/no-undeclared-commands.d.ts +1 -15
  92. package/dist/rules/no-undeclared-commands.js +11 -18
  93. package/dist/rules/no-unused-declarations.d.ts +1 -18
  94. package/dist/rules/no-unused-declarations.js +15 -36
  95. package/dist/rules/prefer-local.d.ts +3 -2
  96. package/dist/rules/prefer-local.js +7 -4
  97. package/dist/rules/quote-expansions.js +3 -28
  98. package/dist/rules/require-network-wrapper.d.ts +3 -18
  99. package/dist/rules/require-network-wrapper.js +43 -10
  100. package/dist/rules/require-strict-mode.d.ts +5 -46
  101. package/dist/rules/require-strict-mode.js +17 -107
  102. package/dist/rules/require-tty-guard.d.ts +2 -0
  103. package/dist/rules/require-tty-guard.js +8 -1
  104. package/dist/rules/resolve-declaration-convention.d.ts +9 -89
  105. package/dist/rules/resolve-declaration-convention.js +19 -72
  106. package/dist/rules/resolve-network-wrapper.d.ts +20 -2
  107. package/dist/rules/resolve-network-wrapper.js +71 -36
  108. package/dist/rules/resolve-transparent-wrappers.d.ts +38 -0
  109. package/dist/rules/resolve-transparent-wrappers.js +108 -0
  110. package/dist/rules/set-options.d.ts +3 -2
  111. package/dist/rules/set-options.js +18 -6
  112. package/dist/rules/shebang-interpreter.js +4 -2
  113. package/dist/rules/strict-mode-prologue.d.ts +43 -0
  114. package/dist/rules/strict-mode-prologue.js +91 -0
  115. package/dist/rules/transparent-wrappers.d.ts +4 -3
  116. package/dist/rules/transparent-wrappers.js +5 -4
  117. package/dist/rules/user-pattern.d.ts +9 -6
  118. package/dist/rules/user-pattern.js +16 -12
  119. package/dist/shell-dialect.d.ts +8 -0
  120. package/dist/shell-dialect.js +22 -0
  121. package/dist/syntax/analyze.d.ts +3 -3
  122. package/dist/syntax/analyze.js +3 -3
  123. package/dist/syntax/index.d.ts +7 -4
  124. package/dist/syntax/index.js +7 -4
  125. package/dist/version.js +2 -1
  126. package/docs/compat.md +81 -33
  127. package/docs/custom-rule-tutorial.md +31 -21
  128. package/docs/declaration-conventions.md +20 -23
  129. package/docs/error-codes.md +93 -0
  130. package/docs/examples/no-listed-commands-rule.ts +2 -2
  131. package/docs/examples/no-rm-rf-rule.mjs +8 -10
  132. package/docs/examples/sorted-declarations-rule.mjs +6 -9
  133. package/docs/examples/tsconfig.json +10 -0
  134. package/docs/rules/README.md +46 -6
  135. package/docs/rules/_template.md +2 -2
  136. package/docs/rules/compat/no-append-all-redirect.md +12 -12
  137. package/docs/rules/compat/no-associative-arrays.md +14 -14
  138. package/docs/rules/compat/no-brace-sequence-padding-step.md +12 -12
  139. package/docs/rules/compat/no-case-attributes.md +13 -13
  140. package/docs/rules/compat/no-case-fallthrough.md +12 -12
  141. package/docs/rules/compat/no-case-modification.md +11 -11
  142. package/docs/rules/compat/no-coproc.md +13 -13
  143. package/docs/rules/compat/no-declare-g.md +13 -13
  144. package/docs/rules/compat/no-double-bracket.md +2 -2
  145. package/docs/rules/compat/no-epoch-variables.md +13 -13
  146. package/docs/rules/compat/no-fd-variable.md +12 -12
  147. package/docs/rules/compat/no-globstar.md +13 -13
  148. package/docs/rules/compat/no-lastpipe-semantics.md +13 -13
  149. package/docs/rules/compat/no-let.md +2 -2
  150. package/docs/rules/compat/no-mapfile.md +16 -16
  151. package/docs/rules/compat/no-nameref.md +13 -13
  152. package/docs/rules/compat/no-negative-array-index.md +14 -14
  153. package/docs/rules/compat/no-nounset-empty-array.md +72 -17
  154. package/docs/rules/compat/no-parameter-transformation.md +19 -19
  155. package/docs/rules/compat/no-pipe-all.md +13 -13
  156. package/docs/rules/compat/no-printf-time-format.md +13 -13
  157. package/docs/rules/compat/no-source.md +2 -2
  158. package/docs/rules/compat/no-test-v.md +12 -12
  159. package/docs/rules/compat/no-unicode-escape.md +13 -13
  160. package/docs/rules/compat/no-wait-n.md +13 -13
  161. package/docs/rules/no-dynamic-invocation.md +17 -12
  162. package/docs/rules/no-eval.md +6 -1
  163. package/docs/rules/no-masked-exit-status.md +6 -2
  164. package/docs/rules/no-secret-env-reads.md +46 -5
  165. package/docs/rules/no-secret-flags.md +32 -6
  166. package/docs/rules/no-unchecked-cd.md +22 -2
  167. package/docs/rules/no-undeclared-commands.md +16 -15
  168. package/docs/rules/no-unused-declarations.md +17 -20
  169. package/docs/rules/prefer-local.md +20 -2
  170. package/docs/rules/quote-expansions.md +8 -5
  171. package/docs/rules/require-network-wrapper.md +26 -21
  172. package/docs/rules/require-shebang.md +10 -4
  173. package/docs/rules/require-strict-mode.md +31 -23
  174. package/docs/rules/require-tty-guard.md +12 -3
  175. package/docs/selectors.md +7 -2
  176. package/docs/shellcheck.md +9 -5
  177. package/docs/transparent-wrappers.md +97 -0
  178. package/docs/wrapper-rules.md +11 -0
  179. package/package.json +3 -3
  180. package/dist/declaration-conventions/read-declared-commands.d.ts +0 -70
  181. package/dist/language/end-of-input-marker.d.ts +0 -29
  182. package/dist/language/end-of-input-marker.js +0 -88
@@ -0,0 +1,1506 @@
1
+ import { Argv0Resolution } from 'sh-ast/analyze';
2
+ import { CommandContext } from 'sh-ast/analyze';
3
+ import type { ConfigObject } from '@eslint/core';
4
+ import type { Directive } from '@eslint/core';
5
+ import type { Expansion } from 'sh-ast';
6
+ import type { File as File_2 } from '@eslint/core';
7
+ import type { FileProblem } from '@eslint/core';
8
+ import type { Language } from '@eslint/core';
9
+ import type { Node } from 'sh-ast';
10
+ import type { OkParseResult } from '@eslint/core';
11
+ import type { ParseResult } from '@eslint/core';
12
+ import type { PrintOptions } from 'sh-ast';
13
+ import type { Replace } from 'sh-ast';
14
+ import { ResolveArgv0Options } from 'sh-ast/analyze';
15
+ import type { ResolveWordOptions } from 'sh-ast/analyze';
16
+ import type { RuleContext } from '@eslint/core';
17
+ import { RuleDefinition } from '@eslint/core';
18
+ import { RuleDefinitionTypeOptions } from '@eslint/core';
19
+ import type { RulesConfig } from '@eslint/core';
20
+ import type { RulesMeta } from '@eslint/core';
21
+ import type { RuleTextEdit } from '@eslint/core';
22
+ import type { RuleTextEditor } from '@eslint/core';
23
+ import type { SettingsConfig } from '@eslint/core';
24
+ import type { Slice } from 'sh-ast';
25
+ import type { SourceLocation } from '@eslint/core';
26
+ import type { SyntaxPos } from 'sh-ast';
27
+ import { TextSourceCodeBase } from '@eslint/plugin-kit';
28
+ import type { TraversalStep } from '@eslint/core';
29
+ import { WordResolution } from 'sh-ast/analyze';
30
+ import { WrapperSpec } from 'sh-ast/analyze';
31
+
32
+ export { Argv0Resolution }
33
+
34
+ export { CommandContext }
35
+
36
+ /**
37
+ * The reference {@link DeclarationConvention}: a script declares the external
38
+ * commands it uses in `# uses:` comments in its header.
39
+ *
40
+ * ```sh
41
+ * #!/usr/bin/env bash
42
+ * # uses: jq curl
43
+ * # uses: git
44
+ * set -euo pipefail
45
+ * ```
46
+ *
47
+ * declares `jq`, `curl`, and `git`. The header is the run of blank and
48
+ * comment-only lines at the top of the file; a `# uses:` comment after the
49
+ * first command is not a declaration. Several pragma lines accumulate, names
50
+ * are whitespace-separated, and each declaration is `kind: 'script'` with a
51
+ * `range` that covers exactly that name. A word starting with `#` ends the list and begins a trailing
52
+ * remark: `# uses: jq # for json` declares only `jq`.
53
+ *
54
+ * Its `removeDeclaration` hook deletes one name and the whitespace that
55
+ * separated it, or the whole pragma line (with its `\n` or `\r\n`) when that
56
+ * name was the line's last.
57
+ *
58
+ * Its `declarationHint` hook tells a person exactly what to add: the line
59
+ * `# uses: curl`, on a line below the shebang, or as the first line of the
60
+ * file when there is no shebang. A name a pragma cannot express (one with
61
+ * whitespace, or starting with `#`) gets no hint.
62
+ *
63
+ * Bind it with `settings: { sh: { declarationConvention: commentPragma } }`.
64
+ *
65
+ * @public
66
+ */
67
+ export declare const commentPragma: Readonly<Required<DeclarationConvention>>;
68
+
69
+ /**
70
+ * Creates a rule that reports every listed command that is not run through
71
+ * `config.wrapper`, for a rule pack's "must be wrapped by X" policies:
72
+ *
73
+ * ```js
74
+ * import { createWrapperRule } from '@eslint-sh/eslint-plugin';
75
+ *
76
+ * export const requireAudit = createWrapperRule({
77
+ * commands: ['kubectl', 'terraform'],
78
+ * wrapper: 'audit-run',
79
+ * });
80
+ * ```
81
+ *
82
+ * The rule declares `meta.languages: ["sh/sh"]`, takes no options (the
83
+ * config is bound here), and reports with message id `unwrappedCommand`,
84
+ * naming the command and the wrapper. Its `meta.docs.url` and
85
+ * `meta.docs.description` default to this package's wrapper-rules page and a
86
+ * 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
+ * transparent-wrapper chain, so `audit-run sudo kubectl apply` is wrapped.
89
+ * Command and wrapper words written as paths match by basename
90
+ * (`/usr/bin/kubectl`). Commands inside `$(…)`, functions, and pipelines are
91
+ * checked; a command whose name or subcommand is not static is not reported.
92
+ *
93
+ * @param config - The commands, the wrapper they must be run through, any
94
+ * subcommand restrictions, and optional `meta.docs` overrides.
95
+ * @returns A {@link ShellRule}: an ESLint rule for the `sh/sh` language,
96
+ * typed so a pack's own declarations need no `@eslint/core` import to name it.
97
+ * @throws TypeError with `ESLINT_SH_WRAPPER_CONFIG` when `config` is malformed (no `commands` array, an empty
98
+ * wrapper name, a subcommand restriction without `names`, or an empty or
99
+ * non-string `docs.url` / `docs.description`).
100
+ *
101
+ * @public
102
+ */
103
+ export declare function createWrapperRule(config: WrapperRuleConfig): ShellRule<[], 'unwrappedCommand'>;
104
+
105
+ /**
106
+ * How a project declares the external commands its shell scripts depend on.
107
+ *
108
+ * Implement this to teach the plugin a project's own declaration syntax, then
109
+ * bind it with `settings: { sh: { declarationConvention: myConvention } }`.
110
+ * Until a convention is bound, rules that consume one report nothing.
111
+ *
112
+ * Bind it through `settings`, not through a rule's options: ESLint copies
113
+ * rule options with `structuredClone`, which cannot copy functions. Define it
114
+ * as a plain object whose methods are its own properties, and bind it in one
115
+ * config entry: when two matching config entries both set it, ESLint merges
116
+ * the two objects property by property, which drops methods inherited from a
117
+ * class prototype and can mix methods from two different conventions.
118
+ *
119
+ * One convention object serves every file its config entry matches, so its
120
+ * answer must depend only on its arguments and on data it holds, never on
121
+ * which file it saw before. ESLint's `--cache` sees a convention's own
122
+ * enumerable data properties (they are part of the config it hashes) but not
123
+ * files the convention reads while linting.
124
+ *
125
+ * {@link commentPragma} is the reference implementation.
126
+ *
127
+ * @public
128
+ */
129
+ export declare interface DeclarationConvention {
130
+ /**
131
+ * Returns every command the linted file declares, in source order. A name
132
+ * declared twice appears twice, each with its own source. `file` names the
133
+ * file being linted, for a convention whose declarations live beside it;
134
+ * a convention that reads only `sourceCode` can leave it out.
135
+ */
136
+ declaredCommands(sourceCode: ShellSourceCode, file: LintedFile): DeclaredCommand[];
137
+ /**
138
+ * Optional edit hook: returns the fix that deletes the single stale
139
+ * declaration `declared` (an in-script entry previously returned by
140
+ * {@link DeclarationConvention.declaredCommands} for the same
141
+ * `sourceCode`), built with the rule's `fixer`. Returns `null` when that
142
+ * declaration cannot be removed safely.
143
+ *
144
+ * It is only ever called with a {@link ScriptDeclaredCommand}: a fix edits
145
+ * only the linted script, and no edit to the script removes a declaration
146
+ * kept anywhere else.
147
+ *
148
+ * A convention without this hook still reports stale declarations; those
149
+ * reports simply carry no autofix.
150
+ */
151
+ removeDeclaration?(sourceCode: ShellSourceCode, declared: ScriptDeclaredCommand, fixer: RuleTextEditor): RuleTextEdit | RuleTextEdit[] | null;
152
+ /**
153
+ * Optional hint hook: returns one short sentence that tells a person how to
154
+ * declare `command`, with text they can copy. {@link commentPragma}'s hint says to
155
+ * add `# uses: curl` on a line below the shebang.
156
+ * `sh/no-undeclared-commands` appends it to its report. Following the
157
+ * sentence literally must make that report go away.
158
+ *
159
+ * Return `null` when this convention cannot declare `command` as written
160
+ * (for example, a name its syntax cannot express). The report then falls
161
+ * back to a generic sentence, as it does for a convention without this
162
+ * hook. Anything other than `null` must be a non-empty single-line string.
163
+ */
164
+ declarationHint?(command: string, sourceCode: ShellSourceCode, file: LintedFile): string | null;
165
+ }
166
+
167
+ /**
168
+ * One command a script declares it depends on, as reported by a
169
+ * {@link DeclarationConvention}. Where the declaration lives is part of what
170
+ * it is, so it is one of three kinds, told apart by the required `kind`:
171
+ * written in the script ({@link ScriptDeclaredCommand}), in another file
172
+ * ({@link FileDeclaredCommand}), or in a source that can only be described in
173
+ * words ({@link DescribedDeclaredCommand}). Only the script kind has a `range`, so
174
+ * narrow on `kind` before reading it.
175
+ *
176
+ * @public
177
+ */
178
+ export declare type DeclaredCommand = ScriptDeclaredCommand | FileDeclaredCommand | DescribedDeclaredCommand;
179
+
180
+ /**
181
+ * Builds a shell rule from its spec, setting `meta.languages` to
182
+ * exactly `["sh/sh"]` so ESLint refuses to run the rule on any other language.
183
+ * Everything else in `meta`, and `create`, is kept as written; message ids
184
+ * and option types are inferred from `meta` or may be given explicitly
185
+ * (`defineShellRule<[], 'found'>(…)`).
186
+ *
187
+ * The language fields are written last, so a JavaScript caller that bypasses
188
+ * the types and supplies its own `languages` or `language` still gets
189
+ * exactly `["sh/sh"]` (and no `language`). A JavaScript caller that omits
190
+ * `meta`, which ESLint allows for a rule, is treated as having written
191
+ * `meta: {}`.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * import { defineShellRule } from '@eslint-sh/eslint-plugin';
196
+ *
197
+ * export const noEval = defineShellRule({
198
+ * meta: { type: 'problem', schema: [], messages: { evalUsed: 'Avoid eval.' } },
199
+ * create(context) {
200
+ * return {
201
+ * CallExpr(node) {
202
+ * if (context.sourceCode.getCommandName(node) === 'eval') {
203
+ * context.report({ node, messageId: 'evalUsed' });
204
+ * }
205
+ * },
206
+ * };
207
+ * },
208
+ * });
209
+ * ```
210
+ *
211
+ * @public
212
+ */
213
+ export declare function defineShellRule<RuleOptions extends unknown[] = [], MessageIds extends string = string>(spec: ShellRuleSpec<RuleOptions, MessageIds>): ShellRule<RuleOptions, MessageIds>;
214
+
215
+ /**
216
+ * A declaration whose source can only be described in words: there is no
217
+ * range in the script and no path to point at, only a phrase that tells a
218
+ * person where it comes from, such as a list written in the ESLint config, a
219
+ * convention's own constant, or a snapshot of a tool registry. A report about
220
+ * it names the source by `description` and carries no fix.
221
+ *
222
+ * @public
223
+ */
224
+ export declare interface DescribedDeclaredCommand {
225
+ /** Says the declaration's source is described in words, by `description`. */
226
+ readonly kind: 'described';
227
+ /** The declared command name, exactly as it would be invoked. */
228
+ readonly name: string;
229
+ /**
230
+ * Names the source for a person who wants to change the declaration, as a
231
+ * phrase that reads after "declared in": "the web image list in
232
+ * eslint.config.js", "the tool registry snapshot of 2026-11-01". It must be a
233
+ * non-empty single line.
234
+ */
235
+ readonly description: string;
236
+ }
237
+
238
+ /**
239
+ * A declaration written in a file other than the linted script: a per-script
240
+ * sidecar, or a manifest several scripts share. A report about it names the
241
+ * file, and carries no fix, since a fix can only edit the linted script.
242
+ *
243
+ * @public
244
+ */
245
+ export declare interface FileDeclaredCommand {
246
+ /** Says the declaration is in another file. */
247
+ readonly kind: 'file';
248
+ /** The declared command name, exactly as it would be invoked. */
249
+ readonly name: string;
250
+ /**
251
+ * Where a person or a tool should look for the declaration: a path
252
+ * relative to {@link LintedFile.cwd}, or an absolute path. It must be a
253
+ * non-empty single line. Rules name it in their reports as given; they never
254
+ * read it.
255
+ */
256
+ readonly path: string;
257
+ /** The 1-based line of `path` that declares the command, when the convention knows it. */
258
+ readonly line?: number;
259
+ }
260
+
261
+ /**
262
+ * Returns validated declarations for the linted file, or `null` when the project
263
+ * has no bound convention. An empty array means a convention is bound and the
264
+ * file declares no commands; consumers must preserve that distinction.
265
+ *
266
+ * The convention receives only a frozen {@link LintedFile}, never rule state.
267
+ * Invalid bindings, output arrays, declaration kinds, provenance or UTF-16 ranges
268
+ * throw an error naming the shared setting before a rule can trust the result.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * File() {
273
+ * const declarations = getDeclaredCommands(context);
274
+ * if (declarations === null) return;
275
+ * for (const declared of declarations) {
276
+ * // Each declaration has been checked against its kind's contract.
277
+ * }
278
+ * }
279
+ * ```
280
+ *
281
+ * @throws Error with `ESLINT_SH_DECLARATION_CONVENTION` for invalid shared bindings, or
282
+ * `ESLINT_SH_DECLARATION_OUTPUT` for invalid hook results.
283
+ * Exceptions thrown by the convention itself pass through unchanged, including their causes.
284
+ * @public
285
+ */
286
+ export declare function getDeclaredCommands(context: LintedFile & {
287
+ readonly sourceCode: ShellSourceCode;
288
+ readonly settings: SettingsConfig;
289
+ }): DeclaredCommand[] | null;
290
+
291
+ /**
292
+ * The file ESLint is linting, as its rule context names it. A
293
+ * {@link DeclarationConvention} receives it so it can find declarations kept
294
+ * outside the script, such as a per-script sidecar file next to it.
295
+ *
296
+ * A rule's own `context` is a `LintedFile`, so a rule that calls
297
+ * `declaredCommands` passes `context`.
298
+ *
299
+ * @public
300
+ */
301
+ export declare interface LintedFile {
302
+ /**
303
+ * The name ESLint lints the code under (`context.filename`). For a code
304
+ * block a processor extracts from another file it is virtual
305
+ * (`README.md/0_0.sh`).
306
+ */
307
+ readonly filename: string;
308
+ /**
309
+ * The path on disk ESLint associates with the code
310
+ * (`context.physicalFilename`): the file it read, or the file a
311
+ * processor's code block came from. With `--stdin --stdin-filename`, it is
312
+ * the name given on the command line; the code came from standard input,
313
+ * and that file may not exist. Resolve sidecar paths from this one, and
314
+ * treat a missing sidecar as a normal case.
315
+ */
316
+ readonly physicalFilename: string;
317
+ /**
318
+ * ESLint's working directory (`context.cwd`). A relative
319
+ * {@link FileDeclaredCommand.path} is relative to it.
320
+ */
321
+ readonly cwd: string;
322
+ }
323
+
324
+ /**
325
+ * The result of {@link ShellLanguage.normalizeLanguageOptions}: `dialect` and
326
+ * `directivePrefix` are always resolved to concrete values (defaulted when
327
+ * the caller didn't specify them), and `toJSON()` provides the "custom
328
+ * serialization" ESLint's languages guide recommends
329
+ * (https://eslint.org/docs/latest/extend/languages, "normalizeLanguageOptions")
330
+ * so that config caching keyed off `JSON.stringify(languageOptions)` is
331
+ * stable irrespective of the input object's own key order — `JSON.stringify`
332
+ * calls `toJSON()` automatically when present.
333
+ *
334
+ * @public
335
+ */
336
+ export declare interface NormalizedShellLanguageOptions extends Record<string, unknown> {
337
+ readonly dialect: ShellDialect;
338
+ readonly directivePrefix: string;
339
+ readonly minBashVersion?: string;
340
+ toJSON(): ShellLanguageOptionsJSON;
341
+ }
342
+
343
+ /**
344
+ * The `@eslint-sh/eslint-plugin` plugin object, this package's default
345
+ * export (`import sh from '@eslint-sh/eslint-plugin'`). `languages.sh` provides
346
+ * `ShellLanguage` / `ShellSourceCode`, selected in a flat config via
347
+ * `language: "sh/sh"` (`namespace: "sh"`). `meta.version` is read from this
348
+ * package's own `package.json` at runtime — never hardcoded (see
349
+ * `version.ts`).
350
+ *
351
+ * `rules` holds the plugin's built-in rules, each built with
352
+ * `defineShellRule` (so each declares `meta.languages: ["sh/sh"]`) and
353
+ * linking its docs page from `meta.docs.url`. Consumers can also supply their
354
+ * own rules, built with the same `defineShellRule`, while sharing parsing,
355
+ * selectors, source coordinates, and directive semantics.
356
+ *
357
+ * `configs.recommended` is the `sh/recommended` preset: a single config
358
+ * object carrying `plugins: { sh }` and `language: "sh/sh"` but no `files`,
359
+ * so it inherits the globs of the entry that extends it:
360
+ * `{ files: [...], extends: [sh.configs.recommended] }`. It enables the
361
+ * convention-free policy rules. The rules index at
362
+ * https://github.com/mike-north/eslint-sh/blob/main/packages/eslint-plugin/docs/rules/README.md
363
+ * describes preset membership and available autofixes.
364
+ * `configs['agent-authored']` is the strict `sh/agent-authored` preset for
365
+ * machine-written, human-reviewed scripts:
366
+ * every `recommended` rule plus the contract rules, all at `error`.
367
+ * `configs['bash-3.2']` and `configs['posix-portable']` are deployment-target
368
+ * packs: the first sets `languageOptions.minBashVersion: "3.2"` and enables
369
+ * the version-gated `compat/*` rules except the opt-in
370
+ * `compat/no-nounset-empty-array`; the second sets
371
+ * `languageOptions.dialect: "posix"`, enables the effective `compat/*` rules and the
372
+ * shebang/dialect check; it reports named constructs
373
+ * that fail on dash, not every non-POSIX construct, and leaves `local`,
374
+ * `echo -e` and the rest of shellcheck's SC3xxx catalog to shellcheck. Every
375
+ * shipped config is a
376
+ * single object with no `files`; the two packs also carry `languageOptions`,
377
+ * because the target they name is their meaning. Beyond plugin registration
378
+ * and naming, target packs contain only language, languageOptions, and rules
379
+ * whose findings depend on that target. The shebang check belongs because it
380
+ * compares the declared interpreter with the target dialect. Error-handling
381
+ * policy comes from composing recommended, whose POSIX default is `set -eu`.
382
+ * The Bash-only empty-array nounset check cannot report under POSIX and is
383
+ * omitted from posix-portable.
384
+ *
385
+ * Re-exported, unchanged, as the default export of the `eslint-sh` umbrella
386
+ * package: importing this package or the umbrella package both yield the
387
+ * same plugin object.
388
+ *
389
+ * @public
390
+ */
391
+ declare const plugin: {
392
+ meta: {
393
+ name: string;
394
+ version: string;
395
+ namespace: string;
396
+ };
397
+ languages: {
398
+ sh: ShellLanguage;
399
+ };
400
+ rules: Record<string, RuleDefinition<RuleDefinitionTypeOptions>>;
401
+ configs: {
402
+ recommended: ConfigObject;
403
+ "agent-authored": ConfigObject;
404
+ "bash-3.2": ConfigObject;
405
+ "posix-portable": ConfigObject;
406
+ };
407
+ };
408
+ export default plugin;
409
+
410
+ export { ResolveArgv0Options }
411
+
412
+ /**
413
+ * Returns the convention bound in `settings.sh.declarationConvention`, or `null`
414
+ * when absent. Present invalid values throw an error naming the shared setting.
415
+ *
416
+ * Use {@link getDeclaredCommands} to read validated declarations. This narrow
417
+ * resolver exists for consumers that also need a convention hook, such as
418
+ * `removeDeclaration`; it never exposes rule-specific binding policy.
419
+ *
420
+ * @throws Error with `ESLINT_SH_DECLARATION_CONVENTION` for malformed bindings or optional hooks.
421
+ * @public
422
+ */
423
+ export declare function resolveDeclarationConvention(context: {
424
+ readonly settings: SettingsConfig;
425
+ }): DeclarationConvention | null;
426
+
427
+ /**
428
+ * Returns the shared project wrappers followed by `builtIns` (defaults when
429
+ * omitted). Entries accept command names or JSON-expressible `WrapperSpec`s
430
+ * in `settings: { sh: { transparentWrappers: [...] } }`. The shared network
431
+ * wrapper is also transparent; conflicting specs for the same project name
432
+ * throw rather than allowing policies to disagree. Shared specs compare effective
433
+ * grammars for overlapping names, normalizing matcher defaults and retaining
434
+ * expanded built-in flag patterns; an extra transparent alias does not acquire
435
+ * network approval. Explicit specs remain complete replacements. Duplicate project
436
+ * names are rejected so list order cannot silently choose their meaning.
437
+ *
438
+ * Utility wrappers match absolute and relative paths by basename. Path words
439
+ * remain unchanged in analysis results. `shellBuiltin: true` entries match
440
+ * exact names only: an executable path cannot acquire in-process semantics.
441
+ * An explicit path spec takes precedence over a basename fallback regardless
442
+ * of configuration order.
443
+ * Aliases are built even when only `builtIns` are supplied. Overridden names
444
+ * are removed from lower-priority entries, preserving their unrelated aliases
445
+ * and preventing a utility entry from undoing an exact-name builtin override.
446
+ * The input tables are never mutated.
447
+ *
448
+ * @param context - The consuming rule's context.
449
+ * @param builtIns - The rule's own built-in wrapper scope.
450
+ * @throws Error with `ESLINT_SH_WRAPPER_SETTING` for malformed bindings, or
451
+ * `ESLINT_SH_WRAPPER_CONFLICT` for duplicate names or contradictory shared policies.
452
+ * @public
453
+ */
454
+ export declare function resolveTransparentWrappers(context: TransparentWrappersBindingContext, builtIns?: readonly WrapperSpec[]): readonly WrapperSpec[];
455
+
456
+ /**
457
+ * A declaration written in the linted script's own text: the only kind an
458
+ * ESLint fix can edit, because a fix edits only the file being linted.
459
+ *
460
+ * @public
461
+ */
462
+ export declare interface ScriptDeclaredCommand {
463
+ /** Says the declaration is in the script. */
464
+ readonly kind: 'script';
465
+ /** The declared command name, exactly as it would be invoked (`jq`, `docker-compose`). */
466
+ readonly name: string;
467
+ /**
468
+ * The `[start, end)` source range of this declaration, as UTF-16 offsets
469
+ * into `sourceCode.text` (the same coordinates as every node's `range`),
470
+ * with `0 <= start <= end <= sourceCode.text.length`. Rules report a
471
+ * declaration at this range, so it should cover the text that declares
472
+ * this one name and nothing else.
473
+ */
474
+ readonly range: readonly [number, number];
475
+ }
476
+
477
+ /**
478
+ * 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
480
+ * ESLint passes to rule visitors, so a rule can `context.report()` on it.
481
+ *
482
+ * The data comes from `sh-ast/analyze`'s `enumerateCommands` and is facts
483
+ * only: how the command is reached and what its words resolve to, never a
484
+ * verdict on whether running it is safe. A dynamic (`static: false`) `argv0`
485
+ * is a normal result.
486
+ *
487
+ * Read one through `ShellSourceCode.getCommandSites()`.
488
+ *
489
+ * Every rule linting a file sees the same sites, so each one is deeply
490
+ * frozen: the entry, its `context` array and every frame in it, its `argv`
491
+ * array, and every `WordResolution` in `argv` (`argv0` included). Writing to
492
+ * any of them throws in strict-mode code and is ignored otherwise, so one rule
493
+ * cannot change what another rule reads. The `node` is the shared lint view
494
+ * node, which, like every node ESLint passes to rules, is not frozen and must
495
+ * not be modified.
496
+ *
497
+ * @public
498
+ */
499
+ export declare interface ShellCommandSite {
500
+ /**
501
+ * The `CallExpr` view node for this command: the same object (`===`)
502
+ * ESLint passes to a `CallExpr` visitor, with `range` and `loc` in this
503
+ * file's UTF-16 coordinates.
504
+ */
505
+ readonly node: ShellNodeOf<'CallExpr'>;
506
+ /**
507
+ * The path from the file root to this command, outermost frame first,
508
+ * exactly as `sh-ast/analyze` reports it. For example, `date` in
509
+ * `f() { echo "$(date)"; }` has
510
+ * `[{ kind: 'function', name: 'f' }, { kind: 'cmdSubst' }]`.
511
+ */
512
+ readonly context: readonly CommandContext[];
513
+ /** The command word (`argv[0]`) resolved with `{ context: 'command-argument' }`. */
514
+ readonly argv0: WordResolution;
515
+ /**
516
+ * Every word of the command, `argv0` included, in argument order, each
517
+ * resolved with `{ context: 'command-argument' }`. Leading `VAR=val`
518
+ * assignments are not part of argv.
519
+ */
520
+ readonly argv: readonly WordResolution[];
521
+ /**
522
+ * Follows this command's argv0 through transparent wrappers (`env`, `sudo`,
523
+ * `nohup`, `exec`, …) and returns `sh-ast/analyze`'s `resolveArgv0`
524
+ * result. Same answer as
525
+ * `ShellSourceCode.resolveInvokedCommand(node, options)`; both read the
526
+ * same per-file index.
527
+ *
528
+ * @param options - Forwarded to `resolveArgv0` unchanged.
529
+ * `transparentWrappers` replaces `sh-ast/analyze`'s
530
+ * `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
531
+ * extend them instead.
532
+ * @returns A new result on every call. Its `chain` and `chainIndices`
533
+ * arrays belong to the caller. `chainIndices` gives each chain entry's
534
+ * position in this site's `argv`.
535
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
536
+ * `options.transparentWrappers` contains a malformed entry.
537
+ */
538
+ resolveInvokedCommand(options?: ResolveArgv0Options): Argv0Resolution;
539
+ }
540
+
541
+ /** Directive processing uses the comment text without its leading shell hash. @public */
542
+ export declare type ShellComment = ShellNodeOf<'Comment'>;
543
+
544
+ /** Project names for the five supported shell grammars. @public */
545
+ export declare type ShellDialect = 'bash' | 'posix' | 'mksh' | 'bats' | 'zsh';
546
+
547
+ /** The lint root has a statement collection even when upstream represents it as nil. @public */
548
+ export declare type ShellFile = ShellNodeOf<'File'>;
549
+
550
+ /**
551
+ * `ShellLanguage` — the `@eslint/core` `Language` implementation for shell
552
+ * scripts. Registered by the plugin as `languages.sh`, so consumers select
553
+ * it via `language: "sh/sh"`. Its root export is type-only: `plugin.languages.sh`
554
+ * is the single runtime language handle, and the language pipeline owns source construction.
555
+ *
556
+ * Implements `matchesSelectorClass` (the six launch esquery selector
557
+ * classes — see `./selector-classes.js`), so rules and end users can write
558
+ * class-based selectors (`:command`, `:loop`, `:conditional`, `:expansion`,
559
+ * `:quoted`, `:function`) against shell trees. The `SourceCode` directive
560
+ * members (`getDisableDirectives`, `getInlineConfigNodes`,
561
+ * `applyInlineConfig`) are implemented on `ShellSourceCode` itself; see
562
+ * shell-source-code.ts.
563
+ *
564
+ * @public
565
+ */
566
+ declare class ShellLanguage implements Language {
567
+ readonly fileType: "text";
568
+ readonly lineStart: 1;
569
+ readonly columnStart: 1;
570
+ readonly nodeTypeKey: string;
571
+ readonly visitorKeys: Record<string, string[]>;
572
+ readonly defaultLanguageOptions: ShellLanguageOptions;
573
+ /**
574
+ * Validates `languageOptions.dialect` (must be one of the five supported
575
+ * dialects, if present), `languageOptions.minBashVersion` (must be a
576
+ * string matching the `MAJOR[.MINOR]` numeric shape, if present, and
577
+ * applies only to `bash` and `bats`), and
578
+ * `languageOptions.directivePrefix` (must be a valid directive-comment
579
+ * label, if present). The removed `shellVersion` key throws with
580
+ * migration guidance; other unknown keys are silently ignored. See `shell-language-options.ts`'s
581
+ * `validateShellLanguageOptions` for the full rationale.
582
+ * @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
583
+ */
584
+ validateLanguageOptions(languageOptions: ShellLanguageOptions): void;
585
+ /**
586
+ * Resolves `dialect` to its default (`"bash"`) when unset and attaches a
587
+ * `toJSON()` method with a fixed key order, so that ESLint's config
588
+ * caching (keyed off serializing `languageOptions`) is stable regardless
589
+ * of the key order a user's config happened to use. See
590
+ * `shell-language-options.ts`'s `normalizeShellLanguageOptions`.
591
+ */
592
+ normalizeLanguageOptions(languageOptions: ShellLanguageOptions): NormalizedShellLanguageOptions;
593
+ /**
594
+ * `@eslint/core`'s esquery hook: lets a selector's leading `:` "class"
595
+ * (e.g. `:command` in `CallExpr[args.0.parts.0.value='jq']` isn't even
596
+ * needed there, but `:loop :command` is) match a whole family of node
597
+ * types instead of one literal type name. Delegates to
598
+ * `./selector-classes.js`'s `SELECTOR_CLASS_NODE_TYPES` table for the six
599
+ * launch classes; `ancestry` is unused today because none of the six launch
600
+ * classes need ancestor context, but the parameter is accepted to match
601
+ * `Language.matchesSelectorClass`'s signature exactly.
602
+ */
603
+ matchesSelectorClass(className: string, node: ShellNode, _ancestry: ShellNode[]): boolean;
604
+ /**
605
+ * Parses `file.body` (guaranteed to be a `string`, since `fileType` is
606
+ * `"text"`) with one synchronous parse and its original-position snapshot,
607
+ * mapping the result to
608
+ * the `{ok: true, ast}` / `{ok: false, errors}` shape `Language.parse` is
609
+ * required to return. Never throws — parse failures are reported as
610
+ * fatal lint messages, per the `Language` contract.
611
+ *
612
+ * A file whose extension marks it as a known non-shell source type (for
613
+ * example `.js` or `.json`) is never shell-parsed: it fails with a single
614
+ * diagnostic explaining that a `language: 'sh/sh'` config entry without
615
+ * `files` reached it, and how to scope that entry. Unicode characters remain
616
+ * source text. A native nesting-budget refusal returns no partial tree and
617
+ * becomes a fatal resource diagnostic at 1:1.
618
+ */
619
+ parse(file: File_2, context: {
620
+ languageOptions: ShellLanguageOptions;
621
+ }): ParseResult<ShellFile>;
622
+ /**
623
+ * Creates the `ShellSourceCode` ESLint uses to run rules against `ast`.
624
+ * `context.languageOptions` is ESLint's already-normalized copy (see
625
+ * `packages/eslint-plugin/test/language-options.test.ts` and
626
+ * `eslint`'s `Config#finalize`, which replaces `languageOptions` with
627
+ * `normalizeLanguageOptions`'s return value before either `parse` or
628
+ * `createSourceCode` is called) — `directivePrefix` is therefore always
629
+ * present, but `?? 'eslint'` stays as an explicit, honest fallback for
630
+ * direct construction (e.g. tests that skip the `Language` normalization
631
+ * step), mirroring `parse()`'s `dialect` default above. `dialect` and
632
+ * `minBashVersion` are forwarded so rules read the same normalized values
633
+ * through `sourceCode.dialect` / `sourceCode.minBashVersion`.
634
+ */
635
+ createSourceCode(file: File_2, parseResult: OkParseResult<ShellFile>, context: {
636
+ languageOptions: ShellLanguageOptions;
637
+ }): ShellSourceCode;
638
+ }
639
+
640
+ /**
641
+ * `languageOptions` accepted by {@link ShellLanguage}: `dialect` selects
642
+ * mvdan/sh's `LangVariant` through a consumer-owned mapping (default `"bash"`); `minBashVersion`
643
+ * is consumed by the rule layer (e.g. the bash-3.2 compatibility pack),
644
+ * never by the parser itself.
645
+ *
646
+ * Extends `Record<string, unknown>` (rather than a bare interface) so this
647
+ * type satisfies the `@eslint/core` package's `LanguageOptions` bound
648
+ * (itself `Record<string, unknown>`) wherever it is used as a
649
+ * `Language`/`SourceCode` type parameter — ESLint's own contract for
650
+ * language options is that they are arbitrary user-supplied records, not a
651
+ * closed shape.
652
+ *
653
+ * @public
654
+ */
655
+ export declare interface ShellLanguageOptions extends Record<string, unknown> {
656
+ readonly dialect?: ShellDialect;
657
+ /**
658
+ * The minimum Bash version (`MAJOR[.MINOR]`, such as `"3.2"`) the
659
+ * script must support, including every newer Bash. Only valid with the
660
+ * `bash` or `bats` dialect (the default is `bash`). The parser ignores
661
+ * it; `compat/*` rules report features unavailable at this floor. Unset
662
+ * means no Bash version constraint. Versions compare numerically by
663
+ * major then minor, with no upper version limit.
664
+ */
665
+ readonly minBashVersion?: string;
666
+ /**
667
+ * The prefix directive/inline-config comments must start with — e.g. the
668
+ * default `"eslint"` recognizes `# eslint-disable-next-line ...` and
669
+ * `# eslint <rule-config>`. Consumers who embed shell-linting inside a
670
+ * larger toolchain that already overloads `#eslint-*` comments for
671
+ * something else can configure a different prefix.
672
+ * @defaultValue `"eslint"`
673
+ */
674
+ readonly directivePrefix?: string;
675
+ }
676
+
677
+ /**
678
+ * The plain-data shape {@link NormalizedShellLanguageOptions.toJSON} returns:
679
+ * `dialect` and `directivePrefix` always present (both defaulted), `minBashVersion`
680
+ * present only when the caller supplied one. Keys are always emitted in this
681
+ * fixed order so that two logically-identical inputs serialize identically
682
+ * regardless of the key order the caller happened to use — the property this
683
+ * type exists to guarantee for cache-key stability (see
684
+ * {@link NormalizedShellLanguageOptions}). `directivePrefix` is included
685
+ * unconditionally (like `dialect`, unlike `minBashVersion`) because — like
686
+ * `dialect` and unlike `minBashVersion` — it always has a concrete effect on
687
+ * linting results (which comments the `SourceCode` recognizes as directives)
688
+ * whether or not the caller supplied one, so two configs that differ only in
689
+ * an *implicit* default vs. an *explicit* `directivePrefix: "eslint"` must
690
+ * still cache-key identically.
691
+ *
692
+ * @public
693
+ */
694
+ export declare interface ShellLanguageOptionsJSON {
695
+ readonly dialect: ShellDialect;
696
+ readonly directivePrefix: string;
697
+ readonly minBashVersion?: string;
698
+ }
699
+
700
+ /**
701
+ * A listener for a node of type `Node`. It is declared with method syntax on
702
+ * purpose: method parameters are checked bivariantly, which lets a listener
703
+ * for one node type sit alongside the union-typed listener every other
704
+ * selector key gets (see {@link ShellRuleVisitor}) without a type error.
705
+ *
706
+ * Exported so a helper that builds listeners for several rules can name the
707
+ * type it returns; `node` is the matched node and `parent` its parent
708
+ * (`undefined` for the root `File`).
709
+ *
710
+ * @public
711
+ */
712
+ export declare type ShellListener<Node extends ShellNode = ShellNode> = {
713
+ listener(node: Node, parent: ShellNode | undefined): void;
714
+ }['listener'];
715
+
716
+ /**
717
+ * A node in the consumer's lint view: the union of every node type, so
718
+ * narrowing on `type` gives that node's fields with no cast. Scalar/child fields
719
+ * use lowercase upstream spellings; syntax fidelity belongs to the associated
720
+ * upstream tree. Auxiliary view nodes may have spans derived from children and
721
+ * are not upstream Nodes.
722
+ * @public
723
+ */
724
+ export declare type ShellNode = ShellNodeMap[ShellNodeType];
725
+
726
+ /**
727
+ * The lint-view type of one upstream field value `Value`: a record becomes the
728
+ * node type of that record (a union of records, a union of node types), a slice
729
+ * becomes a read-only array of such nodes with its nil elements removed, a Go
730
+ * string becomes a JavaScript `string`, and booleans and operator values stay
731
+ * as they are. Upstream nil (`null`) and typed nils never reach a view, so
732
+ * neither appears in the result.
733
+ *
734
+ * It is the type of every field of every {@link ShellNodeMap} entry, exported
735
+ * so a helper that takes or returns a node's field value can name it.
736
+ *
737
+ * @public
738
+ */
739
+ export declare type ShellNodeField<Value> = Exclude<Value, null | {
740
+ readonly Type: 'TypedNil';
741
+ }> extends infer Present ? Present extends readonly (infer Element)[] ? readonly ShellNodeField<Element>[] : Present extends {
742
+ readonly Type: infer Type extends ShellNodeType;
743
+ } ? ShellNodeMap[Type] : Present extends string | Uint8Array ? string : Present : never;
744
+
745
+ /**
746
+ * Lint-view node types by their `type` discriminator, one entry per upstream
747
+ * syntax record. It is computed from `sh-ast`'s generated interfaces, so it
748
+ * follows the pinned mvdan/sh version.
749
+ *
750
+ * A node has `type`, `range` and `loc`, plus a lowercase field for each
751
+ * non-position upstream field. A field that is a single child that may be nil
752
+ * upstream is optional, because the view omits the key when the child is
753
+ * absent; a slice is always present.
754
+ *
755
+ * `range` is a half-open UTF-16 span of the source text and `loc` its ESLint
756
+ * line/column form; both describe the view, not the upstream byte positions. A
757
+ * node whose line ends in CRLF ends before the `\r` (and a text field such as
758
+ * `value` loses that one trailing `\r`), so a CRLF file reads like its LF
759
+ * twin. Auxiliary records (`Expansion`, `Replace`, `Slice`) take their span
760
+ * from their children.
761
+ *
762
+ * @public
763
+ */
764
+ export declare type ShellNodeMap = {
765
+ [Record in Exclude<Node, {
766
+ readonly Type: 'TypedNil';
767
+ }> | Expansion | Replace | Slice as Record['Type']]: {
768
+ /** Syntax kind of this node; the discriminator to narrow a ShellNode by. */
769
+ readonly type: Record['Type'];
770
+ /**
771
+ * Half-open UTF-16 span of the node in the source text. Its type is the
772
+ * mutable tuple ESLint's `fixer` methods take, so `node.range` can be passed
773
+ * to `fixer.insertTextBeforeRange` and the others without a cast; treat it
774
+ * as read-only.
775
+ */
776
+ range: [number, number];
777
+ /** ESLint line and column of the span's two ends. */
778
+ readonly loc: {
779
+ readonly start: ShellPosition;
780
+ readonly end: ShellPosition;
781
+ };
782
+ } & {
783
+ readonly [Name in keyof Record & string as Name extends 'Type' ? never : [Record[Name]] extends [SyntaxPos] ? never : null extends Record[Name] ? Exclude<Record[Name], null | {
784
+ readonly Type: 'TypedNil';
785
+ }> extends {
786
+ readonly Type: string;
787
+ } ? never : Lowercase<Name> : Lowercase<Name>]: ShellNodeField<Record[Name]>;
788
+ } & {
789
+ readonly [Name in keyof Record & string as null extends Record[Name] ? Exclude<Record[Name], null | {
790
+ readonly Type: 'TypedNil';
791
+ }> extends {
792
+ readonly Type: string;
793
+ } ? Lowercase<Name> : never : never]?: ShellNodeField<Record[Name]>;
794
+ };
795
+ };
796
+
797
+ /** The lint-view node whose `type` is `Type`, for example `ShellNodeOf<'Stmt'>`. @public */
798
+ export declare type ShellNodeOf<Type extends ShellNodeType> = ShellNodeMap[Type];
799
+
800
+ /** Every value a lint-view node's `type` can hold. @public */
801
+ export declare type ShellNodeType = keyof ShellNodeMap;
802
+
803
+ /** An ESLint location counts UTF-16 units, with both line and column starting at one. @public */
804
+ export declare interface ShellPosition {
805
+ /** One-based source line, with CRLF treated as one line break. */
806
+ readonly line: number;
807
+ /** One-based UTF-16 column; tabs and grapheme widths are not expanded. */
808
+ readonly column: number;
809
+ }
810
+
811
+ /**
812
+ * A finished shell rule, as {@link defineShellRule} returns it: an ordinary
813
+ * ESLint rule definition (it goes in a plugin's `rules` like any other)
814
+ * specialized to the shell language, whose `meta.languages` is always exactly
815
+ * `["sh/sh"]`. The `meta.languages` requirement is part of the type, so a
816
+ * hand-written object that omits it, or names another language, is not a
817
+ * `ShellRule`.
818
+ *
819
+ * @public
820
+ */
821
+ export declare type ShellRule<RuleOptions extends unknown[] = [], MessageIds extends string = string> = Omit<RuleDefinition<{
822
+ LangOptions: NormalizedShellLanguageOptions;
823
+ Code: ShellSourceCode;
824
+ RuleOptions: RuleOptions;
825
+ Visitor: ShellRuleVisitor;
826
+ Node: ShellNode;
827
+ MessageIds: MessageIds;
828
+ ExtRuleDocs: unknown;
829
+ }>, 'meta'> & {
830
+ readonly meta: Omit<RulesMeta<MessageIds, RuleOptions>, 'languages'> & {
831
+ languages: ['sh/sh'];
832
+ };
833
+ };
834
+
835
+ /**
836
+ * The `context` a shell rule's `create()` receives: ESLint's rule context
837
+ * specialized to the shell language, so `context.sourceCode` is
838
+ * {@link ShellSourceCode}, `context.languageOptions` is
839
+ * {@link NormalizedShellLanguageOptions}, `context.options` is `RuleOptions`,
840
+ * and `context.report` takes {@link ShellNode}s and only the `MessageIds` the
841
+ * rule declares. Name it when a helper outside `create()` needs the context.
842
+ *
843
+ * `context.languageOptions` is the object `ShellLanguage.normalizeLanguageOptions`
844
+ * returned, not the user's config input, so `dialect` is always set (`"bash"`
845
+ * by default) and needs no fallback. `context.sourceCode.dialect` carries that
846
+ * same normalized value; read whichever is closer to hand.
847
+ *
848
+ * @public
849
+ */
850
+ export declare type ShellRuleContext<RuleOptions extends unknown[] = [], MessageIds extends string = string> = RuleContext<{
851
+ LangOptions: NormalizedShellLanguageOptions;
852
+ Code: ShellSourceCode;
853
+ RuleOptions: RuleOptions;
854
+ Node: ShellNode;
855
+ MessageIds: MessageIds;
856
+ }>;
857
+
858
+ /**
859
+ * The `meta` a rule author writes: every field ESLint's rule `meta` accepts
860
+ * (`type`, `docs`, `schema`, `messages`, `fixable`, `defaultOptions`, …)
861
+ * except the language fields, which {@link defineShellRule} owns. `languages`
862
+ * and its deprecated singular predecessor `language` are typed `never`, so
863
+ * writing either — in particular a language other than `sh/sh` — is a
864
+ * compile error rather than a value the helper silently replaces.
865
+ *
866
+ * @public
867
+ */
868
+ export declare type ShellRuleMeta<RuleOptions extends unknown[] = [], MessageIds extends string = string> = Omit<RulesMeta<MessageIds, RuleOptions>, 'languages' | 'language'> & {
869
+ readonly languages?: never;
870
+ readonly language?: never;
871
+ };
872
+
873
+ /**
874
+ * What a rule author hands to {@link defineShellRule}: the rule's `meta` and
875
+ * its `create()`, exactly as in any ESLint rule, minus `meta.languages`. It is
876
+ * the rule before the helper finishes it; {@link ShellRule} is the finished
877
+ * rule (ESLint's `RuleDefinition`), so the input is named a spec, not a
878
+ * definition.
879
+ *
880
+ * @public
881
+ */
882
+ export declare interface ShellRuleSpec<RuleOptions extends unknown[] = [], MessageIds extends string = string> {
883
+ /** The rule's metadata; see {@link ShellRuleMeta}. */
884
+ readonly meta: ShellRuleMeta<RuleOptions, MessageIds>;
885
+ /** Builds the rule's listeners for one file from the shell-typed context. */
886
+ readonly create: (context: ShellRuleContext<RuleOptions, MessageIds>) => ShellRuleVisitor;
887
+ }
888
+
889
+ /**
890
+ * The listener map a shell rule's `create()` returns. Keys are node types or
891
+ * esquery selectors written against the lint view's spelling (for example
892
+ * `CallExpr[args.0.parts.0.value='jq']` or the `:command` selector class),
893
+ * optionally suffixed with `:exit`. ESLint calls each listener with the
894
+ * matched node and its parent (the parent is `undefined` for the root
895
+ * `File`).
896
+ *
897
+ * A key that is exactly a node type, with or without `:exit` (`CallExpr`,
898
+ * `Word:exit`), types its listener's node as that node type, so
899
+ * `CallExpr(node) { node.args }` reads `args` with no `type` check. Any other
900
+ * selector string (`*`, `CallExpr[…]`, `:command`, `Stmt > CallExpr`) matches
901
+ * nodes of more than one type, or of one type the key does not state, so its
902
+ * listener receives the whole {@link ShellNode} union: narrow it on `type`.
903
+ *
904
+ * @public
905
+ */
906
+ export declare interface ShellRuleVisitor extends ShellTypedListeners {
907
+ [selector: string]: ShellListener | undefined;
908
+ }
909
+
910
+ /**
911
+ * `ShellSourceCode` — the `SourceCode` object ESLint uses to work with a
912
+ * parsed shell file. Extends `@eslint/plugin-kit`'s `TextSourceCodeBase`, which
913
+ * already implements `getLoc`/`getRange`/`getText`/`lines` (both by reading
914
+ * the normalized node's own `loc`/`range` fields — see
915
+ * the consumer's source-view contract), `getLocFromIndex`, and
916
+ * `getIndexFromLoc`; this class adds the two members the base class
917
+ * deliberately leaves unimplemented: `traverse()` (base throws "Not
918
+ * implemented") and `getParent()` (base throws "Not implemented", and
919
+ * `getAncestors()` — already implemented generically in terms of
920
+ * `getParent()` — falls out for free).
921
+ *
922
+ * Directive support (`getDisableDirectives`, `getInlineConfigNodes`,
923
+ * `applyInlineConfig`) recognizes all four disable-comment forms
924
+ * (`<prefix>-disable`, `<prefix>-enable`, `<prefix>-disable-line`,
925
+ * `<prefix>-disable-next-line`) plus whole-file inline rule config
926
+ * (bare `<prefix> <rule-config>`), sourced from the tree's `Comment` nodes
927
+ * and parsed with
928
+ * `@eslint/plugin-kit`'s `ConfigCommentParser` — the same building blocks
929
+ * `@eslint/json`'s `JSONSourceCode` uses, generalized so the `<prefix>` is
930
+ * configurable (default `"eslint"`; see `ShellLanguageOptions.directivePrefix`)
931
+ * rather than hardcoded to `"eslint"`.
932
+ *
933
+ * Selector-class support (`matchesSelectorClass`, the six launch esquery
934
+ * classes) is implemented on `ShellLanguage` — see `shell-language.ts` and
935
+ * `selector-classes.ts`.
936
+ *
937
+ * Exported from the package root as a type only. Rules receive the instance
938
+ * from `context.sourceCode`; its constructor is internal language plumbing.
939
+ *
940
+ * Rule-author helpers (`resolveWord`, `resolveWordText`, `getCommandName`,
941
+ * `resolveInvokedCommand`, `getCommandSites`) answer "is this word statically
942
+ * the string `jq`?", "which command does this invocation run?", and "which
943
+ * commands does this file run, and where?" by delegating to
944
+ * `sh-ast/analyze`. They never reinterpret words themselves, so every rule
945
+ * gets the same answer for the same syntax. `dialect` and `minBashVersion`
946
+ * expose the file's normalized language options.
947
+ *
948
+ * Syntax access (`getSyntax`, `getViewNode`, `getIndexFromSyntaxPos`,
949
+ * `getLocFromSyntaxPos`) reaches behind the lint view to the sh-ast records
950
+ * this file was parsed into: from a view node to its record and back, and
951
+ * from a record's byte positions (such as `BinaryCmd.OpPos`, which the view
952
+ * leaves out) to ESLint coordinates in this file's text.
953
+ *
954
+ * Printed fixes (`getEditableSyntax`, `getPrintedReplacement`) edit an
955
+ * independent copy of a view node's record and print it with sh-ast's
956
+ * printer, returning the source range and text for `fixer.replaceTextRange`.
957
+ *
958
+ * @public
959
+ */
960
+ declare class ShellSourceCode extends TextSourceCodeBase<{
961
+ LangOptions: ShellLanguageOptions;
962
+ RootNode: ShellFile;
963
+ SyntaxElementWithLoc: ShellNode;
964
+ ConfigNode: ShellComment;
965
+ }> {
966
+ #private;
967
+ constructor(options: {
968
+ text: string;
969
+ ast: ShellFile;
970
+ directivePrefix?: string;
971
+ dialect?: ShellDialect;
972
+ minBashVersion?: string;
973
+ });
974
+ /**
975
+ * The shell dialect this file was parsed as: the normalized
976
+ * `languageOptions.dialect`, which defaults to `"bash"` when the config
977
+ * leaves it unset. Rules use it to gate dialect-specific checks.
978
+ */
979
+ get dialect(): ShellDialect;
980
+ /**
981
+ * The configured `languageOptions.minBashVersion` (a `MAJOR[.MINOR]` string
982
+ * such as `"3.2"`), or `undefined` when the config does not set one. The
983
+ * script must support this Bash and every newer release. The parser never
984
+ * reads it; compatibility rules use it as a floor with no upper limit.
985
+ */
986
+ get minBashVersion(): string | undefined;
987
+ /**
988
+ * The one-based location of a UTF-16 `index` in this file's text, where
989
+ * `index` may be anywhere from 0 to `text.length`. CRLF counts as one line
990
+ * break.
991
+ *
992
+ * Overrides the base class, which measures every index from the root
993
+ * node's own start and so assumes the root spans the whole text. A shell
994
+ * file's root starts at its first statement or comment, so the base answer
995
+ * was shifted by any leading blank lines or indentation.
996
+ *
997
+ * @throws TypeError with `ESLINT_SH_SOURCE_INDEX` when `index` is not a number.
998
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `index` is not an integer from 0 to `text.length`.
999
+ */
1000
+ getLocFromIndex(index: number): {
1001
+ line: number;
1002
+ column: number;
1003
+ };
1004
+ /**
1005
+ * The UTF-16 index of a one-based `loc` in this file's text: the inverse of
1006
+ * {@link ShellSourceCode.getLocFromIndex}. The column may name any position
1007
+ * on its line up to and including the line break.
1008
+ *
1009
+ * Overrides the base class for the same reason as `getLocFromIndex`.
1010
+ *
1011
+ * @throws TypeError with `ESLINT_SH_SOURCE_LOCATION` when `loc` is not an object with numeric `line` and `column`.
1012
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `loc` is not inside the text.
1013
+ */
1014
+ getIndexFromLoc(loc: {
1015
+ line: number;
1016
+ column: number;
1017
+ }): number;
1018
+ /**
1019
+ * Resolves a lint-view word using its original syntax and grammar position.
1020
+ * `sh-ast/analyze` owns static-word interpretation and dynamic reasons; this
1021
+ * method supplies the lint tree's position-based policy, without executing shell.
1022
+ *
1023
+ * Without explicit options, `CallExpr.args` use command-argument context, so
1024
+ * `PATH=a:~/bin` is literal there. Other positions retain the analyzer's
1025
+ * conservative default, including tilde expansion after an unquoted colon.
1026
+ * Explicit options are forwarded unchanged, even when empty.
1027
+ *
1028
+ * @param word - A parsed Word from the lint view.
1029
+ * @param options - Explicit analysis policy overriding grammar defaults.
1030
+ * @returns Static text or the analyzer's reason the word is dynamic.
1031
+ * @throws TypeError with `ESLINT_SH_WORD_NODE` when the word has no associated parsed shell syntax.
1032
+ * @public
1033
+ */
1034
+ resolveWord(word: ShellNodeOf<'Word'>, options?: ResolveWordOptions): WordResolution;
1035
+ /**
1036
+ * The text-only form of {@link ShellSourceCode.resolveWord}: returns its text
1037
+ * exactly when static, otherwise `null`. Both methods share one policy path
1038
+ * through `sh-ast/analyze`.
1039
+ *
1040
+ * @param word - A parsed Word from the lint view.
1041
+ * @param options - Explicit analysis policy overriding grammar defaults.
1042
+ * @returns The resolved text, or `null` when the word is not static.
1043
+ * @throws TypeError with `ESLINT_SH_WORD_NODE` when `word` is not a parsed shell `Word`.
1044
+ * @public
1045
+ */
1046
+ resolveWordText(word: ShellNodeOf<'Word'>, options?: ResolveWordOptions): string | null;
1047
+ /**
1048
+ * Returns the static text of `callExpr`'s command word (`argv[0]`) as
1049
+ * written, or `null` when that word is dynamic or absent. Transparent
1050
+ * wrappers are **not** followed: `sudo rm x` yields `"sudo"`. Use
1051
+ * {@link ShellSourceCode.resolveInvokedCommand} for the command a wrapper
1052
+ * chain actually runs.
1053
+ *
1054
+ * Delegates to `sh-ast/analyze`: the answer is the `argv0` resolution of the
1055
+ * `CommandSite` that `enumerateCommands` reports for this `CallExpr` in this
1056
+ * file. Leading `VAR=val` assignments are not part of argv, so
1057
+ * `FOO=1 jq .` yields `"jq"`. An assignment-only statement (`FOO=1`) has no
1058
+ * argv0 and no `CommandSite`, and yields `null`.
1059
+ *
1060
+ * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
1061
+ * @returns The command word's static text, or `null`.
1062
+ * @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
1064
+ * nesting exceeds analysis's recursion guard; see
1065
+ * {@link ShellSourceCode.resolveInvokedCommand}.
1066
+ */
1067
+ getCommandName(callExpr: ShellNodeOf<'CallExpr'>): string | null;
1068
+ /**
1069
+ * Follows `callExpr`'s argv0 through transparent wrappers (`env`, `sudo`,
1070
+ * `nohup`, `exec`, …) and returns `sh-ast/analyze`'s full `resolveArgv0`
1071
+ * result, or `null` for a `CallExpr` that has no `CommandSite` (an
1072
+ * assignment-only statement such as `FOO=1`).
1073
+ *
1074
+ * Delegates to `resolveArgv0` with the `CommandSite` that `enumerateCommands`
1075
+ * reports for this `CallExpr` in this file, so it inherits that function's
1076
+ * guarantee that an unknowable word is never guessed through. Read the
1077
+ * effective command's name as
1078
+ * `res.effective.static ? res.effective.text : null`.
1079
+ * `sudo -u x "$prog"` and `exec "$@"` have a non-static `effective` with
1080
+ * reason `expansion`; `env -S '…'` and `bash -c '…'` have reason
1081
+ * `embedded-command`; `chain`
1082
+ * lists every word resolved along the way, outermost wrapper first, and
1083
+ * `chainIndices` gives each entry's position in the command's `argv` (as
1084
+ * {@link ShellSourceCode.getCommandSites} reports it). When `effective` is
1085
+ * static, the effective command's arguments are
1086
+ * `argv.slice(chainIndices.at(-1)! + 1)`: every entry after the effective
1087
+ * command's own index. For an interpreter command string the final chain
1088
+ * index instead locates the selector flag; the interpreter is in `chain.at(-2)`.
1089
+ * `embeddedCommandInterpreters: []` retains the interpreter as the static
1090
+ * effective command when a policy needs program identity. Utility wrappers
1091
+ * can match absolute-path basenames; `shellBuiltin: true` entries require
1092
+ * exact names, so external paths do not acquire in-process semantics.
1093
+ *
1094
+ * Enumeration runs once per file, the first time any command helper is
1095
+ * called. If the file's nesting exceeds `enumerateCommands`'s recursion
1096
+ * guard, its `ShAnalyzeMaxDepthError` propagates unchanged and ESLint
1097
+ * reports the rule as crashed for that file. That fails closed: a partial
1098
+ * index would silently omit real commands.
1099
+ *
1100
+ * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
1101
+ * @param options - Forwarded to `resolveArgv0` unchanged.
1102
+ * `transparentWrappers` replaces `sh-ast/analyze`'s
1103
+ * `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
1104
+ * extend them instead.
1105
+ * @returns The resolution, or `null` when `callExpr` invokes no command.
1106
+ * @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
1108
+ * nesting exceeds analysis's recursion guard.
1109
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
1110
+ * `options.transparentWrappers` contains a malformed entry.
1111
+ */
1112
+ resolveInvokedCommand(callExpr: ShellNodeOf<'CallExpr'>, options?: ResolveArgv0Options): Argv0Resolution | null;
1113
+ /**
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.
1119
+ *
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()`.
1127
+ *
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.
1143
+ */
1144
+ getCommandSites(): readonly ShellCommandSite[];
1145
+ /**
1146
+ * Returns the sh-ast record `node` was projected from: this file's original
1147
+ * parse of `node`, with every field the lint view leaves out, including
1148
+ * named token positions such as `BinaryCmd.OpPos`, `Stmt.Semicolon` and
1149
+ * `Redirect.OpPos`. Pass those positions to
1150
+ * {@link ShellSourceCode.getIndexFromSyntaxPos} or
1151
+ * {@link ShellSourceCode.getLocFromSyntaxPos} to report on them, or pass the
1152
+ * record to an `sh-ast/analyze` function.
1153
+ *
1154
+ * The returned record is read-only by contract. It is the language's
1155
+ * original parse, shared by every rule and helper linting this file, and
1156
+ * mutating it is unsupported: helpers such as
1157
+ * {@link ShellSourceCode.resolveWordText} read the same record and would see
1158
+ * the edit. It is not frozen, so a write does not throw. Make edits on an
1159
+ * editable copy from {@link ShellSourceCode.getEditableSyntax} instead.
1160
+ *
1161
+ * @param node - A view node from this file's lint tree.
1162
+ * @returns The original sh-ast record, or `undefined` when `node` has none
1163
+ * in this file: an auxiliary view (a record whose type is not an sh-ast
1164
+ * `Node`, such as the `Slice` of `${x:1:2}`), a view node from another
1165
+ * file's tree, or an
1166
+ * object that did not come from the parser.
1167
+ */
1168
+ getSyntax(node: ShellNode): Node | undefined;
1169
+ /**
1170
+ * Returns the lint view node projected from `syntax`: the inverse of
1171
+ * {@link ShellSourceCode.getSyntax}. The result is the same object (`===`)
1172
+ * ESLint passes to rule visitors, so it can be passed to
1173
+ * `context.report()`. Use it to come back to the view after navigating the
1174
+ * original records, for example from a `Stmt` record's `Cmd`.
1175
+ *
1176
+ * Lookup is by object identity, so only the parser's own records match.
1177
+ * sh-ast's `walk` passes its callback a fresh copy of each comment stored
1178
+ * on a `Stmt`, `CaseItem` or `ArrayElem`, as Go's `syntax.Walk` does, so
1179
+ * those `Comment` copies have no view node. Read the stored comment from
1180
+ * the record's `Comments` array instead.
1181
+ *
1182
+ * @param syntax - An sh-ast `Node` record from this file's original parse.
1183
+ * @returns The view node, or `undefined` for any other record, including a
1184
+ * copy of one of this file's records (such as a `structuredClone`) and a
1185
+ * record from another parse.
1186
+ */
1187
+ getViewNode(syntax: Node): ShellNode | undefined;
1188
+ /**
1189
+ * Returns an independent, editable deep copy of the sh-ast record `node`
1190
+ * was parsed from: the first half of a printed fix. Edit the copy, then pass
1191
+ * it to {@link ShellSourceCode.getPrintedReplacement}.
1192
+ *
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,
1198
+ * arrays, positions and byte buffers. Editing it leaves this file's original
1199
+ * syntax, its lint view, its cached traversal and the answers of view-aware
1200
+ * helpers such as {@link ShellSourceCode.resolveWord} and
1201
+ * {@link ShellSourceCode.resolveWordText} unchanged. Each call returns a new
1202
+ * copy.
1203
+ *
1204
+ * The copy's position fields keep their original values, and the copy has
1205
+ * no view node: {@link ShellSourceCode.getViewNode},
1206
+ * {@link ShellSourceCode.getIndexFromSyntaxPos} and the parse's position
1207
+ * snapshot describe the original source, not the edit. Keep `node` to know
1208
+ * which source range the fix replaces.
1209
+ *
1210
+ * @param node - A view node from this file's lint tree.
1211
+ * @returns A deep copy of `node`'s original sh-ast record.
1212
+ * @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file: an
1213
+ * auxiliary view (such as the `Slice` of `${x:1:2}`), a view node of another
1214
+ * file, or an object that did not come from the parser.
1215
+ */
1216
+ getEditableSyntax(node: ShellNode): Node;
1217
+ /**
1218
+ * Prints `edited` with sh-ast's `printSync` and pairs the text with the
1219
+ * source range it replaces, so a printed fix is
1220
+ * `fix: (fixer) => fixer.replaceTextRange(r.range, r.text)`. `edited` is
1221
+ * usually a copy from {@link ShellSourceCode.getEditableSyntax} of `node`
1222
+ * or of one of its ancestors.
1223
+ *
1224
+ * The range is `node.range`, except that a `File` root replaces the whole
1225
+ * text (`[0, text.length]`) whatever `node` is, which allows whole-file
1226
+ * regeneration. `options` is passed to `printSync` unchanged.
1227
+ *
1228
+ * The printer formats; it does not replay the source. Its output starts at
1229
+ * column 0 and indents nested lines with upstream's indentation (tabs by
1230
+ * default, `Indent` spaces when `options.Indent` is set). Replacing a
1231
+ * multi-line root nested inside other code, such as an `if` statement in a
1232
+ * function body, therefore keeps the shell meaning but may change the
1233
+ * formatting of its lines. Use a `Word` or `WordPart` root for a surgical
1234
+ * fix that leaves the surrounding source as written.
1235
+ *
1236
+ * A `Stmt` root is adjusted so its text matches `node.range`. A statement's
1237
+ * own leading and trailing comments lie outside its range, so they are not
1238
+ * printed (the copy passed in is not modified). When `node` is a statement
1239
+ * whose range ends in its `;` or `&` terminator, upstream prints the
1240
+ * statement without a `;`, so a `;` is appended unless the edited statement
1241
+ * prints its own `&`, `|&` or disown operator. Without this, replacing `a`
1242
+ * in `a; b` would produce `a b`.
1243
+ *
1244
+ * @param node - A view node from this file's lint tree: the node the fix
1245
+ * replaces.
1246
+ * @param edited - The record to print: a `File`, `Stmt`, `Word`, `Assign`,
1247
+ * `Command` or `WordPart`.
1248
+ * @param options - Forwarded to `printSync` unchanged.
1249
+ * @returns The range to replace and the printed text to put there.
1250
+ * @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file (see
1251
+ * {@link ShellSourceCode.getEditableSyntax}), when `edited` is not a
1252
+ * printable root (`ESLINT_SH_PRINT_ROOT`; the message names its type), or when the printer's output
1253
+ * is not valid UTF-8 (`ESLINT_SH_PRINT_ENCODING`), or the edited syntax contains literal vertical tabs or
1254
+ * form feeds that the printer cannot preserve (`ESLINT_SH_PRINT_UNSAFE_TEXT`). Non-UTF-8 output comes back
1255
+ * from `printSync` as a `Uint8Array` and is never decoded lossily into a fix.
1256
+ * @throws `PrintError` (`SH_AST_SYNTAX_PRINT`), `PrintPanicError` (`SH_AST_SYNTAX_PRINT_PANIC`),
1257
+ * or `InputError` (`SH_AST_SYNTAX_INPUT`), passed through unchanged from sh-ast, when upstream's
1258
+ * printer fails for `edited` or `options`.
1259
+ */
1260
+ getPrintedReplacement(node: ShellNode, edited: Node, options?: PrintOptions): {
1261
+ range: [number, number];
1262
+ text: string;
1263
+ };
1264
+ /**
1265
+ * Converts a byte position from this file's original parse into the
1266
+ * UTF-16 index ESLint uses for `range` and `text.slice`. sh-ast positions
1267
+ * count UTF-8 bytes, so a raw `Offset` is wrong for any source with
1268
+ * non-ASCII text before it. For example, in `echo 🎉 && echo 中文`,
1269
+ * `getIndexFromSyntaxPos(binaryCmd.OpPos)` is the index where `&&` starts.
1270
+ *
1271
+ * The conversion is only correct for positions of this file's original
1272
+ * parse, as read from {@link ShellSourceCode.getSyntax}'s records. The live
1273
+ * positions of an edited or copied tree describe that edit, not this
1274
+ * source.
1275
+ *
1276
+ * @param pos - A `SyntaxPos` from one of this file's original records.
1277
+ * @returns The UTF-16 index of `pos` in this file's text.
1278
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid (`IsValid === false`), recovered
1279
+ * (`IsRecovered === true`), or overflowed (`OffsetOverflow === true`), or
1280
+ * when its offset is not a UTF-8 character boundary of this source. Such a
1281
+ * position is never rounded to a nearby boundary.
1282
+ * @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
1283
+ * code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
1284
+ */
1285
+ getIndexFromSyntaxPos(pos: SyntaxPos): number;
1286
+ /**
1287
+ * Converts a byte position from this file's original parse into a one-based
1288
+ * ESLint location, the shape `context.report({ loc })` takes. The column
1289
+ * counts UTF-16 code units, not bytes, and CRLF counts as one line break.
1290
+ * Same contract as {@link ShellSourceCode.getIndexFromSyntaxPos}.
1291
+ *
1292
+ * @param pos - A `SyntaxPos` from one of this file's original records.
1293
+ * @returns The one-based line and UTF-16 column of `pos`.
1294
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid, recovered, or overflowed, or
1295
+ * when its offset is not a UTF-8 character boundary of this source.
1296
+ * @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
1297
+ * code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
1298
+ */
1299
+ getLocFromSyntaxPos(pos: SyntaxPos): {
1300
+ line: number;
1301
+ column: number;
1302
+ };
1303
+ /**
1304
+ * Returns the parent of `node`, or `undefined` for the root `File` node
1305
+ * (or any node visited before `traverse()` has run once). ESLint always
1306
+ * calls `traverse()` before any rule can call `getParent`/`getAncestors`,
1307
+ * so in practice the map is always populated by the time a rule observes
1308
+ * it.
1309
+ */
1310
+ getParent(node: ShellNode): ShellNode | undefined;
1311
+ /**
1312
+ * Produces the enter/exit steps ESLint uses for selectors and ancestor lookup.
1313
+ * Child keys describe the consumer view, including its auxiliary records.
1314
+ * This callback protocol is ESLint's, independent of upstream syntax.Walk.
1315
+ */
1316
+ traverse(): Iterable<TraversalStep>;
1317
+ /**
1318
+ * Returns every `Comment` node whose text is a directive or inline-config
1319
+ * candidate for this source code's `directivePrefix` — the pool both
1320
+ * {@link ShellSourceCode.getDisableDirectives} and {@link ShellSourceCode.applyInlineConfig} draw from,
1321
+ * and the array ESLint core itself asks for directly (to warn "has no
1322
+ * effect" when `linterOptions.noInlineConfig` is set — see
1323
+ * `eslint`'s `lib/linter/linter.js`, the `warnInlineConfig` branch).
1324
+ */
1325
+ getInlineConfigNodes(): ShellComment[];
1326
+ /**
1327
+ * Returns the disable/enable directives found among
1328
+ * {@link ShellSourceCode.getInlineConfigNodes}'s comments, recognizing all four forms —
1329
+ * `<prefix>-disable`, `<prefix>-enable`, `<prefix>-disable-line`,
1330
+ * `<prefix>-disable-next-line` — with `-- justification` capture, per the
1331
+ * `@eslint/core` `Directive` contract. Mirrors `@eslint/json`'s
1332
+ * `JSONSourceCode.getDisableDirectives` (verified against its published
1333
+ * source as the named ecosystem precedent), generalized to a configurable
1334
+ * prefix instead of the hardcoded `"eslint"` label.
1335
+ *
1336
+ * Unlike `JSONSourceCode` (whose block comments can span multiple
1337
+ * physical lines, making `<prefix>-disable-line` spanning lines a real,
1338
+ * reportable problem), mvdan/sh's `#` line comments cannot contain an
1339
+ * embedded newline — the parser always terminates a comment at end of
1340
+ * line — so that particular problem can never arise here and is not
1341
+ * checked for.
1342
+ */
1343
+ getDisableDirectives(): {
1344
+ directives: Directive[];
1345
+ problems: FileProblem[];
1346
+ };
1347
+ /**
1348
+ * Returns the whole-file inline rule configuration found among
1349
+ * {@link ShellSourceCode.getInlineConfigNodes}'s comments — a bare `<prefix> <rule-config>`
1350
+ * comment (e.g. `# eslint sh/rule-a: "error"`), parsed with
1351
+ * `ConfigCommentParser.parseJSONLikeConfig`. Mirrors `@eslint/json`'s
1352
+ * `JSONSourceCode.applyInlineConfig`. This is the surface
1353
+ * `linterOptions.noInlineConfig: true` suppresses (ESLint core skips
1354
+ * calling this method — and `getDisableDirectives`, together, since both
1355
+ * are gated by the same flag in `eslint`'s own `linter.js` — and instead
1356
+ * calls `getInlineConfigNodes` to emit a "has no effect" warning per
1357
+ * comment).
1358
+ */
1359
+ applyInlineConfig(): {
1360
+ configs: {
1361
+ config: {
1362
+ rules: RulesConfig;
1363
+ };
1364
+ loc: SourceLocation;
1365
+ }[];
1366
+ problems: FileProblem[];
1367
+ };
1368
+ }
1369
+
1370
+ /**
1371
+ * The listeners whose key names one node type, or that node type with the
1372
+ * `:exit` suffix, each receiving exactly that node type. The key is
1373
+ * unambiguous in both forms (`CallExpr`, `CallExpr:exit`), so a listener
1374
+ * needs no `node.type` guard. Wildcard (`*`, `*:exit`) and attribute or
1375
+ * class selectors name no single type and fall under the index signature.
1376
+ *
1377
+ * Exported because {@link ShellRuleVisitor} extends it.
1378
+ *
1379
+ * @public
1380
+ */
1381
+ export declare type ShellTypedListeners = {
1382
+ [Type in ShellNodeType as Type | `${Type}:exit`]?: ShellListener<ShellNodeOf<Type>>;
1383
+ };
1384
+
1385
+ /** The rule-context fields needed to resolve shared wrappers and their path spellings. @public */
1386
+ export declare interface TransparentWrappersBindingContext {
1387
+ /** Shared ESLint configuration containing the project's shell facts. */
1388
+ readonly settings: SettingsConfig;
1389
+ /** The current file supplies path spellings without filesystem inspection or execution. */
1390
+ readonly sourceCode: ShellSourceCode;
1391
+ }
1392
+
1393
+ export { WordResolution }
1394
+
1395
+ /**
1396
+ * What a "must be run through a wrapper" rule enforces. Passed to
1397
+ * {@link createWrapperRule}.
1398
+ *
1399
+ * @public
1400
+ */
1401
+ export declare interface WrapperRuleConfig {
1402
+ /**
1403
+ * The command names that must be run through the wrapper. A static command
1404
+ * word matches a name when it equals it, or when it contains a slash and
1405
+ * its basename equals it (`/usr/bin/curl` and `./bin/curl` match `curl`).
1406
+ */
1407
+ readonly commands: readonly string[];
1408
+ /**
1409
+ * The wrapper the commands must be run through. A string names a wrapper
1410
+ * 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`, …),
1412
+ * whose known option shape is used. A `WrapperSpec` declares the wrapper's
1413
+ * option shape, so that `retry -n 3 curl x` is recognized as `curl` run
1414
+ * through `retry`; any of its `names` counts as the wrapper. Like
1415
+ * `commands`, a wrapper run by path matches by basename
1416
+ * (`/usr/local/bin/retry curl x`).
1417
+ */
1418
+ readonly wrapper: string | WrapperSpec;
1419
+ /**
1420
+ * Listed commands that count only with some subcommands, keyed by command
1421
+ * name. A listed command with no entry here counts with any arguments.
1422
+ */
1423
+ readonly subcommands?: Readonly<Record<string, WrapperRuleSubcommands>>;
1424
+ /**
1425
+ * Invocations of a listed command that only act locally and so are not
1426
+ * reported, keyed by the command as the rule's message names it: the listed
1427
+ * name (`curl`), or the name with its subcommand (`git clone`).
1428
+ */
1429
+ readonly localInvocations?: Readonly<Record<string, WrapperRuleLocalInvocation>>;
1430
+ /**
1431
+ * The rule's `meta.docs` fields a rule pack owns. `url` defaults to this
1432
+ * package's wrapper-rules docs page, and `description` to a sentence naming
1433
+ * the commands and the wrapper. Set them to point users at the pack's own
1434
+ * documentation.
1435
+ */
1436
+ readonly docs?: {
1437
+ readonly url?: string;
1438
+ readonly description?: string;
1439
+ };
1440
+ }
1441
+
1442
+ /**
1443
+ * Ways to invoke one listed command that only act locally, so the policy has
1444
+ * nothing to guard. An invocation matching either field is not reported.
1445
+ *
1446
+ * @public
1447
+ */
1448
+ export declare interface WrapperRuleLocalInvocation {
1449
+ /**
1450
+ * Complete argument lists, after the command (and its subcommand, if it has
1451
+ * one), that make the invocation local. They match exactly: with
1452
+ * `[['--version']]`, `curl --version` is local and
1453
+ * `curl --version https://example.com` is not.
1454
+ */
1455
+ readonly argLists?: readonly (readonly string[])[];
1456
+ /** Local when the command's source operand is a local path. */
1457
+ readonly localOperand?: WrapperRuleLocalOperand;
1458
+ }
1459
+
1460
+ /**
1461
+ * Names the operand of a listed command whose value decides whether the
1462
+ * invocation can leave the machine, such as the source of `git clone`.
1463
+ *
1464
+ * The flags describe the options that may precede the operand, with the same
1465
+ * meaning as {@link WrapperRuleSubcommands}'s: `noArgFlags` take no value and
1466
+ * `argFlags` take one (as `--depth 1`, or `--depth=1` in one word). The
1467
+ * operand is the first word after them, or after a `--`. A flag that is not
1468
+ * declared leaves the operand unknown, and an unknown operand is never taken
1469
+ * as local.
1470
+ *
1471
+ * @public
1472
+ */
1473
+ export declare interface WrapperRuleLocalOperand extends Pick<WrapperSpec, 'noArgFlags' | 'argFlags'> {
1474
+ /**
1475
+ * The operand counts as local when it is a static word starting with one
1476
+ * of these, such as `['./', '../', '/', 'file://']`.
1477
+ */
1478
+ readonly localPrefixes: readonly string[];
1479
+ }
1480
+
1481
+ /**
1482
+ * Restricts a listed command to some of its subcommands, for commands such as
1483
+ * `git` where only some subcommands are in scope (`git fetch` is a network
1484
+ * call, `git status` is not).
1485
+ *
1486
+ * The flag fields are `WrapperSpec`'s own, picked from it so the two cannot
1487
+ * drift, and describe the command's options that may appear before the
1488
+ * subcommand (`git -C dir fetch`): `noArgFlags` take no operand (`--bare`),
1489
+ * `argFlags` take one (`-C <dir>`), and `stopsChainFlags` mean the command
1490
+ * runs no subcommand at all (`git --version fetch` prints the version, and is
1491
+ * never reported). The subcommand is found the way a wrapped command is:
1492
+ * declared options are skipped, and a flag the command does not declare
1493
+ * leaves the subcommand unknown, so the invocation is not reported.
1494
+ *
1495
+ * @public
1496
+ */
1497
+ export declare interface WrapperRuleSubcommands extends Pick<WrapperSpec, 'noArgFlags' | 'argFlags' | 'stopsChainFlags'> {
1498
+ /** The subcommands that make an invocation of the command count, such as `['fetch', 'push']`. */
1499
+ readonly names: readonly string[];
1500
+ }
1501
+
1502
+ export { WrapperSpec }
1503
+
1504
+ export { }
1505
+
1506
+ export type { ShellLanguage, ShellSourceCode };