@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
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * A gate is data: a feature name mapped to the oldest Bash release that has
6
6
  * it and whether POSIX sh has it. A new gate is a new row here, not new
7
- * decision logic in a rule. The semantics of `languageOptions.shellVersion`
7
+ * decision logic in a rule. The semantics of `languageOptions.minBashVersion`
8
8
  * and `languageOptions.dialect` for gating are defined once, by
9
9
  * {@link isFeatureAvailable}, and documented for users in `docs/compat.md`.
10
10
  *
@@ -35,28 +35,28 @@ export type CompatFeature = 'appendAllRedirect' | 'associativeArrays' | 'braceSe
35
35
  *
36
36
  * @internal
37
37
  */
38
- export type GateLanguageOptions = Pick<ShellLanguageOptions, 'dialect' | 'shellVersion'>;
38
+ export type GateLanguageOptions = Pick<ShellLanguageOptions, 'dialect' | 'minBashVersion'>;
39
39
  /**
40
40
  * Whether `feature` is available to a file linted with `languageOptions`.
41
41
  *
42
42
  * - `dialect: "posix"`: available only when the gate's `posix` is `true`,
43
- * at any `shellVersion` (a Bash-only feature is never available).
44
- * - `dialect: "bash"` (the default) or `"bats"`: an unset `shellVersion`
45
- * means the newest Bash, so every Bash feature is available. A set
46
- * `shellVersion` makes the feature available when it is the gate's `bash`
43
+ * regardless of Bash releases (a Bash-only feature is never available).
44
+ * - `dialect: "bash"` (the default) or `"bats"`: an unset `minBashVersion`
45
+ * means no Bash version constraint, so every Bash feature is available. A set
46
+ * `minBashVersion` makes the feature available when it is the gate's `bash`
47
47
  * minimum or newer, comparing major then minor numerically (`"4"` is
48
48
  * `4.0`; `"3.10"` is newer than `"3.2"`). A `null` minimum is available at
49
49
  * every version.
50
50
  * - `dialect: "mksh"` or `"zsh"`: the table carries no data for these
51
- * shells, and their `shellVersion` numbers their own releases, not Bash's,
52
- * so no gate applies and every feature is available.
51
+ * shells. Config validation rejects `minBashVersion` for them; no Bash
52
+ * gate applies and every feature is available.
53
53
  *
54
54
  * @internal
55
55
  */
56
56
  export declare function isFeatureAvailable(feature: CompatFeature, languageOptions: GateLanguageOptions): boolean;
57
57
  /**
58
58
  * Human-readable words for a gate's report: what the feature needs
59
- * (`required`, such as `bash 4.0 or newer`) and what the file targets
59
+ * (`required`, such as `bash 4.0 or newer`) and what the file must support
60
60
  * (`target`, such as `bash 3.2` or `POSIX sh`). Compat rule messages
61
61
  * interpolate both as `{{required}}` and `{{target}}`.
62
62
  *
@@ -151,7 +151,7 @@ function compareVersions(a, b) {
151
151
  return a[0] !== b[0] ? a[0] - b[0] : a[1] - b[1];
152
152
  }
153
153
  /**
154
- * The dialects whose `shellVersion` is a Bash version. `bats` test files run
154
+ * The dialects whose `minBashVersion` is a Bash version. `bats` test files run
155
155
  * under Bash, so they are gated exactly like `bash` files.
156
156
  */
157
157
  const BASH_DIALECTS = new Set(['bash', 'bats']);
@@ -159,16 +159,16 @@ const BASH_DIALECTS = new Set(['bash', 'bats']);
159
159
  * Whether `feature` is available to a file linted with `languageOptions`.
160
160
  *
161
161
  * - `dialect: "posix"`: available only when the gate's `posix` is `true`,
162
- * at any `shellVersion` (a Bash-only feature is never available).
163
- * - `dialect: "bash"` (the default) or `"bats"`: an unset `shellVersion`
164
- * means the newest Bash, so every Bash feature is available. A set
165
- * `shellVersion` makes the feature available when it is the gate's `bash`
162
+ * regardless of Bash releases (a Bash-only feature is never available).
163
+ * - `dialect: "bash"` (the default) or `"bats"`: an unset `minBashVersion`
164
+ * means no Bash version constraint, so every Bash feature is available. A set
165
+ * `minBashVersion` makes the feature available when it is the gate's `bash`
166
166
  * minimum or newer, comparing major then minor numerically (`"4"` is
167
167
  * `4.0`; `"3.10"` is newer than `"3.2"`). A `null` minimum is available at
168
168
  * every version.
169
169
  * - `dialect: "mksh"` or `"zsh"`: the table carries no data for these
