@eslint-sh/eslint-plugin 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +41 -34
  2. package/dist/api.d.ts +92 -0
  3. package/dist/api.js +83 -0
  4. package/dist/command-harvest/harvest-commands.d.ts +2 -2
  5. package/dist/command-harvest/harvest-commands.js +2 -2
  6. package/dist/configs/posix-portable.d.ts +6 -10
  7. package/dist/configs/posix-portable.js +4 -6
  8. package/dist/configuration-message.d.ts +14 -0
  9. package/dist/configuration-message.js +33 -0
  10. package/dist/declaration-conventions/get-declared-commands.d.ts +41 -0
  11. package/dist/declaration-conventions/{read-declared-commands.js → get-declared-commands.js} +43 -43
  12. package/dist/eslint-plugin-api.d.ts +1506 -0
  13. package/dist/eslint-plugin-syntax-analyze.d.ts +3 -3
  14. package/dist/eslint-plugin-syntax.d.ts +3 -4
  15. package/dist/eslint-plugin.d.ts +16 -1560
  16. package/dist/index.d.ts +14 -81
  17. package/dist/index.js +22 -76
  18. package/dist/language/command-resolution.d.ts +5 -5
  19. package/dist/language/command-resolution.js +11 -7
  20. package/dist/language/selector-classes.d.ts +7 -3
  21. package/dist/language/selector-classes.js +13 -4
  22. package/dist/language/shell-language-options.d.ts +3 -3
  23. package/dist/language/shell-language-options.js +12 -17
  24. package/dist/language/shell-language.d.ts +3 -1
  25. package/dist/language/shell-language.js +6 -11
  26. package/dist/language/shell-source-code.d.ts +59 -42
  27. package/dist/language/shell-source-code.js +86 -60
  28. package/dist/language/source-coordinates.d.ts +2 -0
  29. package/dist/language/source-coordinates.js +8 -4
  30. package/dist/language/syntax-view.js +19 -7
  31. package/dist/language/word-resolution.d.ts +2 -1
  32. package/dist/language/word-resolution.js +8 -3
  33. package/dist/rules/create-wrapper-rule.d.ts +1 -1
  34. package/dist/rules/create-wrapper-rule.js +11 -9
  35. package/dist/rules/define-shell-rule.js +1 -1
  36. package/dist/rules/no-masked-exit-status.d.ts +4 -3
  37. package/dist/rules/no-masked-exit-status.js +3 -2
  38. package/dist/rules/no-secret-env-reads.d.ts +2 -0
  39. package/dist/rules/no-secret-env-reads.js +13 -2
  40. package/dist/rules/no-secret-flags.d.ts +2 -0
  41. package/dist/rules/no-secret-flags.js +14 -3
  42. package/dist/rules/no-unchecked-cd.js +3 -2
  43. package/dist/rules/no-undeclared-commands.js +8 -3
  44. package/dist/rules/no-unused-declarations.js +6 -2
  45. package/dist/rules/prefer-local.d.ts +3 -2
  46. package/dist/rules/prefer-local.js +4 -2
  47. package/dist/rules/require-network-wrapper.d.ts +1 -1
  48. package/dist/rules/require-network-wrapper.js +11 -7
  49. package/dist/rules/require-strict-mode.d.ts +5 -46
  50. package/dist/rules/require-strict-mode.js +17 -107
  51. package/dist/rules/require-tty-guard.d.ts +2 -0
  52. package/dist/rules/require-tty-guard.js +8 -1
  53. package/dist/rules/resolve-declaration-convention.d.ts +9 -88
  54. package/dist/rules/resolve-declaration-convention.js +19 -71
  55. package/dist/rules/resolve-network-wrapper.d.ts +1 -2
  56. package/dist/rules/resolve-network-wrapper.js +18 -14
  57. package/dist/rules/resolve-transparent-wrappers.d.ts +2 -7
  58. package/dist/rules/resolve-transparent-wrappers.js +19 -9
  59. package/dist/rules/set-options.d.ts +1 -1
  60. package/dist/rules/set-options.js +1 -1
  61. package/dist/rules/strict-mode-prologue.d.ts +43 -0
  62. package/dist/rules/strict-mode-prologue.js +91 -0
  63. package/dist/rules/user-pattern.d.ts +4 -3
  64. package/dist/rules/user-pattern.js +10 -8
  65. package/dist/shell-dialect.d.ts +8 -0
  66. package/dist/shell-dialect.js +22 -0
  67. package/dist/syntax/analyze.d.ts +3 -3
  68. package/dist/syntax/analyze.js +3 -3
  69. package/dist/syntax/index.d.ts +3 -4
  70. package/dist/syntax/index.js +3 -4
  71. package/dist/version.js +2 -1
  72. package/docs/compat.md +5 -6
  73. package/docs/custom-rule-tutorial.md +22 -18
  74. package/docs/declaration-conventions.md +20 -23
  75. package/docs/error-codes.md +93 -0
  76. package/docs/examples/no-rm-rf-rule.mjs +8 -10
  77. package/docs/examples/sorted-declarations-rule.mjs +6 -9
  78. package/docs/examples/tsconfig.json +10 -0
  79. package/docs/rules/README.md +12 -4
  80. package/docs/rules/compat/no-nounset-empty-array.md +1 -1
  81. package/docs/rules/no-masked-exit-status.md +2 -2
  82. package/docs/rules/no-secret-env-reads.md +13 -3
  83. package/docs/rules/no-secret-flags.md +14 -5
  84. package/docs/rules/no-unchecked-cd.md +15 -2
  85. package/docs/rules/require-network-wrapper.md +5 -5
  86. package/docs/rules/require-strict-mode.md +25 -23
  87. package/docs/rules/require-tty-guard.md +12 -3
  88. package/docs/selectors.md +7 -2
  89. package/docs/wrapper-rules.md +2 -0
  90. package/package.json +3 -3
  91. package/dist/declaration-conventions/read-declared-commands.d.ts +0 -70
