@eslint-sh/eslint-plugin 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/README.md +53 -40
  2. package/dist/api.d.ts +92 -0
  3. package/dist/api.js +83 -0
  4. package/dist/command-harvest/builtins/bash.d.ts +1 -1
  5. package/dist/command-harvest/builtins/bash.js +1 -1
  6. package/dist/command-harvest/builtins/bats.d.ts +2 -0
  7. package/dist/command-harvest/builtins/bats.js +3 -0
  8. package/dist/command-harvest/harvest-commands.d.ts +2 -2
  9. package/dist/command-harvest/harvest-commands.js +2 -2
  10. package/dist/command-harvest/wrapper-table.d.ts +3 -19
  11. package/dist/command-harvest/wrapper-table.js +8 -38
  12. package/dist/configs/bash-3-2.d.ts +7 -6
  13. package/dist/configs/bash-3-2.js +4 -3
  14. package/dist/configs/posix-portable.d.ts +7 -11
  15. package/dist/configs/posix-portable.js +4 -6
  16. package/dist/configuration-message.d.ts +14 -0
  17. package/dist/configuration-message.js +33 -0
  18. package/dist/declaration-conventions/get-declared-commands.d.ts +41 -0
  19. package/dist/declaration-conventions/{read-declared-commands.js → get-declared-commands.js} +43 -43
  20. package/dist/eslint-plugin-api.d.ts +1506 -0
  21. package/dist/eslint-plugin-syntax-analyze.d.ts +3 -3
  22. package/dist/eslint-plugin-syntax.d.ts +7 -4
  23. package/dist/eslint-plugin.d.ts +16 -1514
  24. package/dist/index.d.ts +14 -78
  25. package/dist/index.js +22 -74
  26. package/dist/language/command-resolution.d.ts +5 -5
  27. package/dist/language/command-resolution.js +11 -7
  28. package/dist/language/selector-classes.d.ts +7 -3
  29. package/dist/language/selector-classes.js +13 -4
  30. package/dist/language/shell-language-options.d.ts +21 -18
  31. package/dist/language/shell-language-options.js +41 -39
  32. package/dist/language/shell-language.d.ts +13 -10
  33. package/dist/language/shell-language.js +23 -45
  34. package/dist/language/shell-source-code.d.ts +74 -49
  35. package/dist/language/shell-source-code.js +135 -68
  36. package/dist/language/source-coordinates.d.ts +2 -0
  37. package/dist/language/source-coordinates.js +8 -4
  38. package/dist/language/syntax-view.js +19 -7
  39. package/dist/language/word-resolution.d.ts +2 -1
  40. package/dist/language/word-resolution.js +8 -3
  41. package/dist/rules/bash-variable-semantics.d.ts +22 -0
  42. package/dist/rules/bash-variable-semantics.js +41 -0
  43. package/dist/rules/compat/create-compat-rule.js +1 -1
  44. package/dist/rules/compat/declaration-options.d.ts +2 -2
  45. package/dist/rules/compat/declaration-options.js +5 -2
  46. package/dist/rules/compat/no-append-all-redirect.js +1 -1
  47. package/dist/rules/compat/no-associative-arrays.js +2 -2
  48. package/dist/rules/compat/no-brace-sequence-padding-step.js +4 -4
  49. package/dist/rules/compat/no-case-attributes.js +3 -3
  50. package/dist/rules/compat/no-case-fallthrough.js +2 -2
  51. package/dist/rules/compat/no-case-modification.js +2 -2
  52. package/dist/rules/compat/no-coproc.js +1 -1
  53. package/dist/rules/compat/no-declare-g.js +3 -3
  54. package/dist/rules/compat/no-double-bracket.js +2 -2
  55. package/dist/rules/compat/no-epoch-variables.js +2 -2
  56. package/dist/rules/compat/no-fd-variable.js +1 -1
  57. package/dist/rules/compat/no-globstar.js +1 -1
  58. package/dist/rules/compat/no-lastpipe-semantics.js +2 -2
  59. package/dist/rules/compat/no-let.js +2 -1
  60. package/dist/rules/compat/no-mapfile.js +4 -2
  61. package/dist/rules/compat/no-nameref.js +3 -3
  62. package/dist/rules/compat/no-negative-array-index.js +39 -9
  63. package/dist/rules/compat/no-nounset-empty-array.js +15 -4
  64. package/dist/rules/compat/no-parameter-transformation.js +2 -2
  65. package/dist/rules/compat/no-pipe-all.js +1 -1
  66. package/dist/rules/compat/no-printf-time-format.js +4 -2
  67. package/dist/rules/compat/no-source.js +2 -1
  68. package/dist/rules/compat/no-test-v.js +4 -2
  69. package/dist/rules/compat/no-unicode-escape.js +2 -2
  70. package/dist/rules/compat/no-wait-n.js +4 -2
  71. package/dist/rules/compat/nounset-array-proof.d.ts +8 -0
  72. package/dist/rules/compat/nounset-array-proof.js +563 -0
  73. package/dist/rules/compat/posix-absent-command.d.ts +7 -8
  74. package/dist/rules/compat/posix-absent-command.js +17 -15
  75. package/dist/rules/compat/shopt-options.js +3 -1
  76. package/dist/rules/compat/version-gates.d.ts +9 -9
  77. package/dist/rules/compat/version-gates.js +13 -13
  78. package/dist/rules/create-wrapper-rule.d.ts +1 -1
  79. package/dist/rules/create-wrapper-rule.js +23 -16
  80. package/dist/rules/define-shell-rule.js +1 -1
  81. package/dist/rules/no-dynamic-invocation.d.ts +0 -8
  82. package/dist/rules/no-dynamic-invocation.js +7 -15
  83. package/dist/rules/no-eval.js +3 -1
  84. package/dist/rules/no-masked-exit-status.d.ts +4 -3
  85. package/dist/rules/no-masked-exit-status.js +18 -10
  86. package/dist/rules/no-secret-env-reads.d.ts +6 -3
  87. package/dist/rules/no-secret-env-reads.js +49 -15
  88. package/dist/rules/no-secret-flags.d.ts +4 -1
  89. package/dist/rules/no-secret-flags.js +21 -11
  90. package/dist/rules/no-unchecked-cd.js +6 -3
  91. package/dist/rules/no-undeclared-commands.d.ts +1 -15
  92. package/dist/rules/no-undeclared-commands.js +11 -18
  93. package/dist/rules/no-unused-declarations.d.ts +1 -18
  94. package/dist/rules/no-unused-declarations.js +15 -36
  95. package/dist/rules/prefer-local.d.ts +3 -2
  96. package/dist/rules/prefer-local.js +7 -4
  97. package/dist/rules/quote-expansions.js +3 -28
  98. package/dist/rules/require-network-wrapper.d.ts +3 -18
  99. package/dist/rules/require-network-wrapper.js +43 -10
  100. package/dist/rules/require-strict-mode.d.ts +5 -46
  101. package/dist/rules/require-strict-mode.js +17 -107
  102. package/dist/rules/require-tty-guard.d.ts +2 -0
  103. package/dist/rules/require-tty-guard.js +8 -1
  104. package/dist/rules/resolve-declaration-convention.d.ts +9 -89
  105. package/dist/rules/resolve-declaration-convention.js +19 -72
  106. package/dist/rules/resolve-network-wrapper.d.ts +20 -2
  107. package/dist/rules/resolve-network-wrapper.js +71 -36
  108. package/dist/rules/resolve-transparent-wrappers.d.ts +38 -0
  109. package/dist/rules/resolve-transparent-wrappers.js +108 -0
  110. package/dist/rules/set-options.d.ts +3 -2
  111. package/dist/rules/set-options.js +18 -6
  112. package/dist/rules/shebang-interpreter.js +4 -2
  113. package/dist/rules/strict-mode-prologue.d.ts +43 -0
  114. package/dist/rules/strict-mode-prologue.js +91 -0
  115. package/dist/rules/transparent-wrappers.d.ts +4 -3
  116. package/dist/rules/transparent-wrappers.js +5 -4
  117. package/dist/rules/user-pattern.d.ts +9 -6
  118. package/dist/rules/user-pattern.js +16 -12
  119. package/dist/shell-dialect.d.ts +8 -0
  120. package/dist/shell-dialect.js +22 -0
  121. package/dist/syntax/analyze.d.ts +3 -3
  122. package/dist/syntax/analyze.js +3 -3
  123. package/dist/syntax/index.d.ts +7 -4
  124. package/dist/syntax/index.js +7 -4
  125. package/dist/version.js +2 -1
  126. package/docs/compat.md +81 -33
  127. package/docs/custom-rule-tutorial.md +31 -21
  128. package/docs/declaration-conventions.md +20 -23
  129. package/docs/error-codes.md +93 -0
  130. package/docs/examples/no-listed-commands-rule.ts +2 -2
  131. package/docs/examples/no-rm-rf-rule.mjs +8 -10
  132. package/docs/examples/sorted-declarations-rule.mjs +6 -9
  133. package/docs/examples/tsconfig.json +10 -0
  134. package/docs/rules/README.md +46 -6
  135. package/docs/rules/_template.md +2 -2
  136. package/docs/rules/compat/no-append-all-redirect.md +12 -12
  137. package/docs/rules/compat/no-associative-arrays.md +14 -14
  138. package/docs/rules/compat/no-brace-sequence-padding-step.md +12 -12
  139. package/docs/rules/compat/no-case-attributes.md +13 -13
  140. package/docs/rules/compat/no-case-fallthrough.md +12 -12
  141. package/docs/rules/compat/no-case-modification.md +11 -11
  142. package/docs/rules/compat/no-coproc.md +13 -13
  143. package/docs/rules/compat/no-declare-g.md +13 -13
  144. package/docs/rules/compat/no-double-bracket.md +2 -2
  145. package/docs/rules/compat/no-epoch-variables.md +13 -13
  146. package/docs/rules/compat/no-fd-variable.md +12 -12
  147. package/docs/rules/compat/no-globstar.md +13 -13
  148. package/docs/rules/compat/no-lastpipe-semantics.md +13 -13
  149. package/docs/rules/compat/no-let.md +2 -2
  150. package/docs/rules/compat/no-mapfile.md +16 -16
  151. package/docs/rules/compat/no-nameref.md +13 -13
  152. package/docs/rules/compat/no-negative-array-index.md +14 -14
  153. package/docs/rules/compat/no-nounset-empty-array.md +72 -17
  154. package/docs/rules/compat/no-parameter-transformation.md +19 -19
  155. package/docs/rules/compat/no-pipe-all.md +13 -13
  156. package/docs/rules/compat/no-printf-time-format.md +13 -13
  157. package/docs/rules/compat/no-source.md +2 -2
  158. package/docs/rules/compat/no-test-v.md +12 -12
  159. package/docs/rules/compat/no-unicode-escape.md +13 -13
  160. package/docs/rules/compat/no-wait-n.md +13 -13
  161. package/docs/rules/no-dynamic-invocation.md +17 -12
  162. package/docs/rules/no-eval.md +6 -1
  163. package/docs/rules/no-masked-exit-status.md +6 -2
  164. package/docs/rules/no-secret-env-reads.md +46 -5
  165. package/docs/rules/no-secret-flags.md +32 -6
  166. package/docs/rules/no-unchecked-cd.md +22 -2
  167. package/docs/rules/no-undeclared-commands.md +16 -15
  168. package/docs/rules/no-unused-declarations.md +17 -20
  169. package/docs/rules/prefer-local.md +20 -2
  170. package/docs/rules/quote-expansions.md +8 -5
  171. package/docs/rules/require-network-wrapper.md +26 -21
  172. package/docs/rules/require-shebang.md +10 -4
  173. package/docs/rules/require-strict-mode.md +31 -23
  174. package/docs/rules/require-tty-guard.md +12 -3
  175. package/docs/selectors.md +7 -2
  176. package/docs/shellcheck.md +9 -5
  177. package/docs/transparent-wrappers.md +97 -0
  178. package/docs/wrapper-rules.md +11 -0
  179. package/package.json +3 -3
  180. package/dist/declaration-conventions/read-declared-commands.d.ts +0 -70
  181. package/dist/language/end-of-input-marker.d.ts +0 -29
  182. package/dist/language/end-of-input-marker.js +0 -88