170
- * shells, and their `shellVersion` numbers their own releases, not Bash's,
171
- * so no gate applies and every feature is available.
170
+ * shells. Config validation rejects `minBashVersion` for them; no Bash
171
+ * gate applies and every feature is available.
172
172
  *
173
173
  * @internal
174
174
  */
@@ -179,14 +179,14 @@ export function isFeatureAvailable(feature, languageOptions) {
179
179
  return gate.posix;
180
180
  if (!BASH_DIALECTS.has(dialect))
181
181
  return true;
182
- const { shellVersion } = languageOptions;
183
- if (shellVersion === undefined || gate.bash === null)
182
+ const { minBashVersion } = languageOptions;
183
+ if (minBashVersion === undefined || gate.bash === null)
184
184
  return true;
185
- const target = parseVersion(shellVersion);
185
+ const floor = parseVersion(minBashVersion);
186
186
  const minimum = parseVersion(gate.bash);
187
- if (target === undefined || minimum === undefined)
187
+ if (floor === undefined || minimum === undefined)
188
188
  return true;
189
- return compareVersions(target, minimum) >= 0;
189
+ return compareVersions(floor, minimum) >= 0;
190
190
  }
191
191
  /**
192
192
  * Describes why `feature` is unavailable under `languageOptions`, for a
@@ -200,6 +200,6 @@ export function describeGate(feature, languageOptions) {
200
200
  const required = gate.bash === null ? 'bash' : `bash ${gate.bash} or newer`;
201
201
  const target = (languageOptions.dialect ?? 'bash') === 'posix'
202
202
  ? 'POSIX sh'
203
- : `bash ${languageOptions.shellVersion ?? ''}`.trim();
203
+ : `bash ${languageOptions.minBashVersion ?? ''}`.trim();
204
204
  return { required, target };
205
205
  }
@@ -157,7 +157,7 @@ export declare function buildWrapperRule<RuleOptions extends unknown[] = []>(con
157
157
  * subcommand restrictions, and optional `meta.docs` overrides.
158
158
  * @returns A {@link ShellRule}: an ESLint rule for the `sh/sh` language,
159
159
  * typed so a pack's own declarations need no `@eslint/core` import to name it.
160
- * @throws TypeError when `config` is malformed (no `commands` array, an empty
160
+ * @throws TypeError with `ESLINT_SH_WRAPPER_CONFIG` when `config` is malformed (no `commands` array, an empty
161
161
  * wrapper name, a subcommand restriction without `names`, or an empty or
162
162
  * non-string `docs.url` / `docs.description`).
163
163
  *
@@ -36,7 +36,9 @@
36
36
  * static. Commands inside command strings (`bash -c '…'`) are not commands to
37
37
  * this analysis and are out of scope.
38
38
  */
39
+ import { configurationMessage } from '../configuration-message.js';
39
40
  import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-ast/analyze';
41
+ import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
40
42
  import { definedFunctionNames } from '../command-harvest/harvest-commands.js';
41
43
  import { createRule, packageDocsUrl } from './create-rule.js';
42
44
  /**
@@ -90,14 +92,15 @@ function isStringArray(value) {
90
92
  * offending field, so a malformed binding fails when a rule pack is loaded
91
93
  * rather than in the middle of linting a file.
92
94
  */