package/dist/index.d.ts CHANGED
@@ -1,85 +1,18 @@
1
- /** Exposes the ESLint language, source view, and rule-author helpers as one plugin boundary. */
2
- import type { ConfigObject } from '@eslint/core';
3
- import { ShellLanguage } from './language/shell-language.js';
4
- export { ShellLanguage } from './language/shell-language.js';
5
- export { ShellSourceCode } from './language/shell-source-code.js';
6
- export type { NormalizedShellLanguageOptions, ShellLanguageOptions, ShellLanguageOptionsJSON, } from './language/shell-language-options.js';
7
- export { resolveWord } from './language/word-resolution.js';
8
- export type { Argv0Resolution } from 'sh-ast/analyze';
9
- export type { CommandContext, ResolveArgv0Options, WordResolution } from 'sh-ast/analyze';
10
- export type { ShellCommandSite } from './language/command-resolution.js';
11
- export type { ShellComment, ShellFile, ShellNode, ShellNodeField, ShellNodeMap, ShellNodeOf, ShellNodeType, ShellPosition, } from './language/syntax-view.js';
12
- export type { ShellDialect } from './language/shell-language-options.js';
13
- export type { DeclarationConvention, DeclaredCommand, FileDeclaredCommand, LintedFile, DescribedDeclaredCommand, ScriptDeclaredCommand, } from './declaration-conventions/declaration-convention.js';
14
- export { readDeclaredCommands } from './declaration-conventions/read-declared-commands.js';
15
- export type { DeclarationReadContext } from './declaration-conventions/read-declared-commands.js';
16
- export { commentPragma } from './declaration-conventions/comment-pragma.js';
17
- export { resolveTransparentWrappers } from './rules/resolve-transparent-wrappers.js';
18
- export type { TransparentWrappersBindingContext } from './rules/resolve-transparent-wrappers.js';
19
- export { resolveDeclarationConvention } from './rules/resolve-declaration-convention.js';
20
- export type { DeclarationConventionBindingContext } from './rules/resolve-declaration-convention.js';
21
- export { defineShellRule } from './rules/define-shell-rule.js';
22
- export type { ShellListener, ShellRule, ShellRuleContext, ShellRuleMeta, ShellRuleSpec, ShellRuleVisitor, ShellTypedListeners, } from './rules/define-shell-rule.js';
23
- export { createWrapperRule } from './rules/create-wrapper-rule.js';
24
- export type { WrapperRuleConfig, WrapperRuleLocalInvocation, WrapperRuleLocalOperand, WrapperRuleSubcommands, } from './rules/create-wrapper-rule.js';
25
- export type { WrapperSpec } from 'sh-ast/analyze';
26
1
  /**
27
- * The `@eslint-sh/eslint-plugin` plugin object, this package's default
28
- * export (`import sh from '@eslint-sh/eslint-plugin'`). `languages.sh` provides
29
- * `ShellLanguage` / `ShellSourceCode`, selected in a flat config via
30
- * `language: "sh/sh"` (`namespace: "sh"`). `meta.version` is read from this
31
- * package's own `package.json` at runtime — never hardcoded (see
32
- * `version.ts`).
33
- *
34
- * `rules` holds the plugin's built-in rules, each built with
35
- * `defineShellRule` (so each declares `meta.languages: ["sh/sh"]`) and
36
- * linking its docs page from `meta.docs.url`. Consumers can also supply their
37
- * own rules, built with the same `defineShellRule`, while sharing parsing,
38
- * selectors, source coordinates, and directive semantics.
39
- *
40
- * `configs.recommended` is the `sh/recommended` preset: a single config
41
- * object carrying `plugins: { sh }` and `language: "sh/sh"` but no `files`,
42
- * so it inherits the globs of the entry that extends it:
43
- * `{ files: [...], extends: [sh.configs.recommended] }`. It enables the
44
- * convention-free policy rules. The rules index at
45
- * https://github.com/mike-north/eslint-sh/blob/main/packages/eslint-plugin/docs/rules/README.md
46
- * describes preset membership and available autofixes.
47
- * `configs['agent-authored']` is the strict `sh/agent-authored` preset for
48
- * machine-written, human-reviewed scripts:
49
- * every `recommended` rule plus the contract rules, all at `error`.
50
- * `configs['bash-3.2']` and `configs['posix-portable']` are deployment-target
51
- * packs: the first sets `languageOptions.minBashVersion: "3.2"` and enables
52
- * the version-gated `compat/*` rules except the opt-in
53
- * `compat/no-nounset-empty-array`; the second sets
54
- * `languageOptions.dialect: "posix"`, enables the `compat/*` rules and the
55
- * shebang/dialect check, and requires `set -eu`; it reports named constructs
56
- * that fail on dash, not every non-POSIX construct, and leaves `local`,
57
- * `echo -e` and the rest of shellcheck's SC3xxx catalog to shellcheck. Every
58
- * shipped config is a
59
- * single object with no `files`; the two packs also carry `languageOptions`,
60
- * because the target they name is their meaning.
61
- *
62
- * Re-exported, unchanged, as the default export of the `eslint-sh` umbrella
63
- * package: importing this package or the umbrella package both yield the
64
- * same plugin object.
2
+ * Node's CommonJS entry uses the same plugin as ESM and every preset. Helpers
3
+ * remain non-enumerable so ESLint's plugin/config traversal sees only plugin
4
+ * data, while existing namespace-style require properties retain their identity.
5
+ * API Extractor reads api.ts instead: it cannot represent quoted export names.
6
+ */
7
+ import plugin, * as api from './api.js';
8
+ export { default } from './api.js';
9
+ export * from './api.js';
10
+ /**
11
+ * The require(ESM) result is the plugin itself, augmented with the ESM namespace's
12
+ * default and named values. This assertion describes the properties installed
13
+ * above; it neither wraps nor copies the plugin, preserving preset identity.
65
14
  *
66
15
  * @public
67
16
  */
