@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
@@ -1,9 +1,17 @@
1
+ /**
2
+ * ESLint's per-file shell view: source coordinates, grammar-aware analysis and
3
+ * checked syntax edits for rules. The language pipeline owns construction;
4
+ * consumers receive this instance through their rule context.
5
+ * Guard codes distinguish malformed argument shapes, foreign views, inexact
6
+ * ranges and printer content loss. Dependency analysis/printing errors retain
7
+ * their classes, codes and causes.
8
+ */
1
9
  import { ConfigCommentParser, Directive, TextSourceCodeBase, VisitNodeStep, } from '@eslint/plugin-kit';
2
10
  import { childNodes, isShellComment, projectedComments, projectedCoordinates, syntaxForNode, viewForSyntax, walkShell, } from './syntax-view.js';
3
11
  import { SourceCoordinates } from './source-coordinates.js';
4
12
  import { SYNTAX_INTERFACES, printSync } from 'sh-ast';
5
- import { resolveArgv0 } from 'sh-ast/analyze';
6
- import { buildCommandSiteIndex, rawCallExprFor, viewCommandSites } from './command-resolution.js';
13
+ import { resolveArgv0 } from 'sh-analysis';
14
+ import { buildCommandSiteIndex, rawCallExprFor, viewCommandInventory, } from './command-resolution.js';
7
15
  import { resolveWord } from './word-resolution.js';
8
16
  /**
9
17
  * Refuses edited syntax whose string or byte values the upstream printer treats as layout.
@@ -21,8 +29,8 @@ function refusePrinterControlCharacters(root) {
21
29
  const unsafe = (typeof current === 'string' && /[\v\f]/u.test(current)) ||
22
30
  (current instanceof Uint8Array && current.some((byte) => byte === 0x0b || byte === 0x0c));
23
31
  if (unsafe) {
24
- throw new TypeError('cannot print a text fix containing literal vertical tabs and form feeds: ' +
25
- 'the printer changes their value');
32
+ throw Object.assign(new TypeError('cannot print a text fix containing literal vertical tabs and form feeds: ' +
33
+ 'the printer changes their value'), { code: 'ESLINT_SH_PRINT_UNSAFE_TEXT' });
26
34
  }
27
35
  // A checked byte-valued string is a leaf; its individual numbers are not syntax children.
28
36
  if (current instanceof Uint8Array) {
@@ -220,8 +228,8 @@ function computeUnusedDirectiveFixRange(comment, text) {
220
228
  * converting them would place a report or fix somewhere the parser never
221
229
  * pointed. They are rejected rather than rounded to a nearby boundary.
222
230
  *
223
- * @throws TypeError when `pos` is not shaped like an sh-ast `SyntaxPos`.
224
- * @throws RangeError when `pos` is invalid, recovered, or overflowed.
231
+ * @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not shaped like an sh-ast `SyntaxPos`.
232
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid, recovered, or overflowed.
225
233
  */
226
234
  function exactByteOffset(pos) {
227
235
  const candidate = pos;
@@ -231,11 +239,13 @@ function exactByteOffset(pos) {
231
239
  typeof pos.IsValid !== 'boolean' ||
232
240
  typeof pos.IsRecovered !== 'boolean' ||
233
241
  typeof pos.OffsetOverflow !== 'boolean') {
234
- throw new TypeError('expected an sh-ast SyntaxPos');
242
+ throw Object.assign(new TypeError('expected an sh-ast SyntaxPos'), {
243
+ code: 'ESLINT_SH_SYNTAX_POSITION',
244
+ });
235
245
  }
236
246
  if (!pos.IsValid || pos.IsRecovered || pos.OffsetOverflow) {
237
- throw new RangeError(`syntax position has no exact source offset (IsValid: ${String(pos.IsValid)}, ` +
238
- `IsRecovered: ${String(pos.IsRecovered)}, OffsetOverflow: ${String(pos.OffsetOverflow)})`);
247
+ throw Object.assign(new RangeError(`syntax position has no exact source offset (IsValid: ${String(pos.IsValid)}, ` +
248
+ `IsRecovered: ${String(pos.IsRecovered)}, OffsetOverflow: ${String(pos.OffsetOverflow)})`), { code: 'ESLINT_SH_SOURCE_RANGE' });
239
249
  }
240
250
  return pos.Offset;
241
251
  }
@@ -265,11 +275,13 @@ function printableRootType(edited) {
265
275
  candidate === null ||
266
276
  !('Type' in candidate) ||
267
277
  typeof candidate.Type !== 'string') {
268
- throw new TypeError('expected an sh-ast syntax record to print');
278
+ throw Object.assign(new TypeError('expected an sh-ast syntax record to print'), {
279
+ code: 'ESLINT_SH_PRINT_ROOT',
280
+ });
269
281
  }