@@ -3,7 +3,7 @@
3
3
  * POSIX `sh` rather than for Bash.
4
4
  *
5
5
  * It sets `languageOptions.dialect: 'posix'`, which makes every Bash-only
6
- * feature unavailable at any `shellVersion`, and enables the `compat/*` rules
6
+ * feature unavailable at any `minBashVersion`, and enables the `compat/*` rules
7
7
  * that report those features. The dialect is also what every dialect-aware
8
8
  * rule reads, so the preset is one switch rather than a list of settings that
9
9
  * could drift apart.
@@ -14,18 +14,14 @@
14
14
  * shellcheck, which is why it does not promise "any POSIX `sh`". The scope and
15
15
  * the shell behaviour behind it are stated for users in `docs/compat.md`.
16
16
  *
17
- * `require-strict-mode` is configured, not merely enabled. Its default under
18
- * `posix` is already `set -eu`, but the preset states `mode: 'set -eu'`
19
- * explicitly so that neither a later edit to that default nor an inherited
20
- * `recommended` severity-only entry can make the pack demand `pipefail`,
21
- * which POSIX gained only in POSIX.1-2024 and which dash and older BusyBox
22
- * ash reject. A pack that asked for `pipefail` would make its own autofix
23
- * break a working `#!/bin/sh` script.
17
+ * Target presets carry only target facts and findings that depend on them.
18
+ * The shebang check belongs here because it verifies the declared interpreter
19
+ * against the configured target. Error-handling policy belongs to recommended:
20
+ * `extends: [sh.configs.recommended, sh.configs['posix-portable']]` requires
21
+ * the dialect-aware POSIX default, `set -eu`.
24
22
  *