68
- declare const plugin: {
69
- meta: {
70
- name: string;
71
- version: string;
72
- namespace: string;
73
- };
74
- languages: {
75
- sh: ShellLanguage;
76
- };
77
- rules: Record<string, import("@eslint/core").RuleDefinition<import("@eslint/core").RuleDefinitionTypeOptions>>;
78
- configs: {
79
- recommended: ConfigObject;
80
- "agent-authored": ConfigObject;
81
- "bash-3.2": ConfigObject;
82
- "posix-portable": ConfigObject;
83
- };
84
- };
85
- export default plugin;
17
+ declare const commonJsModule: typeof plugin & Readonly<typeof api>;
18
+ export { commonJsModule as 'module.exports' };
package/dist/index.js CHANGED
@@ -1,80 +1,26 @@
1
- import { createAgentAuthoredConfig } from './configs/agent-authored.js';
2
- import { createBash32Config } from './configs/bash-3-2.js';
3
- import { createPosixPortableConfig } from './configs/posix-portable.js';
4
- import { createRecommendedConfig } from './configs/recommended.js';
5
- import { ShellLanguage } from './language/shell-language.js';
6
- import { rules } from './rules/index.js';
7
- import { readPackageVersion } from './version.js';
8
- export { ShellLanguage } from './language/shell-language.js';
9
- export { ShellSourceCode } from './language/shell-source-code.js';
10
- export { resolveWord } from './language/word-resolution.js';
11
- export { readDeclaredCommands } from './declaration-conventions/read-declared-commands.js';
12
- export { commentPragma } from './declaration-conventions/comment-pragma.js';
13
- export { resolveTransparentWrappers } from './rules/resolve-transparent-wrappers.js';
14
- export { resolveDeclarationConvention } from './rules/resolve-declaration-convention.js';
15
- export { defineShellRule } from './rules/define-shell-rule.js';
16
- export { createWrapperRule } from './rules/create-wrapper-rule.js';
17
- /* eslint-disable @api-extractor-tools/public-on-non-exported -- `plugin` is exported below as
18
- `export default plugin`; the rule only recognizes inline exports. */
19
1
  /**
20
- * The `@eslint-sh/eslint-plugin` plugin object, this package's default
21
- * export (`import sh from '@eslint-sh/eslint-plugin'`). `languages.sh` provides
22
- * `ShellLanguage` / `ShellSourceCode`, selected in a flat config via
23
- * `language: "sh/sh"` (`namespace: "sh"`). `meta.version` is read from this
24
- * package's own `package.json` at runtime — never hardcoded (see
25
- * `version.ts`).
26
- *
27
- * `rules` holds the plugin's built-in rules, each built with
28
- * `defineShellRule` (so each declares `meta.languages: ["sh/sh"]`) and
29
- * linking its docs page from `meta.docs.url`. Consumers can also supply their
30
- * own rules, built with the same `defineShellRule`, while sharing parsing,
31
- * selectors, source coordinates, and directive semantics.
32
- *
33
- * `configs.recommended` is the `sh/recommended` preset: a single config
34
- * object carrying `plugins: { sh }` and `language: "sh/sh"` but no `files`,
35
- * so it inherits the globs of the entry that extends it:
36
- * `{ files: [...], extends: [sh.configs.recommended] }`. It enables the
37
- * convention-free policy rules. The rules index at
38
- * https://github.com/mike-north/eslint-sh/blob/main/packages/eslint-plugin/docs/rules/README.md
39
- * describes preset membership and available autofixes.
40
- * `configs['agent-authored']` is the strict `sh/agent-authored` preset for
41
- * machine-written, human-reviewed scripts:
42
- * every `recommended` rule plus the contract rules, all at `error`.
43
- * `configs['bash-3.2']` and `configs['posix-portable']` are deployment-target
44
- * packs: the first sets `languageOptions.minBashVersion: "3.2"` and enables
45
- * the version-gated `compat/*` rules except the opt-in
46
- * `compat/no-nounset-empty-array`; the second sets
47
- * `languageOptions.dialect: "posix"`, enables the `compat/*` rules and the
48
- * shebang/dialect check, and requires `set -eu`; it reports named constructs
49
- * that fail on dash, not every non-POSIX construct, and leaves `local`,
50
- * `echo -e` and the rest of shellcheck's SC3xxx catalog to shellcheck. Every
51
- * shipped config is a
52
- * single object with no `files`; the two packs also carry `languageOptions`,
53
- * because the target they name is their meaning.
54
- *
55
- * Re-exported, unchanged, as the default export of the `eslint-sh` umbrella
56
- * package: importing this package or the umbrella package both yield the
57
- * same plugin object.
2
+ * Node's CommonJS entry uses the same plugin as ESM and every preset. Helpers
3
+ * remain non-enumerable so ESLint's plugin/config traversal sees only plugin
4
+ * data, while existing namespace-style require properties retain their identity.
5
+ * API Extractor reads api.ts instead: it cannot represent quoted export names.
6
+ */
7
+ import plugin, * as api from './api.js';
8
+ export { default } from './api.js';
9
+ export * from './api.js';
10
+ for (const [name, value] of Object.entries(api)) {
11
+ Object.defineProperty(plugin, name, {
12
+ value,
13
+ enumerable: false,
14
+ writable: false,
15
+ configurable: false,
16
+ });
17
+ }
18
+ /**
19
+ * The require(ESM) result is the plugin itself, augmented with the ESM namespace's
20
+ * default and named values. This assertion describes the properties installed
21
+ * above; it neither wraps nor copies the plugin, preserving preset identity.
58
22
  *
59
23
  * @public
60
24
  */
