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