25
23
  * It follows the shape contract in `./recommended.ts`, extended with
26
- * `languageOptions` for the reason given in `./bash-3-2.ts`. It composes
27
- * through `extends: [sh.configs.recommended, sh.configs['posix-portable']]`;
28
- * the later entry's `require-strict-mode` options win.
24
+ * `languageOptions` because the target is the preset's meaning.
29
25
  *
30
26
  * Rule membership follows the **Configs** column of the rule catalog (rows
31
27
  * marked `P`), which a test checks against this module.
@@ -1,14 +1,13 @@
1
1
  /**
2
2
  * The rules `sh/posix-portable` enables, all at `error`, keyed as a user
3
- * writes them (`sh/<rule-name>`): every `compat/*` rule (each reports under
4
- * `dialect: 'posix'` whatever the version), including the POSIX-only gates
5
- * `bash-3.2` has no use for, the shebang/dialect check, and strict mode in its
6
- * POSIX spelling.
3
+ * writes them (`sh/<rule-name>`): the effective `compat/*` rules under
4
+ * `dialect: 'posix'`, including the POSIX-only gates
5
+ * `bash-3.2` has no use for, and the shebang/dialect check. The empty-array
6
+ * nounset rule is omitted because it checks Bash targets and cannot report under POSIX.
7
7
  *
8
8
  * @internal
9
9
  */