270
282
  if (!printableRootTypes.has(candidate.Type)) {
271
- throw new TypeError(`cannot print a ${candidate.Type} as a fix: printSync accepts File, Stmt, Word, Assign, ` +
272
- 'Command and WordPart roots');
283
+ throw Object.assign(new TypeError(`cannot print a ${candidate.Type} as a fix: printSync accepts File, Stmt, Word, Assign, ` +
284
+ 'Command and WordPart roots'), { code: 'ESLINT_SH_PRINT_ROOT' });
273
285
  }
274
286
  return candidate.Type;
275
287
  }
@@ -323,11 +335,14 @@ function withUnusedDirectiveFixRange(comment, text) {
323
335
  * classes) is implemented on `ShellLanguage` — see `shell-language.ts` and
324
336
  * `selector-classes.ts`.
325
337
  *
326
- * Rule-author helpers (`resolveWordText`, `getCommandName`,
327
- * `resolveInvokedCommand`, `getCommandSites`) answer "is this word statically
338
+ * Exported from the package root as a type only. Rules receive the instance
339
+ * from `context.sourceCode`; its constructor is internal language plumbing.
340
+ *
341
+ * Rule-author helpers (`resolveWord`, `resolveWordText`, `getCommandName`,
342
+ * `resolveInvokedCommand`, `getCommandInventory`) answer "is this word statically
328
343
  * the string `jq`?", "which command does this invocation run?", and "which
329
344
  * commands does this file run, and where?" by delegating to
330
- * `sh-ast/analyze`. They never reinterpret words themselves, so every rule
345
+ * `sh-analysis`. They never reinterpret words themselves, so every rule
331
346
  * gets the same answer for the same syntax. `dialect` and `minBashVersion`
332
347
  * expose the file's normalized language options.
333
348
  *
@@ -400,7 +415,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
400
415
  */
401
416
  #commandSites;
402
417
  /**
403
- * {@link ShellSourceCode.getCommandSites}'s answer: the index's sites in
418
+ * {@link ShellSourceCode.getCommandInventory}'s answer: the index's sites in
404
419
  * view terms, built once from `#commandSites` so every caller shares one
405
420
  * frozen array.
406
421
  */