61
- const plugin = {
62
- meta: {
63
- name: '@eslint-sh/eslint-plugin',
64
- version: readPackageVersion(),
65
- namespace: 'sh',
66
- },
67
- languages: {
68
- sh: new ShellLanguage(),
69
- },
70
- rules,
71
- // Filled in below: each shipped config registers this very object under
72
- // `plugins.sh`, so the plugin must exist before its configs can.
73
- configs: {},
74
- };
75
- /* eslint-enable @api-extractor-tools/public-on-non-exported */
76
- plugin.configs.recommended = createRecommendedConfig(plugin);
77
- plugin.configs['agent-authored'] = createAgentAuthoredConfig(plugin);
78
- plugin.configs['bash-3.2'] = createBash32Config(plugin);
79
- plugin.configs['posix-portable'] = createPosixPortableConfig(plugin);
80
- export default plugin;
25
+ const commonJsModule = plugin;
26
+ export { commonJsModule as 'module.exports' };
@@ -70,7 +70,7 @@ export interface ShellCommandSite {
70
70
  * @returns A new result on every call. Its `chain` and `chainIndices`
71
71
  * arrays belong to the caller. `chainIndices` gives each chain entry's
72
72
  * position in this site's `argv`.
73
- * @throws `ShAnalyzeInvalidWrapperSpecError` (from `sh-ast/analyze`) when
73
+ * @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
74
74
  * `options.transparentWrappers` contains a malformed entry.
75
75
  */
76
76
  resolveInvokedCommand(options?: ResolveArgv0Options): Argv0Resolution;
@@ -91,8 +91,8 @@ export interface ShellCommandSite {
91
91
  * sibling commands. So every site is frozen in place here, before any rule
92
92
  * can see it (see {@link freezeCommandSite}).
93
93
  *
94
- * @throws TypeError when `file` has no associated parsed syntax.
95
- * @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when the file's
94
+ * @throws TypeError with `ESLINT_SH_FILE_NODE` when `file` has no associated parsed syntax.
95
+ * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
96
96
  * nesting exceeds analysis's recursion guard. It propagates unchanged: a
97
97
  * partial index would silently omit real commands, so callers fail closed.
98
98
  * @internal
@@ -107,7 +107,7 @@ export declare function buildCommandSiteIndex(file: ShellFile): CommandSiteIndex
107
107
  * when the index was built: the same array is shared by every rule linting
108
108
  * this file.
109
109
  *
110
- * @throws Error when a site's `CallExpr` has no view node in `file`. Analysis
110
+ * @throws Error with `ESLINT_SH_COMMAND_SITE_VIEW` when a site's `CallExpr` has no view node in `file`. Analysis
111
111
  * of the same parse only reports parser nodes the projection saw, so this
112
112
  * marks a broken invariant rather than a shell construct; failing loudly is
113
113
  * safer than silently dropping a command.
@@ -117,7 +117,7 @@ export declare function viewCommandSites(file: ShellFile, index: CommandSiteInde
117
117
  /**
118
118
  * Returns the parser's own `CallExpr` behind a lint `CallExpr`.
119
119
  *
120
- * @throws TypeError when `callExpr` is not a parsed `CallExpr` from this
120
+ * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed `CallExpr` from this
121
121
  * language adapter (a fabricated or synthetic view node has no syntax).
122
122
  * @internal
123
123
  */
@@ -5,6 +5,8 @@
5
5
  * analysis reports, maps a lint `CallExpr` to its raw syntax node, and maps
6
6
  * each site's raw `CallExpr` forward to its lint view node, so every rule gets
7
7
  * the analysis answer rather than a local reinterpretation.
8
+ *
9
+ * ESLINT_SH_FILE_NODE and ESLINT_SH_CALL_NODE reject missing syntax associations. ESLINT_SH_COMMAND_SITE_VIEW rejects a site from a different file; analysis resource and wrapper failures propagate unchanged.
8
10
  */
9
11
  import { enumerateCommands, resolveArgv0 } from 'sh-ast/analyze';
10
12
  import { syntaxForNode, viewForSyntax, withoutCrlfCarriageReturn } from './syntax-view.js';
@@ -24,8 +26,8 @@ import { syntaxForNode, viewForSyntax, withoutCrlfCarriageReturn } from './synta
24
26
  * sibling commands. So every site is frozen in place here, before any rule
25
27
  * can see it (see {@link freezeCommandSite}).
26
28
  *
27
- * @throws TypeError when `file` has no associated parsed syntax.
28
- * @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when the file's
29
+ * @throws TypeError with `ESLINT_SH_FILE_NODE` when `file` has no associated parsed syntax.
30
+ * @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
29
31
  * nesting exceeds analysis's recursion guard. It propagates unchanged: a
30
32
  * partial index would silently omit real commands, so callers fail closed.
31
33
  * @internal
@@ -33,7 +35,9 @@ import { syntaxForNode, viewForSyntax, withoutCrlfCarriageReturn } from './synta
33
35
  export function buildCommandSiteIndex(file) {
34
36
  const syntax = syntaxForNode(file);
35
37
  if (syntax?.Type !== 'File') {
36
- throw new TypeError('expected a parsed shell File from this language adapter');
38
+ throw Object.assign(new TypeError('expected a parsed shell File from this language adapter'), {
39
+ code: 'ESLINT_SH_FILE_NODE',
40
+ });
37
41
  }
38
42
  const sites = Object.freeze(enumerateCommands(syntax).map((site) => freezeCommandSite(withLfArgv(site))));
39
43
  return { sites, byNode: new Map(sites.map((site) => [site.node, site])) };
@@ -83,7 +87,7 @@ function freezeCommandSite(site) {
83
87
  * when the index was built: the same array is shared by every rule linting
84
88
  * this file.
85
89
  *
86
- * @throws Error when a site's `CallExpr` has no view node in `file`. Analysis
90
+ * @throws Error with `ESLINT_SH_COMMAND_SITE_VIEW` when a site's `CallExpr` has no view node in `file`. Analysis
87
91
  * of the same parse only reports parser nodes the projection saw, so this
88
92
  * marks a broken invariant rather than a shell construct; failing loudly is
89
93
  * safer than silently dropping a command.
@@ -93,7 +97,7 @@ export function viewCommandSites(file, index) {
93
97
  return Object.freeze(index.sites.map((site) => {
94
98
  const node = viewForSyntax(file, site.node);
95
99
  if (node?.type !== 'CallExpr') {
96
- throw new Error('command site has no CallExpr in the lint view of this file');
100
+ throw Object.assign(new Error('command site has no CallExpr in the lint view of this file'), { code: 'ESLINT_SH_COMMAND_SITE_VIEW' });
97
101
  }
98
102
  return Object.freeze({
99
103
  node,
@@ -107,14 +111,14 @@ export function viewCommandSites(file, index) {
107
111
  /**
108
112
  * Returns the parser's own `CallExpr` behind a lint `CallExpr`.
109
113
  *
110
- * @throws TypeError when `callExpr` is not a parsed `CallExpr` from this
114
+ * @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed `CallExpr` from this
111
115
  * language adapter (a fabricated or synthetic view node has no syntax).
112
116
  * @internal
113
117
  */
114
118
  export function rawCallExprFor(callExpr) {
115
119
  const syntax = syntaxForNode(callExpr);
116
120
  if (syntax?.Type !== 'CallExpr') {
117
- throw new TypeError('expected a parsed shell CallExpr from this language adapter');
121
+ throw Object.assign(new TypeError('expected a parsed shell CallExpr from this language adapter'), { code: 'ESLINT_SH_CALL_NODE' });
118
122
  }
119
123
  return syntax;
120
124
  }
@@ -1,7 +1,11 @@
1
1
  import type { ShellNode as ShNode } from './syntax-view.js';
2
2
  /**
3
- * The six launch esquery selector classes `ShellLanguage.matchesSelectorClass`
4
- * implements. Keys are the *bare* class name —
3
+ * Candidate node types for the six launch esquery selector classes
4
+ * `ShellLanguage.matchesSelectorClass` implements. `:command` additionally
5
+ * requires a command word: a `CallExpr` with nonempty `args` has a command
6
+ * site, including when that word is dynamic. Assignment-only calls such as
7
+ * `FOO=1` have no site; consumers wanting every call select `CallExpr` directly.
8
+ * Keys are the *bare* class name —
5
9
  * esquery strips the leading `:` before invoking a language's
6
10
  * `matchesSelectorClass` (confirmed against `esquery`'s own `case 'class'`
7
11
  * matcher, which calls `options.matchClass(selector.name, node, ancestry)`
@@ -41,7 +45,7 @@ export type SelectorClassName = keyof typeof SELECTOR_CLASS_NODE_TYPES;
41
45
  /**
42
46
  * Implements the matching behavior behind `ShellLanguage.matchesSelectorClass`
43
47
  * (`@eslint/core`'s `Language.matchesSelectorClass`): `true` when `node`'s
44
- * `type` belongs to the named launch class, `false` for every other node
48
+ * construct belongs to the named launch class, `false` for every other node
45
49
  * type (including the five other launch classes' node types) and for any
46
50
  * unrecognized `className` (a class name this language does not define —
47
51
  * per the `Language` contract, an unknown class simply never matches,
@@ -1,6 +1,10 @@
1
1
  /**
2
- * The six launch esquery selector classes `ShellLanguage.matchesSelectorClass`
3
- * implements. Keys are the *bare* class name —
2
+ * Candidate node types for the six launch esquery selector classes
3
+ * `ShellLanguage.matchesSelectorClass` implements. `:command` additionally
4
+ * requires a command word: a `CallExpr` with nonempty `args` has a command
5
+ * site, including when that word is dynamic. Assignment-only calls such as
6
+ * `FOO=1` have no site; consumers wanting every call select `CallExpr` directly.
7
+ * Keys are the *bare* class name —
4
8
  * esquery strips the leading `:` before invoking a language's
5
9
  * `matchesSelectorClass` (confirmed against `esquery`'s own `case 'class'`
6
10
  * matcher, which calls `options.matchClass(selector.name, node, ancestry)`
@@ -30,7 +34,7 @@ export const SELECTOR_CLASS_NODE_TYPES = {
30
34
  quoted: ['SglQuoted', 'DblQuoted'],
31
35
  function: ['FuncDecl'],
32
36
  };
33
- /** Membership is independent of syntax field values or source positions. */
37
+ /** Candidate types are shared across matches; command-word presence is checked per node. */
34
38
  const nodeTypesByClassName = new Map(Object.entries(SELECTOR_CLASS_NODE_TYPES).map(([className, nodeTypes]) => [
35
39
  className,
36
40
  new Set(nodeTypes),
@@ -38,7 +42,7 @@ const nodeTypesByClassName = new Map(Object.entries(SELECTOR_CLASS_NODE_TYPES).m
38
42
  /**
39
43
  * Implements the matching behavior behind `ShellLanguage.matchesSelectorClass`
40
44
  * (`@eslint/core`'s `Language.matchesSelectorClass`): `true` when `node`'s
41
- * `type` belongs to the named launch class, `false` for every other node
45
+ * construct belongs to the named launch class, `false` for every other node
42
46
  * type (including the five other launch classes' node types) and for any
43
47
  * unrecognized `className` (a class name this language does not define —
44
48
  * per the `Language` contract, an unknown class simply never matches,
@@ -47,5 +51,10 @@ const nodeTypesByClassName = new Map(Object.entries(SELECTOR_CLASS_NODE_TYPES).m
47
51
  * @public
48
52
  */
49
53
  export function matchesSelectorClass(className, node) {
54
+ // A command site exists exactly when a call has a command word. Its name
55
+ // need not be statically known, and assignments before it do not remove it.
56
+ if (className === 'command') {
57
+ return node.type === 'CallExpr' && node.args.length > 0;
58
+ }
50
59
  return nodeTypesByClassName.get(className)?.has(node.type) ?? false;
51
60
  }
@@ -1,6 +1,5 @@
1
- /** Owns ESLint configuration labels and validates their consumer-facing meaning before parsing. */
2
- /** The dialect labels understood by ESLint configuration, mapped to upstream numeric variants when parsing. @public */
3
- export type ShellDialect = 'bash' | 'posix' | 'mksh' | 'bats' | 'zsh';
1
+ import type { ShellDialect } from '../shell-dialect.js';
2
+ export type { ShellDialect } from '../shell-dialect.js';
4
3
  /**
5
4
  * `languageOptions` accepted by {@link ShellLanguage}: `dialect` selects
6
5
  * mvdan/sh's `LangVariant` through a consumer-owned mapping (default `"bash"`); `minBashVersion`
@@ -95,6 +94,7 @@ export interface NormalizedShellLanguageOptions extends Record<string, unknown>
95
94
  * this function's entire job is validating an untrusted boundary: the
96
95
  * caller-supplied object may not actually match the declared shape.
97
96
  *
97
+ * @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
98
98
  * @public
99
99
  */
100
100
  export declare function validateShellLanguageOptions(languageOptions: Record<string, unknown>): void;
@@ -1,14 +1,6 @@
1
- /**
2
- * The full set of dialects {@link ShellLanguage.validateLanguageOptions}
3
- * accepts, in the order surfaced by its error message. Mirrors
4
- * the consumer's configuration labels; the syntax interface itself accepts
5
- * upstream numeric constants rather than these configuration strings.
6
- */
7
- const SUPPORTED_SHELL_DIALECTS = ['bash', 'posix', 'mksh', 'bats', 'zsh'];
8
- /** Narrows configuration labels without treating arbitrary strings as parser variants. */
9
- function isShellDialect(value) {
10
- return (typeof value === 'string' && SUPPORTED_SHELL_DIALECTS.includes(value));
11
- }
1
+ /** Validates ESLint-specific language options before parsing; shared vocabulary owns the grammar labels. */
2
+ import { configurationMessage } from '../configuration-message.js';
3
+ import { isShellDialect, SUPPORTED_SHELL_DIALECTS } from '../shell-dialect.js';
12
4
  /**
13
5
  * Default for {@link ShellLanguageOptions.directivePrefix} — the
14
6
  * ESLint-conventional spelling. The directive prefix is configurable but
@@ -57,32 +49,35 @@ function isValidMinBashVersionShape(value) {
57
49
  * this function's entire job is validating an untrusted boundary: the
58
50
  * caller-supplied object may not actually match the declared shape.
59
51
  *
52
+ * @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
60
53
  * @public
61
54
  */
62
55
  export function validateShellLanguageOptions(languageOptions) {
56
+ // ESLINT_SH_LANGUAGE_OPTION means a project language option cannot be honored,
57
+ // including combinations whose individual values would otherwise be valid.
63
58
  // A removed key must not disappear during normalization: that would
64
59
  // silently disable the consumer's compatibility requirement.
65
60
  if ('shellVersion' in languageOptions) {
66
- throw new TypeError('@eslint-sh/eslint-plugin: languageOptions.shellVersion has been removed. Use languageOptions.minBashVersion with dialect "bash" or "bats" instead.');
61
+ throw Object.assign(new TypeError(configurationMessage('languageOptions.shellVersion', 'has been removed; use languageOptions.minBashVersion with dialect "bash" or "bats" instead', languageOptions.shellVersion)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
67
62
  }
68
63
  const { dialect, minBashVersion, directivePrefix } = languageOptions;
69
64
  if (dialect !== undefined && !isShellDialect(dialect)) {
70
- throw new TypeError(`@eslint-sh/eslint-plugin: languageOptions.dialect must be one of ${SUPPORTED_SHELL_DIALECTS.join(', ')}; received ${JSON.stringify(dialect)}.`);
65
+ throw Object.assign(new TypeError(configurationMessage('languageOptions.dialect', `must be one of ${SUPPORTED_SHELL_DIALECTS.join(', ')}`, dialect)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
71
66
  }
72
67
  if (minBashVersion !== undefined &&
73
68
  dialect !== undefined &&
74
69
  dialect !== 'bash' &&
75
70
  dialect !== 'bats') {
76
- throw new TypeError(`@eslint-sh/eslint-plugin: languageOptions.minBashVersion applies only to bash and bats; dialect is "${dialect}". Remove minBashVersion or set dialect to "bash" or "bats".`);
71
+ throw Object.assign(new TypeError(configurationMessage('languageOptions.minBashVersion', `applies only to bash and bats; dialect is "${dialect}". Remove minBashVersion or set dialect to "bash" or "bats"`, minBashVersion)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
77
72
  }
78
73
  if (minBashVersion !== undefined && typeof minBashVersion !== 'string') {
79
- throw new TypeError(`@eslint-sh/eslint-plugin: languageOptions.minBashVersion must be a string (e.g. "3.2"); received ${JSON.stringify(minBashVersion)}.`);
74
+ throw Object.assign(new TypeError(configurationMessage('languageOptions.minBashVersion', 'must be a string (e.g. "3.2")', minBashVersion)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
80
75
  }
81
76
  if (typeof minBashVersion === 'string' && !isValidMinBashVersionShape(minBashVersion)) {
82
- throw new TypeError(`@eslint-sh/eslint-plugin: languageOptions.minBashVersion must match the shape MAJOR[.MINOR] (e.g. "3.2", "5"); received ${JSON.stringify(minBashVersion)}.`);
77
+ throw Object.assign(new TypeError(configurationMessage('languageOptions.minBashVersion', 'must match the shape MAJOR[.MINOR] (e.g. "3.2", "5")', minBashVersion)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
83
78
  }
84
79
  if (directivePrefix !== undefined && !isValidDirectivePrefix(directivePrefix)) {
85
- throw new TypeError(`@eslint-sh/eslint-plugin: languageOptions.directivePrefix must be one or more lowercase, hyphen-separated words (e.g. "eslint", "shellcheck-sh"); received ${JSON.stringify(directivePrefix)}.`);
80
+ throw Object.assign(new TypeError(configurationMessage('languageOptions.directivePrefix', 'must be one or more lowercase, hyphen-separated words (e.g. "eslint", "shellcheck-sh")', directivePrefix)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
86
81
  }
87
82
  }
88
83
  /**
@@ -5,7 +5,8 @@ import { type NormalizedShellLanguageOptions, type ShellLanguageOptions } from '
5
5
  /**
6
6
  * `ShellLanguage` — the `@eslint/core` `Language` implementation for shell
7
7
  * scripts. Registered by the plugin as `languages.sh`, so consumers select
8
- * it via `language: "sh/sh"`.
8
+ * it via `language: "sh/sh"`. Its root export is type-only: `plugin.languages.sh`
9
+ * is the single runtime language handle, and the language pipeline owns source construction.
9
10
  *
10
11
  * Implements `matchesSelectorClass` (the six launch esquery selector
11
12
  * classes — see `./selector-classes.js`), so rules and end users can write
@@ -33,6 +34,7 @@ export declare class ShellLanguage implements Language {
33
34
  * label, if present). The removed `shellVersion` key throws with
34
35
  * migration guidance; other unknown keys are silently ignored. See `shell-language-options.ts`'s
35
36
  * `validateShellLanguageOptions` for the full rationale.
37
+ * @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
36
38
  */
37
39
  validateLanguageOptions(languageOptions: ShellLanguageOptions): void;
38
40
  /**
@@ -1,19 +1,12 @@
1
1
  /** Adapts upstream parsing and diagnostics to ESLint's synchronous Language contract. */
2
- import { LangBash, LangBats, LangError, LangMirBSDKorn, LangPOSIX, LangZsh, ParseError, ShParseMaxDepthError, parseWithPositionsSync, } from 'sh-ast';
2
+ import { LangError, ParseError, ShParseMaxDepthError, parseWithPositionsSync, } from 'sh-ast';
3
+ import { SHELL_VARIANTS } from '../shell-dialect.js';
3
4
  import { nonShellFileError } from './non-shell-file-guard.js';
4
5
  import { matchesSelectorClass as matchesShellSelectorClass } from './selector-classes.js';
5
6
  import { ShellSourceCode } from './shell-source-code.js';
6
7
  import { SourceCoordinates } from './source-coordinates.js';
7
8
  import { adaptSyntaxFile, shellVisitorKeys } from './syntax-view.js';
8
9
  import { normalizeShellLanguageOptions, validateShellLanguageOptions, } from './shell-language-options.js';
9
- /** Configuration labels map to exact upstream constants; no shell-version policy is added to parsing. */
10
- const DIALECT_VARIANTS = {
11
- bash: LangBash,
12
- posix: LangPOSIX,
13
- mksh: LangMirBSDKorn,
14
- bats: LangBats,
15
- zsh: LangZsh,
16
- };
17
10
  /** ESLint declares mutable visitor arrays; give it its own copy of the shared consumer relationships. */
18
11
  const mutableShellVisitorKeys = Object.fromEntries(Object.entries(shellVisitorKeys).map(([type, keys]) => [type, [...keys]]));
19
12
  /**
@@ -61,7 +54,8 @@ function toFileError(error, source) {
61
54
  /**
62
55
  * `ShellLanguage` — the `@eslint/core` `Language` implementation for shell
63
56
  * scripts. Registered by the plugin as `languages.sh`, so consumers select
64
- * it via `language: "sh/sh"`.
57
+ * it via `language: "sh/sh"`. Its root export is type-only: `plugin.languages.sh`
58
+ * is the single runtime language handle, and the language pipeline owns source construction.
65
59
  *
66
60
  * Implements `matchesSelectorClass` (the six launch esquery selector
67
61
  * classes — see `./selector-classes.js`), so rules and end users can write
@@ -89,6 +83,7 @@ export class ShellLanguage {
89
83
  * label, if present). The removed `shellVersion` key throws with
90
84
  * migration guidance; other unknown keys are silently ignored. See `shell-language-options.ts`'s
91
85
  * `validateShellLanguageOptions` for the full rationale.
86
+ * @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
92
87
  */
93
88
  validateLanguageOptions(languageOptions) {
94
89
  validateShellLanguageOptions(languageOptions);
@@ -139,7 +134,7 @@ export class ShellLanguage {
139
134
  const text = file.body;
140
135
  const dialect = context.languageOptions.dialect ?? 'bash';
141
136
  const parseOptions = {
142
- Variant: DIALECT_VARIANTS[dialect],
137
+ Variant: SHELL_VARIANTS[dialect],
143
138
  Filename: file.path,
144
139
  KeepComments: true,
145
140
  };