10
10
  const posixPortableRules = {
11
- 'sh/require-strict-mode': ['error', { mode: 'set -eu' }],
12
11
  'sh/shebang-matches-dialect': 'error',
13
12
  'sh/compat/no-append-all-redirect': 'error',
14
13
  'sh/compat/no-associative-arrays': 'error',
@@ -27,7 +26,6 @@ const posixPortableRules = {
27
26
  'sh/compat/no-mapfile': 'error',
28
27
  'sh/compat/no-nameref': 'error',
29
28
  'sh/compat/no-negative-array-index': 'error',
30
- 'sh/compat/no-nounset-empty-array': 'error',
31
29
  'sh/compat/no-parameter-transformation': 'error',
32
30
  'sh/compat/no-pipe-all': 'error',
33
31
  'sh/compat/no-printf-time-format': 'error',
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Human diagnostics for project-owned configuration boundaries. Codes belong to
3
+ * the rejecting boundary; this module only keeps paths and received values
4
+ * consistent, without constructing errors or coupling runtime packages.
5
+ */
6
+ /**
7
+ * Render a rejected value using the project's short JSON-first convention.
8
+ * Non-JSON values must not replace the intended configuration failure with a
9
+ * serialization exception. The rendering is diagnostic text, never stored state.
10
+ * @internal
11
+ */
12
+ export declare function describeConfigurationValue(value: unknown): string;
13
+ /** The user's path identifies the binding; prose may evolve independently of the error code. @internal */
14
+ export declare function configurationMessage(where: string, detail: string, value: unknown): string;
@@ -0,0 +1,33 @@
1
+ // Generated from shared/configuration-message.ts; edit the canonical source.
2
+ /**
3
+ * Human diagnostics for project-owned configuration boundaries. Codes belong to
4
+ * the rejecting boundary; this module only keeps paths and received values
5
+ * consistent, without constructing errors or coupling runtime packages.
6
+ */
7
+ /**
8
+ * Render a rejected value using the project's short JSON-first convention.
9
+ * Non-JSON values must not replace the intended configuration failure with a
10
+ * serialization exception. The rendering is diagnostic text, never stored state.
11
+ * @internal
12
+ */
13
+ export function describeConfigurationValue(value) {
14
+ // JSON turns nonfinite numbers into null, which would identify a different rejected value.
15
+ if (typeof value === 'number' && !Number.isFinite(value)) {
16
+ return String(value);
17
+ }
18
+ if (typeof value === 'bigint') {
19
+ return `${String(value)}n`;
20
+ }
21
+ try {
22
+ // JSON.stringify also returns undefined for functions, symbols and undefined.
23
+ const rendered = JSON.stringify(value);
24
+ return rendered ?? String(value);
25
+ }
26
+ catch {
27
+ return String(value);
28
+ }
29
+ }
30
+ /** The user's path identifies the binding; prose may evolve independently of the error code. @internal */
31
+ export function configurationMessage(where, detail, value) {
32
+ return `${where}: ${detail}; received ${describeConfigurationValue(value)}.`;
33
+ }
@@ -0,0 +1,41 @@
1
+ import type { SettingsConfig } from '@eslint/core';
2
+ import type { ShellSourceCode } from '../language/shell-source-code.js';
3
+ import type { DeclaredCommand, LintedFile } from './declaration-convention.js';
4
+ /**
5
+ * The only view of the linted file a convention's hooks receive: `filename`,
6
+ * `physicalFilename` and `cwd`, frozen. A rule's `context` must never reach a
7
+ * hook, because it would let a convention report, read options or reach other
8
+ * rule state.
9
+ *
10
+ * @internal
11
+ */
12
+ export declare function toLintedFile(context: LintedFile): LintedFile;
13
+ /**
14
+ * Returns validated declarations for the linted file, or `null` when the project
15
+ * has no bound convention. An empty array means a convention is bound and the
16
+ * file declares no commands; consumers must preserve that distinction.
17
+ *
18
+ * The convention receives only a frozen {@link LintedFile}, never rule state.
19
+ * Invalid bindings, output arrays, declaration kinds, provenance or UTF-16 ranges
20
+ * throw an error naming the shared setting before a rule can trust the result.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * File() {
25
+ * const declarations = getDeclaredCommands(context);
26
+ * if (declarations === null) return;
27
+ * for (const declared of declarations) {
28
+ * // Each declaration has been checked against its kind's contract.
29
+ * }
30
+ * }
31
+ * ```
32
+ *
33
+ * @throws Error with `ESLINT_SH_DECLARATION_CONVENTION` for invalid shared bindings, or
34
+ * `ESLINT_SH_DECLARATION_OUTPUT` for invalid hook results.
35
+ * Exceptions thrown by the convention itself pass through unchanged, including their causes.
36
+ * @public
37
+ */
38
+ export declare function getDeclaredCommands(context: LintedFile & {
39
+ readonly sourceCode: ShellSourceCode;
40
+ readonly settings: SettingsConfig;
41
+ }): DeclaredCommand[] | null;
@@ -1,8 +1,23 @@
1
1
  /**
2
- * The binding a validation error names. A convention can only be bound in
3
- * settings in practice: ESLint copies rule options with `structuredClone`,
4
- * which rejects an object with methods.
2
+ * The one path by which a rule reads a bound convention's declarations for
3
+ * the file it is linting. The built-in consumers (`sh/no-undeclared-commands`,
4
+ * `sh/no-unused-declarations`) and a pack's own rules all call
5
+ * {@link getDeclaredCommands}, so they hand the convention the same
6
+ * {@link LintedFile} and trust only declarations that passed the same checks.
7
+ *
8
+ * The checks exist because a declaration's kind decides where a report goes
9
+ * and whether a fix is offered. A declaration of an unknown kind, one missing
10
+ * its kind's fields, or a script range outside the text would otherwise be
11
+ * reported at a made-up location, crash deep inside a rule, or be silently
12
+ * accepted by a rule that only reads names. Failing with the declaration and
13
+ * the setting in the message makes the convention's bug the thing the user
14
+ * sees.
15
+ *
16
+ * ESLINT_SH_DECLARATION_OUTPUT identifies invalid extension results. Exceptions thrown by convention hooks belong to the extension and propagate unchanged.
5
17
  */
18
+ import { configurationMessage, describeConfigurationValue } from '../configuration-message.js';
19
+ import { resolveDeclarationConvention } from '../rules/resolve-declaration-convention.js';
20
+ /** Validation errors identify the same shared policy that supplied the declarations. */
6
21
  const BINDING = 'settings.sh.declarationConvention';
7
22
  /**
8
23
  * The only view of the linted file a convention's hooks receive: `filename`,
@@ -64,64 +79,49 @@ function invalidReason(value, textLength) {
64
79
  case undefined:
65
80
  return "`kind` is missing: it must be 'script', 'file' or 'described'";
66
81
  default:
67
- return `\`kind\` must be 'script', 'file' or 'described', not ${describe(declared.kind)}`;
68
- }
69
- }
70
- /** A short rendering of a value for an error message. */
71
- function describe(value) {
72
- try {
73
- // `JSON.stringify` returns `undefined` for a function or `undefined`.
74
- const text = JSON.stringify(value);
75
- return text ?? String(value);
76
- }
77
- catch {
78
- return String(value);
82
+ return `\`kind\` must be 'script', 'file' or 'described', not ${describeConfigurationValue(declared.kind)}`;
79
83
  }
80
84
  }
81
85
  /**
82
- * Returns the declarations `convention` makes for the file `context` is
83
- * linting, after checking each one against its kind. Call it from a rule's
84
- * listener with the convention `resolveDeclarationConvention` returned and
85
- * the rule's own `context`.
86
- *
87
- * The convention receives a frozen {@link LintedFile} holding only
88
- * `filename`, `physicalFilename` and `cwd`, never the whole context, so it
89
- * sees which file it is reading and nothing it could report through.
86
+ * Returns validated declarations for the linted file, or `null` when the project
87
+ * has no bound convention. An empty array means a convention is bound and the
88
+ * file declares no commands; consumers must preserve that distinction.
90
89
  *
91
- * Throws an `Error` that names the setting, starting
92
- * `Invalid settings.sh.declarationConvention:`, and shows the offending value when
93
- * `declaredCommands` does not return an array, or returns a declaration with
94
- * a missing or unknown `kind`, without its kind's fields, or with a `range`
95
- * outside the linted text.
90
+ * The convention receives only a frozen {@link LintedFile}, never rule state.
91
+ * Invalid bindings, output arrays, declaration kinds, provenance or UTF-16 ranges
92
+ * throw an error naming the shared setting before a rule can trust the result.
96
93
  *
97
94
  * @example
98
95
  * ```ts
99
- * const convention = resolveDeclarationConvention(context);
100
- * if (convention === null) return {};
101
- * return {
102
- * File() {
103
- * for (const declared of readDeclaredCommands(convention, context)) {
104
- * if (declared.kind === 'script') {
105
- * // declared.range is an offset pair into context.sourceCode.text
106
- * }
107
- * }
108
- * },
109
- * };
96
+ * File() {
97
+ * const declarations = getDeclaredCommands(context);
98
+ * if (declarations === null) return;
99
+ * for (const declared of declarations) {
100
+ * // Each declaration has been checked against its kind's contract.
101
+ * }
102
+ * }
110
103
  * ```
111
104
  *
105
+ * @throws Error with `ESLINT_SH_DECLARATION_CONVENTION` for invalid shared bindings, or
106
+ * `ESLINT_SH_DECLARATION_OUTPUT` for invalid hook results.
107
+ * Exceptions thrown by the convention itself pass through unchanged, including their causes.
112
108
  * @public
113
109
  */
114
- export function readDeclaredCommands(convention, context) {
110
+ export function getDeclaredCommands(context) {
111
+ const convention = resolveDeclarationConvention(context);
112
+ if (convention === null) {
113
+ return null;
114
+ }
115
115
  const { sourceCode } = context;
116
116
  const file = toLintedFile(context);
117
117
  const declarations = convention.declaredCommands(sourceCode, file);
118
118
  if (!Array.isArray(declarations)) {
119
- throw new Error(`Invalid ${BINDING}: \`declaredCommands\` must return an array, but returned ${describe(declarations)}.`);
119
+ throw Object.assign(new Error(configurationMessage(`${BINDING}.declaredCommands`, 'must return an array', declarations)), { code: 'ESLINT_SH_DECLARATION_OUTPUT' });
120
120
  }
121
- for (const declared of declarations) {
121
+ for (const [index, declared] of declarations.entries()) {
122
122
  const reason = invalidReason(declared, sourceCode.text.length);
123
123
  if (reason !== null) {
124
- throw new Error(`Invalid ${BINDING}: \`declaredCommands\` returned the declaration ${describe(declared)}, but ${reason}.`);
124
+ throw Object.assign(new Error(configurationMessage(`${BINDING}.declaredCommands[${String(index)}]`, `returned an invalid declaration: ${reason}`, declared)), { code: 'ESLINT_SH_DECLARATION_OUTPUT' });
125
125
  }
126
126
  }
127
127
  return declarations;