@@ -443,12 +458,15 @@ export class ShellSourceCode extends TextSourceCodeBase {
443
458
  * file's root starts at its first statement or comment, so the base answer
444
459
  * was shifted by any leading blank lines or indentation.
445
460
  *
446
- * @throws TypeError when `index` is not a number.
447
- * @throws RangeError when `index` is not an integer from 0 to `text.length`.
461
+ * @throws TypeError with `ESLINT_SH_SOURCE_INDEX` when `index` is not a number.
462
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `index` is not an integer from 0 to `text.length`.
448
463
  */
449
464
  getLocFromIndex(index) {
450
- if (typeof index !== 'number')
451
- throw new TypeError('Expected `index` to be a number.');
465
+ if (typeof index !== 'number') {
466
+ throw Object.assign(new TypeError('Expected `index` to be a number.'), {
467
+ code: 'ESLINT_SH_SOURCE_INDEX',
468
+ });
469
+ }
452
470
  const { line, column } = this.#textCoordinates().atIndex(index);
453
471
  return { line, column };
454
472
  }
@@ -459,8 +477,8 @@ export class ShellSourceCode extends TextSourceCodeBase {
459
477
  *
460
478
  * Overrides the base class for the same reason as `getLocFromIndex`.
461
479
  *
462
- * @throws TypeError when `loc` is not an object with numeric `line` and `column`.
463
- * @throws RangeError when `loc` is not inside the text.
480
+ * @throws TypeError with `ESLINT_SH_SOURCE_LOCATION` when `loc` is not an object with numeric `line` and `column`.
481
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `loc` is not inside the text.
464
482
  */
465
483
  getIndexFromLoc(loc) {
466
484
  if (typeof loc !== 'object' ||
@@ -468,7 +486,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
468
486
  loc === null ||
469
487
  typeof loc.line !== 'number' ||
470
488
  typeof loc.column !== 'number') {
471
- throw new TypeError('Expected `loc` to be an object with numeric `line` and `column` properties.');
489
+ throw Object.assign(new TypeError('Expected `loc` to be an object with numeric `line` and `column` properties.'), { code: 'ESLINT_SH_SOURCE_LOCATION' });
472
490
  }
473
491
  return this.#textCoordinates().indexAt(loc.line, loc.column);
474
492
  }
@@ -482,30 +500,37 @@ export class ShellSourceCode extends TextSourceCodeBase {
482
500
  return this.#ownCoordinates;
483
501
  }
484
502
  /**
485
- * Returns the literal text of `word` when `sh-ast/analyze`'s `resolveWord`
486
- * reports it static, or `null` otherwise.
503
+ * Resolves a lint-view word using its original syntax and grammar position.
504
+ * `sh-analysis` owns static-word interpretation and dynamic reasons; this
505
+ * method supplies the lint tree's position-based policy, without executing shell.
487
506
  *
488
- * Delegates to `resolveWord` (through this package's `resolveWord` export),
489
- * which alone defines what "static" means: a word is static iff
490
- * `resolveWord` reports `static: true`. Its non-static reasons are
491
- * `expansion`, `tilde`, `glob`, `brace`, `locale`, and `unsupported`.
492
- * Call the root `resolveWord` export instead when the reason matters.
507
+ * Without explicit options, `CallExpr.args` use command-argument context, so
508
+ * `PATH=a:~/bin` is literal there. Other positions retain the analyzer's
509
+ * conservative default, including tilde expansion after an unquoted colon.
510
+ * Explicit options are forwarded unchanged, even when empty.
493
511
  *
494
- * `options` is forwarded to `resolveWord` unchanged. When it is omitted, the
495
- * word's grammar position picks the tilde context: a word in a `CallExpr`'s
496
- * `args` uses `{ context: 'command-argument' }`, the context
497
- * `enumerateCommands` uses for argv, so `resolveWordText(callExpr.args[0])`
498
- * equals `getCommandName(callExpr)`. Any other word uses `resolveWord`'s
499
- * conservative default, which also treats a `~` after an unquoted `:` as a
500
- * tilde expansion, as assignment values do.
512
+ * @param word - A parsed Word from the lint view.
513
+ * @param options - Explicit analysis policy overriding grammar defaults.
514
+ * @returns Static text or the analyzer's reason the word is dynamic.
515
+ * @throws TypeError with `ESLINT_SH_WORD_NODE` when the word has no associated parsed shell syntax.
516
+ * @public
517
+ */
518
+ resolveWord(word, options) {
519
+ return resolveWord(word, options ?? this.#defaultWordOptions(word));
520
+ }
521
+ /**
522
+ * The text-only form of {@link ShellSourceCode.resolveWord}: returns its text
523
+ * exactly when static, otherwise `null`. Both methods share one policy path
524
+ * through `sh-analysis`.
501
525
  *
502
- * @param word - A parsed `Word` node from this file's lint tree.
503
- * @param options - Forwarded to `resolveWord` unchanged when supplied.
526
+ * @param word - A parsed Word from the lint view.
527
+ * @param options - Explicit analysis policy overriding grammar defaults.
504
528
  * @returns The resolved text, or `null` when the word is not static.
505
- * @throws TypeError when `word` is not a parsed shell `Word`.
529
+ * @throws TypeError with `ESLINT_SH_WORD_NODE` when `word` is not a parsed shell `Word`.
530
+ * @public
506
531
  */
507
532
  resolveWordText(word, options) {
508
- const resolution = resolveWord(word, options ?? this.#defaultWordOptions(word));
533
+ const resolution = this.resolveWord(word, options);
509
534
  return resolution.static ? resolution.text : null;
510
535
  }
511
536
  /**
@@ -525,7 +550,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
525
550
  * {@link ShellSourceCode.resolveInvokedCommand} for the command a wrapper
526
551
  * chain actually runs.
527
552
  *
528
- * Delegates to `sh-ast/analyze`: the answer is the `argv0` resolution of the
553
+ * Delegates to `sh-analysis`: the answer is the `argv0` resolution of the
529
554
  * `CommandSite` that `enumerateCommands` reports for this `CallExpr` in this
530
555
  * file. Leading `VAR=val` assignments are not part of argv, so
531
556
  * `FOO=1 jq .` yields `"jq"`. An assignment-only statement (`FOO=1`) has no
@@ -533,8 +558,8 @@ export class ShellSourceCode extends TextSourceCodeBase {
533
558
  *
534
559
  * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
535
560
  * @returns The command word's static text, or `null`.
536
- * @throws TypeError when `callExpr` is not a parsed shell `CallExpr`.
537
- * @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
561
+ * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
562
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
538
563
  * nesting exceeds analysis's recursion guard; see
539
564
  * {@link ShellSourceCode.resolveInvokedCommand}.
540
565
  */
@@ -544,7 +569,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
544
569
  }
545
570
  /**
546
571
  * Follows `callExpr`'s argv0 through transparent wrappers (`env`, `sudo`,
547
- * `nohup`, `exec`, …) and returns `sh-ast/analyze`'s full `resolveArgv0`
572
+ * `nohup`, `exec`, …) and returns `sh-analysis`'s full `resolveArgv0`
548
573
  * result, or `null` for a `CallExpr` that has no `CommandSite` (an
549
574
  * assignment-only statement such as `FOO=1`).
550
575
  *
@@ -558,7 +583,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
558
583
  * `embedded-command`; `chain`
559
584
  * lists every word resolved along the way, outermost wrapper first, and
560
585
  * `chainIndices` gives each entry's position in the command's `argv` (as
561
- * {@link ShellSourceCode.getCommandSites} reports it). When `effective` is
586
+ * {@link ShellSourceCode.getCommandInventory} reports it). When `effective` is
562
587
  * static, the effective command's arguments are
563
588
  * `argv.slice(chainIndices.at(-1)! + 1)`: every entry after the effective
564
589
  * command's own index. For an interpreter command string the final chain
@@ -576,14 +601,14 @@ export class ShellSourceCode extends TextSourceCodeBase {
576
601
  *
577
602
  * @param callExpr - A parsed `CallExpr` node from this file's lint tree.
578
603
  * @param options - Forwarded to `resolveArgv0` unchanged.
579
- * `transparentWrappers` replaces `sh-ast/analyze`'s
604
+ * `transparentWrappers` replaces `sh-analysis`'s
580
605
  * `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
581
606
  * extend them instead.
582
607
  * @returns The resolution, or `null` when `callExpr` invokes no command.
583
- * @throws TypeError when `callExpr` is not a parsed shell `CallExpr`.
584
- * @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
608
+ * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
609
+ * @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
585
610
  * nesting exceeds analysis's recursion guard.
586
- * @throws `ShAnalyzeInvalidWrapperSpecError` (from `sh-ast/analyze`) when
611
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
587
612
  * `options.transparentWrappers` contains a malformed entry.
588
613
  */
589
614
  resolveInvokedCommand(callExpr, options) {
@@ -591,38 +616,21 @@ export class ShellSourceCode extends TextSourceCodeBase {
591
616
  return site ? resolveArgv0(site, options) : null;
592
617
  }
593
618
  /**
594
- * Returns every command invocation in this file, one entry per
595
- * `sh-ast/analyze` `CommandSite`, in source order. Use it when a rule needs
596
- * the whole file's commands with their structural context, such as every
597
- * command inside a function or inside `$(…)`, instead of visiting
598
- * `CallExpr` nodes one by one.
599
- *
600
- * The data comes from `sh-ast/analyze`'s `enumerateCommands`: facts about
601
- * how each command is reached and what its words resolve to, never a
602
- * verdict. Each entry's `context`, `argv0`, and `argv` are analysis's own
603
- * values, unchanged; `context` lists frames outermost first, as in sh-ast.
604
- * Each entry's `node` is the `CallExpr` view node (`===` the node ESLint
605
- * passes to a `CallExpr` visitor), so it can be passed to
606
- * `context.report()`.
619
+ * Returns represented command sites and explicit opaque execution boundaries.
620
+ * Both retain original node identity in this file's UTF-16 ESLint view. This
621
+ * adapter maps sh-analysis observations without parsing text or choosing policy.
607
622
  *
608
- * An assignment-only statement (`FOO=1`) runs no command and has no entry,
609
- * although a command substitution in its value (`FOO=$(date)`) does.
623
+ * The inventory and observation data are frozen and shared across rules; view
624
+ * nodes retain ESLint's ordinary mutable-node contract. Enumeration runs once,
625
+ * lazily, shared with getCommandName and resolveInvokedCommand. Analysis errors
626
+ * propagate unchanged rather than returning a partial inventory.
610
627
  *
611
- * Enumeration runs at most once per file, shared with
612
- * {@link ShellSourceCode.getCommandName} and
613
- * {@link ShellSourceCode.resolveInvokedCommand}, and every call returns the
614
- * same array. Because every rule shares it, the array and everything in each
615
- * entry except `node` are deeply frozen (see `ShellCommandSite`): no rule can
616
- * change what another rule reads. If the file's nesting exceeds `enumerateCommands`'s
617
- * recursion guard, its `ShAnalyzeMaxDepthError` propagates unchanged, as it
618
- * does for those helpers: a partial list would silently omit real commands.
619
- *
620
- * @returns This file's command sites, in source order.
621
- * @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
622
- * nesting exceeds analysis's recursion guard.
628
+ * A known-command policy may inspect `commands`; any assertion of execution
629
+ * completeness must also account for `uncertainties` and its own dynamic-code
630
+ * assumptions. Empty commands with nonempty uncertainties never proves no execution.
623
631
  */
624
- getCommandSites() {
625
- this.#commandSiteViews ??= viewCommandSites(this.ast, this.#getCommandSiteIndex());
632
+ getCommandInventory() {
633
+ this.#commandSiteViews ??= viewCommandInventory(this.ast, this.#getCommandSiteIndex());
626
634
  return this.#commandSiteViews;
627
635
  }
628
636
  /**
@@ -632,7 +640,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
632
640
  * `Redirect.OpPos`. Pass those positions to
633
641
  * {@link ShellSourceCode.getIndexFromSyntaxPos} or
634
642
  * {@link ShellSourceCode.getLocFromSyntaxPos} to report on them, or pass the
635
- * record to an `sh-ast/analyze` function.
643
+ * record to an `sh-analysis` function.
636
644
  *
637
645
  * The returned record is read-only by contract. It is the language's
638
646
  * original parse, shared by every rule and helper linting this file, and
@@ -686,7 +694,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
686
694
  * printing"), so no second parse is involved. The copy owns its records,
687
695
  * arrays, positions and byte buffers. Editing it leaves this file's original
688
696
  * syntax, its lint view, its cached traversal and the answers of view-aware
689
- * helpers such as `resolveWord` and
697
+ * helpers such as {@link ShellSourceCode.resolveWord} and
690
698
  * {@link ShellSourceCode.resolveWordText} unchanged. Each call returns a new
691
699
  * copy.
692
700
  *
@@ -698,7 +706,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
698
706
  *
699
707
  * @param node - A view node from this file's lint tree.
700
708
  * @returns A deep copy of `node`'s original sh-ast record.
701
- * @throws TypeError when `node` has no original record in this file: an
709
+ * @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file: an
702
710
  * auxiliary view (such as the `Slice` of `${x:1:2}`), a view node of another
703
711
  * file, or an object that did not come from the parser.
704
712
  */
@@ -738,13 +746,14 @@ export class ShellSourceCode extends TextSourceCodeBase {
738
746
  * `Command` or `WordPart`.
739
747
  * @param options - Forwarded to `printSync` unchanged.
740
748
  * @returns The range to replace and the printed text to put there.
741
- * @throws TypeError when `node` has no original record in this file (see
749
+ * @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file (see
742
750
  * {@link ShellSourceCode.getEditableSyntax}), when `edited` is not a
743
- * printable root (the message names its type), or when the printer's output
744
- * is not valid UTF-8, or the edited syntax contains literal vertical tabs or
745
- * form feeds that the printer cannot preserve. Non-UTF-8 output comes back
751
+ * printable root (`ESLINT_SH_PRINT_ROOT`; the message names its type), or when the printer's output
752
+ * is not valid UTF-8 (`ESLINT_SH_PRINT_ENCODING`), or the edited syntax contains literal vertical tabs or
753
+ * form feeds that the printer cannot preserve (`ESLINT_SH_PRINT_UNSAFE_TEXT`). Non-UTF-8 output comes back
746
754
  * from `printSync` as a `Uint8Array` and is never decoded lossily into a fix.
747
- * @throws `PrintError` or `PrintPanicError` (from sh-ast) when upstream's
755
+ * @throws `PrintError` (`SH_AST_SYNTAX_PRINT`), `PrintPanicError` (`SH_AST_SYNTAX_PRINT_PANIC`),
756
+ * or `InputError` (`SH_AST_SYNTAX_INPUT`), passed through unchanged from sh-ast, when upstream's
748
757
  * printer fails for `edited` or `options`.
749
758
  */
750
759
  getPrintedReplacement(node, edited, options) {
@@ -754,8 +763,8 @@ export class ShellSourceCode extends TextSourceCodeBase {
754
763
  refusePrinterControlCharacters(root);
755
764
  const printed = printSync(root, options);
756
765
  if (typeof printed !== 'string') {
757
- throw new TypeError('printSync produced output that is not valid UTF-8; a text fix cannot hold it without ' +
758
- 'lossy decoding');
766
+ throw Object.assign(new TypeError('printSync produced output that is not valid UTF-8; a text fix cannot hold it without ' +
767
+ 'lossy decoding'), { code: 'ESLINT_SH_PRINT_ENCODING' });
759
768
  }
760
769
  if (rootType === 'File') {
761
770
  return { range: [0, this.text.length], text: printed };
@@ -777,8 +786,8 @@ export class ShellSourceCode extends TextSourceCodeBase {
777
786
  #originalSyntaxFor(node) {
778
787
  const syntax = this.getSyntax(node);
779
788
  if (syntax === undefined) {
780
- throw new TypeError('expected a view node parsed from this file; auxiliary views, view nodes of other ' +
781
- 'files and objects that did not come from the parser have no original syntax');
789
+ throw Object.assign(new TypeError('expected a view node parsed from this file; auxiliary views, view nodes of other ' +
790
+ 'files and objects that did not come from the parser have no original syntax'), { code: 'ESLINT_SH_FOREIGN_VIEW_NODE' });
782
791
  }
783
792
  return syntax;
784
793
  }
@@ -796,12 +805,12 @@ export class ShellSourceCode extends TextSourceCodeBase {
796
805
  *
797
806
  * @param pos - A `SyntaxPos` from one of this file's original records.
798
807
  * @returns The UTF-16 index of `pos` in this file's text.
799
- * @throws RangeError when `pos` is invalid (`IsValid === false`), recovered
808
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid (`IsValid === false`), recovered
800
809
  * (`IsRecovered === true`), or overflowed (`OffsetOverflow === true`), or
801
810
  * when its offset is not a UTF-8 character boundary of this source. Such a
802
811
  * position is never rounded to a nearby boundary.
803
- * @throws TypeError when `pos` is not a `SyntaxPos`, or when this source
804
- * code's tree was not built by this language's parser.
812
+ * @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
813
+ * code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
805
814
  */
806
815
  getIndexFromSyntaxPos(pos) {
807
816
  return this.#coordinateAt(pos).index;
@@ -814,10 +823,10 @@ export class ShellSourceCode extends TextSourceCodeBase {
814
823
  *
815
824
  * @param pos - A `SyntaxPos` from one of this file's original records.
816
825
  * @returns The one-based line and UTF-16 column of `pos`.
817
- * @throws RangeError when `pos` is invalid, recovered, or overflowed, or
826
+ * @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid, recovered, or overflowed, or
818
827
  * when its offset is not a UTF-8 character boundary of this source.
819
- * @throws TypeError when `pos` is not a `SyntaxPos`, or when this source
820
- * code's tree was not built by this language's parser.
828
+ * @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
829
+ * code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
821
830
  */
822
831
  getLocFromSyntaxPos(pos) {
823
832
  const { line, column } = this.#coordinateAt(pos);
@@ -831,7 +840,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
831
840
  #coordinateAt(pos) {
832
841
  const coordinates = projectedCoordinates(this.ast);
833
842
  if (coordinates === undefined) {
834
- throw new TypeError('expected a parsed shell File from this language adapter');
843
+ throw Object.assign(new TypeError('expected a parsed shell File from this language adapter'), { code: 'ESLINT_SH_FILE_NODE' });
835
844
  }
836
845
  return coordinates.fromByteOffset(exactByteOffset(pos));
837
846
  }
@@ -3,6 +3,8 @@
3
3
  * count bytes; this adapter derives UTF-16 indices and columns without replacing or
4
4
  * mutating the raw syntax position. Display widths, graphemes, and tab expansion
5
5
  * are deliberately outside this contract.
6
+ *
7
+ * ESLINT_SH_SOURCE_RANGE rejects an inexact or out-of-source boundary instead of inventing a location or edit range.
6
8
  */
7
9
  /** A source boundary expressed in JavaScript indexing and ESLint's one-based location convention. @internal */
8
10
  export interface ISourceCoordinate {
@@ -3,6 +3,8 @@
3
3
  * count bytes; this adapter derives UTF-16 indices and columns without replacing or
4
4
  * mutating the raw syntax position. Display widths, graphemes, and tab expansion
5
5
  * are deliberately outside this contract.
6
+ *
7
+ * ESLINT_SH_SOURCE_RANGE rejects an inexact or out-of-source boundary instead of inventing a location or edit range.
6
8
  */
7
9
  /**
8
10
  * Sentinel in the byte table for an offset that falls inside a multi-byte
@@ -69,14 +71,16 @@ export class SourceCoordinates {
69
71
  ? this.#byteIndices[offset]
70
72
  : INTERIOR_BYTE;
71
73
  if (index === INTERIOR_BYTE) {
72
- throw new RangeError(`byte offset ${String(offset)} is not a boundary in this source`);
74
+ throw Object.assign(new RangeError(`byte offset ${String(offset)} is not a boundary in this source`), { code: 'ESLINT_SH_SOURCE_RANGE' });
73
75
  }
74
76
  return this.atIndex(index);
75
77
  }
76
78
  /** Derive a one-based location from a known JavaScript source index. @internal */
77
79
  atIndex(index) {
78
80
  if (!Number.isInteger(index) || index < 0 || index > this.#length) {
79
- throw new RangeError(`UTF-16 index ${String(index)} is outside this source`);
81
+ throw Object.assign(new RangeError(`UTF-16 index ${String(index)} is outside this source`), {
82
+ code: 'ESLINT_SH_SOURCE_RANGE',
83
+ });
80
84
  }
81
85
  let low = 0;
82
86
  let high = this.#lineStarts.length;
@@ -100,12 +104,12 @@ export class SourceCoordinates {
100
104
  */
101
105
  indexAt(line, column) {
102
106
  if (!Number.isInteger(line) || line < 1 || line > this.#lineStarts.length) {
103
- throw new RangeError(`line ${String(line)} is outside this source (lines 1-${String(this.#lineStarts.length)})`);
107
+ throw Object.assign(new RangeError(`line ${String(line)} is outside this source (lines 1-${String(this.#lineStarts.length)})`), { code: 'ESLINT_SH_SOURCE_RANGE' });
104
108
  }
105
109
  const start = this.#lineStarts[line - 1];
106
110
  const last = line === this.#lineStarts.length ? this.#length : this.#lineStarts[line] - 1;
107
111
  if (!Number.isInteger(column) || column < 1 || start + column - 1 > last) {
108
- throw new RangeError(`column ${String(column)} is outside line ${String(line)} (columns 1-${String(last - start + 1)})`);
112
+ throw Object.assign(new RangeError(`column ${String(column)} is outside line ${String(line)} (columns 1-${String(last - start + 1)})`), { code: 'ESLINT_SH_SOURCE_RANGE' });
109
113
  }
110
114
  return start + column - 1;
111
115
  }
@@ -1,5 +1,5 @@
1
1
  import type { File, Node as SyntaxNode, PositionSnapshot } from 'sh-ast';
2
- import type { WordResolution } from 'sh-ast/analyze';
2
+ import type { WordResolution } from 'sh-analysis';
3
3
  import type { ShellNodeMap, ShellNodeOf, ShellNodeType } from './lint-view-types.js';
4
4
  import { SourceCoordinates } from './source-coordinates.js';
5
5
  /**
@@ -4,6 +4,8 @@
4
4
  * are consumer conventions; the original syntax remains untouched and associated
5
5
  * by identity. Bounds are observations of the original parse, tied to this exact
6
6
  * source. This is neither upstream Walk nor a replacement syntax model.
7
+ *
8
+ * ESLINT_SH_SYNTAX_VIEW identifies a record/snapshot invariant that prevents a faithful lint view; it never denotes invalid shell grammar.
7
9
  */
8
10
  import { SYNTAX_INTERFACES, SYNTAX_SCHEMA } from 'sh-ast';
9
11
  import { SourceCoordinates } from './source-coordinates.js';
@@ -122,7 +124,9 @@ function sourceText(value) {
122
124
  if (value instanceof Uint8Array) {
123
125
  return textDecoder.decode(value);
124
126
  }
125
- throw new TypeError('shell text view expected a Go string');
127
+ throw Object.assign(new TypeError('shell text view expected a Go string'), {
128
+ code: 'ESLINT_SH_SYNTAX_VIEW',
129
+ });
126
130
  }
127
131
  /**
128
132
  * Parser nodes whose view span was shortened by {@link endsBeforeCrlfNewline}.
@@ -177,7 +181,9 @@ export function withoutCrlfCarriageReturn(word, resolution) {
177
181
  */
178
182
  export function adaptSyntaxFile(file, source, positions) {
179
183
  if (!isRecord(positions) || typeof positions.get !== 'function') {
180
- throw new TypeError('shell view requires a source position snapshot');
184
+ throw Object.assign(new TypeError('shell view requires a source position snapshot'), {
185
+ code: 'ESLINT_SH_SYNTAX_VIEW',
186
+ });
181
187
  }
182
188
  const coordinates = new SourceCoordinates(source);
183
189
  const views = new WeakMap();
@@ -189,11 +195,15 @@ export function adaptSyntaxFile(file, source, positions) {
189
195
  /** Each projected record owns its derived fields, while real syntax nodes retain their original identity. */
190
196
  const project = (raw, fallback) => {
191
197
  if (!isRecord(raw) || typeof raw.Type !== 'string') {
192
- throw new TypeError('shell view expected a known upstream syntax record');
198
+ throw Object.assign(new TypeError('shell view expected a known upstream syntax record'), {
199
+ code: 'ESLINT_SH_SYNTAX_VIEW',
200
+ });
193
201
  }
194
202
  const plan = projectionPlans.get(raw.Type);
195
203
  if (plan === undefined) {
196
- throw new TypeError('shell view expected a known upstream syntax record');
204
+ throw Object.assign(new TypeError('shell view expected a known upstream syntax record'), {
205
+ code: 'ESLINT_SH_SYNTAX_VIEW',
206
+ });
197
207
  }
198
208
  const realNode = isSyntaxNode(raw);
199
209
  // eslint-disable-next-line @api-extractor-tools/forgotten-export -- This span belongs only to the private projection closure, not the exported signature.
@@ -203,7 +213,7 @@ export function adaptSyntaxFile(file, source, positions) {
203
213
  if (realNode) {
204
214
  const observed = positions.get(raw);
205
215
  if (observed === undefined) {
206
- throw new TypeError(`shell position snapshot has no observation for ${raw.Type}`);
216
+ throw Object.assign(new TypeError(`shell position snapshot has no observation for ${raw.Type}`), { code: 'ESLINT_SH_SYNTAX_VIEW' });
207
217
  }
208
218
  span = {
209
219
  start: position(observed.Pos, fallback.start),
@@ -235,7 +245,7 @@ export function adaptSyntaxFile(file, source, positions) {
235
245
  if (field.slice) {
236
246
  const items = value === null ? [] : value;
237
247
  if (!Array.isArray(items)) {
238
- throw new TypeError(`shell view expected ${raw.Type}.${field.name} to be a slice`);
248
+ throw Object.assign(new TypeError(`shell view expected ${raw.Type}.${field.name} to be a slice`), { code: 'ESLINT_SH_SYNTAX_VIEW' });
239
249
  }
240
250
  const projected = [];
241
251
  for (const item of items) {
@@ -278,7 +288,9 @@ export function adaptSyntaxFile(file, source, positions) {
278
288
  };
279
289
  const root = project(file, wholeSource);
280
290
  if (!isShellFile(root)) {
281
- throw new TypeError('shell view expected a File with statements');
291
+ throw Object.assign(new TypeError('shell view expected a File with statements'), {
292
+ code: 'ESLINT_SH_SYNTAX_VIEW',
293
+ });
282
294
  }
283
295
  projectedViews.set(root, views);
284
296
  projectedCommentsByRoot.set(root, comments);
@@ -1,12 +1,13 @@
1
- import type { ResolveWordOptions, WordResolution } from 'sh-ast/analyze';
1
+ import type { ResolveWordOptions, WordResolution } from 'sh-analysis';
2
2
  import type { ShellNodeOf } from './syntax-view.js';
3
3
  /**
4
4
  * Resolves a parsed lint Word using the upstream-shaped syntax associated with it.
5
- * The view supplies locations and selector fields; sh-ast/analyze owns the word
5
+ * The view supplies locations and selector fields; sh-analysis owns the word
6
6
  * interpretation. Fabricated or synthetic view nodes have no source syntax and
7
7
  * are rejected instead of being treated as known or unknown shell values.
8
8
  * A static word that ends a line of a CRLF file resolves without the line
9
9
  * terminator's carriage return, as it would on LF input.
10
- * @public
10
+ * @throws TypeError with `ESLINT_SH_WORD_NODE` for a word without original syntax.
11
+ * @internal
11
12
  */
12
13
  export declare function resolveWord(word: ShellNodeOf<'Word'>, options?: ResolveWordOptions): WordResolution;
@@ -1,19 +1,24 @@
1
- /** Bridges custom-rule analysis from ESLint view identity back to faithful syntax. */
2
- import { resolveWord as resolveSyntaxWord } from 'sh-ast/analyze';
1
+ /**
2
+ * Bridges lint-word identity to faithful syntax for source-code methods.
3
+ * ESLINT_SH_WORD_NODE rejects a missing source association; dynamic words
4
+ * remain ordinary analysis results rather than errors.
5
+ */
6
+ import { resolveWord as resolveSyntaxWord } from 'sh-analysis';
3
7
  import { syntaxForNode, withoutCrlfCarriageReturn } from './syntax-view.js';
4
8
  /**
5
9
  * Resolves a parsed lint Word using the upstream-shaped syntax associated with it.
6
- * The view supplies locations and selector fields; sh-ast/analyze owns the word
10
+ * The view supplies locations and selector fields; sh-analysis owns the word
7
11
  * interpretation. Fabricated or synthetic view nodes have no source syntax and
8
12
  * are rejected instead of being treated as known or unknown shell values.
9
13
  * A static word that ends a line of a CRLF file resolves without the line
10
14
  * terminator's carriage return, as it would on LF input.
11
- * @public
15
+ * @throws TypeError with `ESLINT_SH_WORD_NODE` for a word without original syntax.
16
+ * @internal
12
17
  */
13
18
  export function resolveWord(word, options) {
14
19
  const syntax = syntaxForNode(word);
15
20
  if (syntax?.Type !== 'Word') {
16
- throw new TypeError('resolveWord expects a parsed shell Word from this language adapter');
21
+ throw Object.assign(new TypeError('resolveWord expects a parsed shell Word from this language adapter'), { code: 'ESLINT_SH_WORD_NODE' });
17
22
  }
18
23
  return withoutCrlfCarriageReturn(syntax, resolveSyntaxWord(syntax, options));
19
24
  }
@@ -13,7 +13,7 @@
13
13
  * gating an option `local` shares (`-n`, `-l`, `-u`) adds `local` with
14
14
  * {@link DECLARATION_AND_LOCAL_COMMANDS}.
15
15
  */
16
- import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-ast/analyze';
16
+ import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
17
17
  import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
18
18
  import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
19
19
  /** The declaration commands that take option clusters. */
@@ -32,7 +32,7 @@ export const DECLARATION_AND_LOCAL_COMMANDS = new Set([
32
32
  ]);
33
33
  /**
34
34
  * The wrappers followed to find a declaration command written as an ordinary
35
- * command: `sh-ast/analyze`'s defaults (which include `command`) plus Bash's
35
+ * command: `sh-analysis`'s defaults (which include `command`) plus Bash's
36
36
  * `builtin`.
37
37
  */
38
38
  const TRANSPARENT_WRAPPERS = [
@@ -72,7 +72,7 @@
72
72
  * the whole word, once per word.
73
73
  */
74
74
  import { createCompatRule } from './create-compat-rule.js';
75
- import { DashHdoc, DplIn, DplOut, Hdoc, WordHdoc } from 'sh-ast/analyze';
75
+ import { DashHdoc, DplIn, DplOut, Hdoc, WordHdoc } from 'sh-ast';
76
76
  /** The sequence between braces: two endpoints and an optional step. */
77
77
  const SEQUENCE = /^([+-]?\d+|[A-Za-z])\.\.([+-]?\d+|[A-Za-z])(?:\.\.([+-]?\d+))?$/u;
78
78
  /**