95
+ // ESLINT_SH_WRAPPER_CONFIG rejects factory bindings before any rule state is created.
93
96
  function compileWrapperRule(config) {
94
97
  const { commands, wrapper, subcommands = {}, localInvocations = {}, docs = {}, } = config;
95
98
  if (!isStringArray(commands)) {
96
- throw new TypeError('createWrapperRule: `commands` must be an array of non-empty strings');
99
+ throw Object.assign(new TypeError(configurationMessage('createWrapperRule config.commands', 'must be an array of non-empty strings', commands)), { code: 'ESLINT_SH_WRAPPER_CONFIG' });
97
100
  }
98
101
  for (const field of ['url', 'description']) {
99
102
  if (docs[field] !== undefined && !isNonEmptyString(docs[field])) {
100
- throw new TypeError(`createWrapperRule: \`docs.${field}\` must be a non-empty string`);
103
+ throw Object.assign(new TypeError(configurationMessage(`createWrapperRule config.docs.${field}`, 'must be a non-empty string', docs[field])), { code: 'ESLINT_SH_WRAPPER_CONFIG' });
101
104
  }
102
105
  }
103
106
  let wrapperSpec;
@@ -112,13 +115,13 @@ function compileWrapperRule(config) {
112
115
  wrapperSpec = wrapper;
113
116
  }
114
117
  else {
115
- throw new TypeError('createWrapperRule: `wrapper` must be a non-empty string or a WrapperSpec with non-empty `names`');
118
+ throw Object.assign(new TypeError(configurationMessage('createWrapperRule config.wrapper', 'must be a non-empty string or a WrapperSpec with non-empty `names`', wrapper)), { code: 'ESLINT_SH_WRAPPER_CONFIG' });
116
119
  }
117
120
  const subcommandSpecs = [];
118
121
  const subcommandNames = new Map();
119
122
  for (const [command, restriction] of Object.entries(subcommands)) {
120
123
  if (!isStringArray(restriction.names) || restriction.names.length === 0) {
121
- throw new TypeError(`createWrapperRule: \`subcommands.${command}.names\` must be a non-empty array of non-empty strings`);
124
+ throw Object.assign(new TypeError(configurationMessage(`createWrapperRule config.subcommands.${command}.names`, 'must be a non-empty array of non-empty strings', restriction.names)), { code: 'ESLINT_SH_WRAPPER_CONFIG' });
122
125
  }
123
126
  subcommandNames.set(command, new Set(restriction.names));
124
127
  // Modeling the command as a transparent wrapper makes `resolveArgv0`
@@ -134,18 +137,18 @@ function compileWrapperRule(config) {
134
137
  for (const [label, local] of Object.entries(localInvocations)) {
135
138
  const where = `localInvocations.${label}`;
136
139
  if (!isRecord(local)) {
137
- throw new TypeError(`createWrapperRule: \`${where}\` must be an object`);
140
+ throw Object.assign(new TypeError(configurationMessage(`createWrapperRule config.${where}`, 'must be an object', local)), { code: 'ESLINT_SH_WRAPPER_CONFIG' });
138
141
  }
139
142
  const { argLists, localOperand } = local;
140
143
  if (argLists !== undefined &&
141
144
  !(Array.isArray(argLists) &&
142
145
  argLists.every((list) => Array.isArray(list) && isStringArray(list)))) {
143
- throw new TypeError(`createWrapperRule: \`${where}.argLists\` must be an array of arrays of non-empty strings`);
146
+ throw Object.assign(new TypeError(configurationMessage(`createWrapperRule config.${where}.argLists`, 'must be an array of arrays of non-empty strings', argLists)), { code: 'ESLINT_SH_WRAPPER_CONFIG' });
144
147
  }
145
148
  if (localOperand === undefined)
146
149
  continue;
147
150
  if (!isRecord(localOperand)) {
148
- throw new TypeError(`createWrapperRule: \`${where}.localOperand\` must be an object`);
151
+ throw Object.assign(new TypeError(configurationMessage(`createWrapperRule config.${where}.localOperand`, 'must be an object', localOperand)), { code: 'ESLINT_SH_WRAPPER_CONFIG' });
149
152
  }
150
153
  for (const field of ['localPrefixes', 'noArgFlags', 'argFlags']) {
151
154
  const value = localOperand[field];
@@ -153,7 +156,7 @@ function compileWrapperRule(config) {
153
156
  ? isStringArray(value)
154
157
  : value === undefined || isStringArray(value);
155
158
  if (!valid) {
156
- throw new TypeError(`createWrapperRule: \`${where}.localOperand.${field}\` must be an array of non-empty strings`);
159
+ throw Object.assign(new TypeError(configurationMessage(`createWrapperRule config.${where}.localOperand.${field}`, 'must be an array of non-empty strings', value)), { code: 'ESLINT_SH_WRAPPER_CONFIG' });
157
160
  }
158
161
  }
159
162
  }
@@ -187,12 +190,13 @@ function staticText(word) {
187
190
  * Resolves `site`'s chain through `compiled`'s wrapper table, following a
188
191
  * wrapper invoked by path as the wrapper it names.
189
192
  *
190
- * `resolveArgv0` matches wrapper names exactly, so a path to a wrapper
191
- * (`/usr/local/bin/retry`) ends the chain as if it were the command run. When
192
- * the chain ends at a static word with a slash whose basename names a table
193
- * entry, the site is resolved again with that entry also recognized under the
193
+ * `resolveArgv0` follows absolute wrapper paths directly. Relative wrapper
194
+ * paths also count for this policy: when the chain ends at a static word
195
+ * with a slash whose basename names a table
196
+ * utility entry, the site is resolved again with that entry also recognized under the
194
197
  * exact path text, so its options and wrapped command are located by the
195
- * same analysis. Each pass adds one new name drawn from the site's own argv,
198
+ * same analysis. Shell builtin entries require exact names and never gain
199
+ * path spellings from this policy. Each pass adds one new name drawn from the site's own argv,
196
200
  * so the loop ends.
197
201
  */
198
202
  function resolveChain(compiled, site) {
@@ -202,7 +206,7 @@ function resolveChain(compiled, site) {
202
206
  const last = staticText(resolution.chain.at(-1));
203
207
  if (last === null || table.some((spec) => spec.names.includes(last)))
204
208
  return resolution;
205
- const spec = compiled.transparentWrappers.find((entry) => matchName(last, new Set(entry.names)) !== null);
209
+ const spec = compiled.transparentWrappers.find((entry) => entry.shellBuiltin !== true && matchName(last, new Set(entry.names)) !== null);
206
210
  if (spec === undefined)
207
211
  return resolution;
208
212
  table = [{ ...spec, names: [last] }, ...table];
@@ -365,7 +369,10 @@ export function buildWrapperRule(config) {
365
369
  schema: [],
366
370
  messages: WRAPPER_RULE_MESSAGES,
367
371
  },
368
- create: (context) => wrapperRuleListeners(compiled, context),
372
+ create: (context) => wrapperRuleListeners({
373
+ ...compiled,
374
+ transparentWrappers: resolveTransparentWrappers(context, compiled.transparentWrappers),
375
+ }, context),
369
376
  });
370
377
  }
371
378
  /**
@@ -396,7 +403,7 @@ export function buildWrapperRule(config) {
396
403
  * subcommand restrictions, and optional `meta.docs` overrides.
397
404
  * @returns A {@link ShellRule}: an ESLint rule for the `sh/sh` language,
398
405
  * typed so a pack's own declarations need no `@eslint/core` import to name it.
399
- * @throws TypeError when `config` is malformed (no `commands` array, an empty
406
+ * @throws TypeError with `ESLINT_SH_WRAPPER_CONFIG` when `config` is malformed (no `commands` array, an empty
400
407
  * wrapper name, a subcommand restriction without `names`, or an empty or
401
408
  * non-string `docs.url` / `docs.description`).
402
409
  *
@@ -43,7 +43,7 @@ export function defineShellRule(spec) {
43
43
  // The type requires `meta`, but ESLint accepts a rule without one, so an
44
44
  // untyped (JavaScript) caller's missing `meta` is read as empty rather than
45
45
  // crashing. The types cannot see that caller, hence the suppression.
46
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
46
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Untyped JavaScript callers may omit the required metadata.
47
47
  const meta = spec.meta ?? {};
48
48
  // Drop the deprecated singular key an untyped caller may have supplied, so
49
49
  // the only language declaration ESLint sees is the one set here.
@@ -18,14 +18,6 @@ export interface NoDynamicInvocationOptions {
18
18
  * `dynamicInvocation`. Embedded commands still report.
19
19
  */
20
20
  readonly allowInFunctions?: readonly string[];
21
- /**
22
- * Command names to treat as transparent wrappers, in addition to the
23
- * built-in list: the word after one is the command that runs. Each is
24
- * followed by name only, with no options of its own, so a flag after it
25
- * makes the effective command unknown. A name already in the built-in list
26
- * keeps its built-in option handling.
27
- */
28
- readonly allowWrappers?: readonly string[];
29
21
  }
30
22
  /**
31
23
  * The `sh/no-dynamic-invocation` rule module.
@@ -22,7 +22,7 @@
22
22
  * reports as `dynamicInvocation`.
23
23
  * - The wrappers followed are `sh-ast/analyze`'s defaults, Bash's `builtin`,
24
24
  * shells invoked as commands (so `bash -c` is an embedded command and
25
- * `bash script.sh` runs `script.sh`), and the names in `allowWrappers`.
25
+ * `bash script.sh` runs `script.sh`), and the shared project wrapper facts.
26
26
  *
27
27
  * The analysis is syntactic by design: `cmd=ls; "$cmd"` reports, because
28
28
  * resolving it would need dataflow. Aliases need no handling: they are not
@@ -31,16 +31,12 @@
31
31
  * command is a human decision.
32
32
  */
33
33
  import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-ast/analyze';
34
+ import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
34
35
  import { createRule } from './create-rule.js';
35
36
  import { BUILTIN_WRAPPER, SHELL_WRAPPER } from './transparent-wrappers.js';
36
37
  /** The registry name of this rule (`sh/no-dynamic-invocation` in a user's config). */
37
38
  const RULE_NAME = 'no-dynamic-invocation';
38
- /**
39
- * The wrappers every invocation is followed through before any configured in
40
- * `allowWrappers`: `sh-ast/analyze`'s defaults, then Bash's `builtin`, then
41
- * shells invoked as commands. `resolveArgv0` uses the first entry whose name
42
- * matches, so the built-in entries take precedence over a user's.
43
- */
39
+ /** Default scope for dynamic invocations, including builtin and shell entrypoints. */
44
40
  const BUILT_IN_WRAPPERS = [
45
41
  ...DEFAULT_TRANSPARENT_WRAPPERS,
46
42
  BUILTIN_WRAPPER,
@@ -78,12 +74,11 @@ export const noDynamicInvocation = createRule({
78
74
  type: 'object',
79
75
  properties: {
80
76
  allowInFunctions: NAME_LIST_SCHEMA,
81
- allowWrappers: NAME_LIST_SCHEMA,
82
77
  },
83
78
  additionalProperties: false,
84
79
  },
85
80
  ],
86
- defaultOptions: [{ allowInFunctions: [], allowWrappers: [] }],
81
+ defaultOptions: [{ allowInFunctions: [] }],
87
82
  messages: {
88
83
  dynamicInvocation: 'The command this runs is not known until run time, so the script cannot be statically reviewed. Name the command with a literal word instead.',
89
84
  embeddedCommand: 'This runs shell code embedded in a string, which cannot be statically reviewed. Write the commands directly instead.',
@@ -91,13 +86,10 @@ export const noDynamicInvocation = createRule({
91
86
  },
92
87
  create(context) {
93
88
  const { sourceCode } = context;
94
- // `defaultOptions` guarantees the options object; either list may still be omitted in it.
95
- const [{ allowInFunctions = [], allowWrappers = [] }] = context.options;
89
+ // The options object exists by default; its dispatcher list may still be omitted.
90
+ const [{ allowInFunctions = [] }] = context.options;
96
91
  const dispatchers = new Set(allowInFunctions);
97
- const transparentWrappers = [
98
- ...BUILT_IN_WRAPPERS,
99
- ...allowWrappers.map((name) => ({ names: [name] })),
100
- ];
92
+ const transparentWrappers = resolveTransparentWrappers(context, BUILT_IN_WRAPPERS);
101
93
  return {
102
94
  File() {
103
95
  for (const site of sourceCode.getCommandSites()) {
@@ -25,6 +25,7 @@
25
25
  * suggestion, because no mechanical rewrite of `eval` preserves behavior.
26
26
  */
27
27
  import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-ast/analyze';
28
+ import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
28
29
  import { createRule } from './create-rule.js';
29
30
  import { BUILTIN_WRAPPER } from './transparent-wrappers.js';
30
31
  /** The registry name of this rule (`sh/no-eval` in a user's config). */
@@ -60,10 +61,11 @@ export const noEval = createRule({
60
61
  },
61
62
  create(context) {
62
63
  const { sourceCode } = context;
64
+ const transparentWrappers = resolveTransparentWrappers(context, TRANSPARENT_WRAPPERS);
63
65
  return {
64
66
  CallExpr(node) {
65
67
  const invoked = sourceCode.resolveInvokedCommand(node, {
66
- transparentWrappers: TRANSPARENT_WRAPPERS,
68
+ transparentWrappers,
67
69
  });
68
70
  if (!invoked?.effective.static) {
69
71
  return;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @internal
5
5
  */
6
- export interface NoMaskedExitStatusOptions {
6
+ interface NoMaskedExitStatusOptions {
7
7
  /** Report only where `errexit` is known to be on. Defaults to `false`. */
8
8
  readonly onlyWithErrexit?: boolean;
9
9
  /**
@@ -16,6 +16,7 @@ export interface NoMaskedExitStatusOptions {
16
16
  readonly builtins?: readonly string[];
17
17
  }
18
18
  /** Message ids this rule reports with. @internal */
19
- export type NoMaskedExitStatusMessageId = 'maskedExitStatus' | 'declareThenAssign' | 'assignThenExport' | 'assignThenReadonly';
19
+ type NoMaskedExitStatusMessageId = 'maskedExitStatus' | 'declareThenAssign' | 'assignThenExport' | 'assignThenReadonly';
20
20
  /** Built-in rule `sh/no-masked-exit-status`. @internal */
21
- export declare const noMaskedExitStatus: import("./define-shell-rule.js").ShellRule<[NoMaskedExitStatusOptions], NoMaskedExitStatusMessageId>;
21
+ declare const noMaskedExitStatus: import("./define-shell-rule.js").ShellRule<[NoMaskedExitStatusOptions], NoMaskedExitStatusMessageId>;
22
+ export { noMaskedExitStatus };
@@ -15,7 +15,8 @@
15
15
  * Real shells give a plain assignment the status of a substitution in any of
16
16
  * those places, so the declaration hides it from all of them. A process
17
17
  * substitution (`<(…)`) is not looked into: it expands to a path. The builtin
18
- * is also read behind the transparent wrappers `builtin` and `command`. One
18
+ * is also read behind the bare in-process wrappers `builtin` and `command`;
19
+ * paths to external executables are not declaration wrappers. One
19
20
  * report is made per operand, on the operand. An array value
20
21
  * (`local -a a=($(cmd))`) is not reported: shellcheck 0.11.0 does not report
21
22
  * it either, and a status-bearing scalar is the construct the rule exists for.
@@ -84,11 +85,12 @@
84
85
  * split into the declaration, the assignment, then `readonly <names>`.
85
86
  */
86
87
  import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-ast/analyze';
88
+ import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
87
89
  import { childNodes } from '../language/syntax-view.js';
88
90
  import { lineBreakOf } from '../language/line-breaks.js';
89
91
  import { createRule } from './create-rule.js';
90
92
  import { batsErrexitIsOn, isStatusChecked } from './no-unchecked-cd.js';
91
- import { setStatementChanges } from './require-strict-mode.js';
93
+ import { setStatementChanges } from './strict-mode-prologue.js';
92
94
  import { applySetOptionChanges, shebangOptionChanges } from './set-options.js';
93
95
  import { BUILTIN_WRAPPER } from './transparent-wrappers.js';
94
96
  /** Every declaration builtin the rule can check; the default for `builtins`. */
@@ -218,10 +220,13 @@ function collectFunctionNames(node, into) {
218
220
  * earlier, so such code can see a different variable afterwards. A function
219
221
  * defined in another file cannot be seen and is not detected.
220
222
  */
221
- function runsUnseenCode(node, functionNames, sourceCode) {
223
+ function runsUnseenCode(node, functionNames, sourceCode, transparentWrappers) {
222
224
  if (node.type === 'CallExpr' && node.args.length > 0) {
225
+ // This check names the launched program; opaque child-interpreter text
226
+ // does not turn its program identity into dynamic lookup.
223
227
  const invoked = sourceCode.resolveInvokedCommand(node, {
224
- transparentWrappers: TRANSPARENT_WRAPPERS,
228
+ transparentWrappers,
229
+ embeddedCommandInterpreters: [],
225
230
  });
226
231
  if (invoked?.effective.static !== true)
227
232
  return true;
@@ -229,7 +234,7 @@ function runsUnseenCode(node, functionNames, sourceCode) {
229
234
  if (CODE_RUNNING_BUILTINS.has(name) || functionNames.has(name))
230
235
  return true;
231
236
  }
232
- return childNodes(node).some((child) => runsUnseenCode(child, functionNames, sourceCode));
237
+ return childNodes(node).some((child) => runsUnseenCode(child, functionNames, sourceCode, transparentWrappers));
233
238
  }
234
239
  /**
235
240
  * The state of `errexit` before each top-level statement of `file`, from the
@@ -446,7 +451,7 @@ function withoutReadonly(flag) {
446
451
  * The replacement text for a standalone declaration, or `null` where no
447
452
  * equivalent split exists. `separator` joins the statements.
448
453
  */
449
- function splitText(declaration, scoped, separator, functionNames, sourceCode) {
454
+ function splitText(declaration, scoped, separator, functionNames, sourceCode, transparentWrappers) {
450
455
  const { variant, flags, operands, flagsKnown } = declaration;
451
456
  if (!flagsKnown || operands.some((operand) => operand.unsplittable))
452
457
  return null;
@@ -489,7 +494,7 @@ function splitText(declaration, scoped, separator, functionNames, sourceCode) {
489
494
  // operand declares nothing that code could observe differently.
490
495
  const mayObserveDeclaration = scoped || operands.length > 1 || flags.length > 0;
491
496
  if (mayObserveDeclaration &&
492
- operands.some((operand) => operand.values.some((value) => runsUnseenCode(value, functionNames, sourceCode)))) {
497
+ operands.some((operand) => operand.values.some((value) => runsUnseenCode(value, functionNames, sourceCode, transparentWrappers)))) {
493
498
  return null;
494
499
  }
495
500
  const makesReadonly = isReadonlyBuiltin || flags.some(isReadonlyFlag);
@@ -530,7 +535,7 @@ function splitText(declaration, scoped, separator, functionNames, sourceCode) {
530
535
  };
531
536
  }
532
537
  /** Built-in rule `sh/no-masked-exit-status`. @internal */
533
- export const noMaskedExitStatus = createRule({
538
+ const noMaskedExitStatus = createRule({
534
539
  name: 'no-masked-exit-status',
535
540
  meta: {
536
541
  type: 'problem',
@@ -567,6 +572,7 @@ export const noMaskedExitStatus = createRule({
567
572
  create(context) {
568
573
  const [options] = context.options;
569
574
  const { sourceCode } = context;
575
+ const transparentWrappers = resolveTransparentWrappers(context, TRANSPARENT_WRAPPERS);
570
576
  const checked = new Set(options.builtins ?? ALL_BUILTINS);
571
577
  const parentOf = (node) => sourceCode.getParent(node);
572
578
  let errexitBefore = new Map();
@@ -613,7 +619,7 @@ export const noMaskedExitStatus = createRule({
613
619
  const indent = text.slice(lineStart + 1, start);
614
620
  const separator = /^[ \t]*$/u.test(indent) ? lineBreakOf(text) + indent : '; ';
615
621
  const scoped = SCOPED_BUILTINS.has(builtin) && inFunction;
616
- suggestion = splitText(declaration, scoped, separator, functionNames, sourceCode);
622
+ suggestion = splitText(declaration, scoped, separator, functionNames, sourceCode, transparentWrappers);
617
623
  }
618
624
  for (const operand of substituted) {
619
625
  context.report({
@@ -645,7 +651,8 @@ export const noMaskedExitStatus = createRule({
645
651
  },
646
652
  CallExpr(node) {
647
653
  const invoked = sourceCode.resolveInvokedCommand(node, {
648
- transparentWrappers: TRANSPARENT_WRAPPERS,
654
+ transparentWrappers,
655
+ embeddedCommandInterpreters: [],
649
656
  });
650
657
  if (invoked?.effective.static !== true)
651
658
  return;
@@ -665,3 +672,4 @@ export const noMaskedExitStatus = createRule({
665
672
  };
666
673
  },
667
674
  });
675
+ export { noMaskedExitStatus };
@@ -5,13 +5,16 @@
5
5
  */
6
6
  export interface NoSecretEnvReadsOptions {
7
7
  /**
8
- * Regex sources tested against each expanded variable's name. Replaces
8
+ * Case-sensitive Unicode regex sources tested against each expanded
9
+ * variable's name. Replaces
9
10
  * {@link DEFAULT_PATTERNS} entirely.
10
11
  */
11
12
  readonly patterns?: readonly string[];
13
+ /** Regex sources added to `patterns`, or to the built-in defaults when it is omitted. */
14
+ readonly additionalPatterns?: readonly string[];
12
15
  /**
13
- * Command names whose arguments may read a secret-shaped variable. A
14
- * command run by path matches by basename.
16
+ * Command names whose own arguments may read a secret-shaped variable. Wrapper-owned operands are still checked normally. A command
17
+ * run by path matches by basename.
15
18
  */
16
19
  readonly allowedSinks?: readonly string[];
17
20
  }
@@ -22,12 +22,14 @@
22
22
  * command that runs (`TOKEN=$GITHUB_TOKEN tool`) is the recommended
23
23
  * pattern and is clean. A read nested deeper (a command substitution in
24
24
  * that value) belongs to the inner command and is judged there.
25
- * - A read in the arguments of an allow-listed sink command is clean. The
26
- * command is the nearest enclosing `CallExpr`, resolved through
27
- * transparent wrappers by `ShellSourceCode#resolveInvokedCommand`.
25
+ * - A read in an argument after the final allow-listed sink command is clean.
26
+ * Wrapper-owned flags and operands receive no sink exemption. The nearest
27
+ * enclosing `CallExpr` supplies argv ownership, and its resolved final
28
+ * command index separates wrapper operands from the sink's arguments.
28
29
  * - Matching is a name pattern, not secret detection.
29
30
  */
30
31
  import { AlternateUnset, AlternateUnsetOrNull } from 'sh-ast/analyze';
32
+ import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
31
33
  import { createRule } from './create-rule.js';
32
34
  import { compileUserPattern } from './user-pattern.js';
33
35
  /**
@@ -69,10 +71,17 @@ export const noSecretEnvReads = createRule({
69
71
  {
70
72
  type: 'object',
71
73
  properties: {
74
+ additionalPatterns: {
75
+ type: 'array',
76
+ // Validate with the rule's actual Unicode/case flags in create(),
77
+ // so syntax and safety errors identify the original option and source.
78
+ items: { type: 'string' },
79
+ },
72
80
  patterns: {
73
81
  type: 'array',
74
- items: { type: 'string', format: 'regex' },
75
- minItems: 1,
82
+ // The shared compiler validates Unicode syntax and identifies
83
+ // the option index and source; flagless schema checks cannot.
84
+ items: { type: 'string' },
76
85
  },
77
86
  allowedSinks: {
78
87
  type: 'array',
@@ -89,33 +98,58 @@ export const noSecretEnvReads = createRule({
89
98
  },
90
99
  create(context) {
91
100
  const options = context.options[0];
92
- const patterns = (options?.patterns ?? DEFAULT_PATTERNS).map((source, index) => compileUserPattern('sh/no-secret-env-reads', `patterns[${String(index)}]`, source, ''));
101
+ // An explicit replacement, including [], owns the base policy. Additions
102
+ // extend that base per file; compile separately to retain each option's identity.
103
+ // Diagnostic rule paths follow the configured ID, including plugin registration aliases.
104
+ const patterns = [
105
+ ...(options?.patterns ?? DEFAULT_PATTERNS).map((source, index) => compileUserPattern(context.id, `patterns[${String(index)}]`, source, 'u')),
106
+ ...(options?.additionalPatterns ?? []).map((source, index) => compileUserPattern(context.id, `additionalPatterns[${String(index)}]`, source, 'u')),
107
+ ];
93
108
  const allowedSinks = new Set(options?.allowedSinks ?? []);
94
109
  const { sourceCode } = context;
110
+ const transparentWrappers = resolveTransparentWrappers(context);
95
111
  const isSecretName = (name) => patterns.some((pattern) => pattern.test(name));
96
- /** Whether the command that `callExpr` runs, wrappers followed, is an allowed sink. */
97
- function isAllowedSink(callExpr) {
98
- if (allowedSinks.size === 0)
112
+ /** Whether this direct argument word belongs to the final approved sink. */
113
+ function isAllowedSink(callExpr, argument) {
114
+ if (allowedSinks.size === 0 || argument.type !== 'Word') {
99
115
  return false;
100
- const effective = sourceCode.resolveInvokedCommand(callExpr)?.effective;
101
- if (!effective?.static)
116
+ }
117
+ // Sink policy names the program receiving these arguments. An interpreter's
118
+ // command-string selector does not change that recipient; judging its code
119
+ // belongs to no-dynamic-invocation rather than this explicit allowance.
120
+ const invoked = sourceCode.resolveInvokedCommand(callExpr, {
121
+ transparentWrappers,
122
+ embeddedCommandInterpreters: [],
123
+ });
124
+ if (!invoked?.effective.static) {
102
125
  return false;
126
+ }
127
+ const effectiveIndex = invoked.chainIndices.at(-1);
128
+ if (effectiveIndex === undefined || callExpr.args.indexOf(argument) <= effectiveIndex) {
129
+ return false;
130
+ }
131
+ const { effective } = invoked;
103
132
  return allowedSinks.has(effective.text) || allowedSinks.has(basename(effective.text));
104
133
  }
105
134
  /**
106
- * Whether the read at `node` is permitted: it sits in the arguments of an
107
- * allowed sink, or directly in an assignment prefix of a command that runs.
135
+ * Whether the read at `node` is permitted: it sits in an actual argument of
136
+ * the final allowed sink, or in an assignment prefix of a command that runs.
108
137
  * The nearest enclosing `Assign` or `CallExpr` decides, so a read inside a
109
138
  * command substitution is judged by the inner command, not the outer one.
110
139
  */
111
140
  function isPermittedRead(node) {
141
+ // Keep the direct child by identity: argument ownership needs no range
142
+ // arithmetic and nested commands retain their own nearest call boundary.
143
+ let child = node;
112
144
  for (let up = sourceCode.getParent(node); up !== undefined; up = sourceCode.getParent(up)) {
113
- if (up.type === 'CallExpr')
114
- return isAllowedSink(up);
145
+ if (up.type === 'CallExpr') {
146
+ return isAllowedSink(up, child);
147
+ }
115
148
  if (up.type === 'Assign') {
116
149
  const owner = sourceCode.getParent(up);
117
150
  return owner?.type === 'CallExpr' && owner.args.length > 0;
118
151
  }
152
+ child = up;
119
153
  }
120
154
  return false;
121
155
  }
@@ -7,9 +7,12 @@ import type { ShellNode } from '../language/syntax-view.js';
7
7
  export interface NoSecretFlagsOptions {
8
8
  /**
9
9
  * Regex sources tested against each flag's name (the word up to, not
10
- * including, its first `=`). Replaces {@link DEFAULT_PATTERNS} entirely.
10
+ * including, its first `=`), with Unicode case-insensitive matching.
11
+ * Replaces {@link DEFAULT_PATTERNS} entirely.
11
12
  */
12
13
  readonly patterns?: readonly string[];
14
+ /** Regex sources added to `patterns`, or to the built-in defaults when it is omitted. */
15
+ readonly additionalPatterns?: readonly string[];
13
16
  }
14
17
  /**
15
18
  * One secret-shaped flag found in a command's arguments.