@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
package/docs/compat.md CHANGED
@@ -5,14 +5,14 @@ are for scripts that must run on an older Bash, such as the Bash 3.2 that macOS
5
5
  `/bin/bash`, or on a plain POSIX `sh`.
6
6
 
7
7
  `compat/*` is reserved for version gates: rules that read the gate table below and your
8
- `shellVersion`/`dialect`. A rule that checks the file against your config without reading the
8
+ `minBashVersion`/`dialect`. A rule that checks the file against your config without reading the
9
9
  target, such as [`sh/shebang-matches-dialect`](./rules/shebang-matches-dialect.md), lives outside
10
10
  the namespace.
11
11
 
12
- The parser does not do this for you. It accepts everything its grammar knows, whatever target
13
- you configure: Bash mode parses `declare -A` and `mapfile` even with `shellVersion: "3.2"`, and
12
+ The parser does not do this for you. It accepts everything its grammar knows, whatever support requirement
13
+ you configure: Bash mode parses `declare -A` and `mapfile` even with `minBashVersion: "3.2"`, and
14
14
  POSIX mode parses `declare -A` as an ordinary command. Only the `compat/*` rules enforce the
15
- target.
15
+ support requirement.
16
16
 
17
17
  A `compat/*` finding stays reported when the code is behind a runtime version guard
18
18
  (`if (( BASH_VERSINFO[0] >= 4 )); then …`): the rules do not follow control flow. Silence a guarded
@@ -65,11 +65,12 @@ points but 4.3 for U+0080 to U+00FF, because the Bash 4.2 release writes those a
65
65
  instead of UTF-8. `sh/compat/no-nounset-empty-array` gates a behavior, not syntax: every Bash has
66
66
  `"${a[@]}"`, but through 4.3 an empty array aborts the script under `set -u`. `every` means every Bash release has the feature, so only
67
67
  `dialect: "posix"` can lack it: those three are the POSIX-only gates, and the other twenty-two are
68
- the version gates. The `bash-3.2` preset enables the version gates and the `posix-portable` preset
69
- enables all twenty-five; see
68
+ the version gates. The `bash-3.2` preset enables twenty-one version gates, excluding the opt-in
69
+ `sh/compat/no-nounset-empty-array`, and the `posix-portable` preset
70
+ enables twenty-four, omitting the Bash-only empty-array check that cannot fire there; see
70
71
  [Presets](#presets).
71
72
 
72
- ## Setting the target
73
+ ## Setting required shell support
73
74
 
74
75
  Every `compat/*` rule reads the same two `languageOptions`, and nothing else. They have no rule
75
76
  options of their own:
@@ -82,7 +83,7 @@ import sh from '@eslint-sh/eslint-plugin';
82
83
  export default defineConfig({
83
84
  files: ['**/*.sh'],
84
85
  extends: [sh.configs.recommended],
85
- languageOptions: { dialect: 'bash', shellVersion: '3.2' },
86
+ languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
86
87
  rules: {
87
88
  'sh/compat/no-associative-arrays': 'error',
88
89
  'sh/compat/no-mapfile': 'error',
@@ -93,37 +94,70 @@ export default defineConfig({
93
94
 
94
95
  A gated feature is available, and its rule reports nothing, according to these rules:
95
96
 
96
- - **`shellVersion` unset means the newest version.** With no `shellVersion`, every Bash feature
97
- is available and no `compat/*` rule reports under `dialect: "bash"`. Set a version to opt in.
98
- - **Versions compare numerically, major first, then minor.** `shellVersion` has the shape
97
+ - **`minBashVersion` is a floor.** `"3.2"` means the script must support Bash 3.2 and
98
+ every newer Bash. Nothing checks for a version being too new. Unset means no Bash
99
+ version constraint, so Bash version gates report nothing under `bash` or `bats`.
100
+ - **Versions compare numerically, major first, then minor.** `minBashVersion` has the shape
99
101
  `MAJOR[.MINOR]`. A missing minor is `0`, so `"4"` is the same as `"4.0"`. Each part is a
100
102
  number, not text, so `"3.10"` is newer than `"3.2"` and still older than `"4.0"`. A feature
101
- is available when `shellVersion` is its minimum version or newer.
102
- - **`dialect: "posix"` makes Bash-only features unavailable at any `shellVersion`.** A POSIX sh
103
- script cannot rely on a feature that only Bash has, whatever version number is configured.
104
- - **`dialect: "bats"` is gated as Bash**, because Bats test files run under Bash.
105
- `shellVersion` is the version of that Bash.
106
- - **`dialect: "mksh"` and `dialect: "zsh"` are not gated.** These shells number their own
107
- releases, so a `shellVersion` there is not a Bash version, and the rules have no data on
108
- which of their releases added which feature. The `compat/*` rules report nothing for them.
103
+ is available when the configured floor is its first Bash release or newer.
104
+ - **Only `bash` and `bats` accept `minBashVersion`.** An omitted `dialect` defaults to
105
+ `bash`. Bats test files run under Bash and use the same floor. With `posix`, `mksh` or
106
+ `zsh`, remove `minBashVersion` or change the dialect to `bash` or `bats`; otherwise
107
+ ESLint rejects the config before linting.
108
+ - **`dialect: "posix"` makes Bash-only features unavailable.** A POSIX sh script cannot
109
+ rely on a feature that only Bash has.
110
+ - **`dialect: "mksh"` and `dialect: "zsh"` are not gated.** The table has no release data
111
+ for these shells, so the `compat/*` rules report nothing for them.
112
+
113
+ ### Migrating from `shellVersion`
114
+
115
+ Replace `languageOptions.shellVersion` with `languageOptions.minBashVersion` and custom
116
+ rule reads of `sourceCode.shellVersion` with `sourceCode.minBashVersion`. The old option
117
+ is removed, with no alias: ESLint rejects it with migration guidance. The normalized and
118
+ JSON option types use `minBashVersion` too. For `posix`, `mksh` and `zsh`, remove the old
119
+ option rather than renaming it, because a Bash floor does not apply to these dialects.
120
+
121
+ Check inherited options too. Extending `sh.configs['bash-3.2']` and then setting
122
+ `languageOptions: { dialect: 'posix' }` retains the preset's Bash 3.2 floor and now
123
+ throws a config error. Extending `[sh.configs['bash-3.2'], sh.configs['posix-portable']]`
124
+ also throws: the later POSIX preset changes the dialect without removing the inherited
125
+ floor. Setting `minBashVersion: undefined` does **not** clear that floor during ESLint's
126
+ config merge, so it does not fix either composition.
127
+
128
+ For scripts that must support POSIX sh, replace the Bash preset with the intended POSIX
129
+ preset, without inheriting `bash-3.2` from any config that applies to those files:
130
+
131
+ ```js
132
+ // eslint.config.js
133
+ import { defineConfig } from 'eslint/config';
134
+ import sh from '@eslint-sh/eslint-plugin';
135
+
136
+ export default defineConfig({
137
+ files: ['**/*.sh'],
138
+ extends: [sh.configs.recommended, sh.configs['posix-portable']],
139
+ });
140
+ ```
109
141
 
110
142
  ## Presets
111
143
 
112
- Two presets name a deployment target and enable every rule that enforces it, so you do not list
113
- the rules yourself:
144
+ Two presets name a deployment target and enable its checks, with the empty-array nounset check
145
+ an explicit opt-in for Bash:
114
146
 
115
- - **`sh.configs['bash-3.2']`** sets `languageOptions: { dialect: 'bash', shellVersion: '3.2' }`
116
- and enables all twenty-two version-gated `compat/*` rules at `error`. Use it for scripts that must run on the Bash
117
- 3.2 that macOS ships as `/bin/bash`.
147
+ - **`sh.configs['bash-3.2']`** sets `languageOptions: { dialect: 'bash', minBashVersion: '3.2' }`
148
+ and enables twenty-one version-gated `compat/*` rules at `error`. Use it for scripts that must run on the Bash
149
+ 3.2 that macOS ships as `/bin/bash`. It leaves `sh/compat/no-nounset-empty-array` off: enable
150
+ that rule explicitly when a script uses `set -u` and arrays that can really be empty. The rule
151
+ cannot prove safety across every caller or helper contract; see its
152
+ [configuration example](./rules/compat/no-nounset-empty-array.md#options).
118
153
  - **`sh.configs['posix-portable']`** reports the Bash-only constructs in the table above, which
119
154
  fail or read as unset on dash, but not `local`, `echo -e` or the others listed under
120
155
  [What `posix-portable` does not report](#what-posix-portable-does-not-report), so a clean run does
121
156
  not prove a script runs under every POSIX `sh`. It sets `languageOptions: { dialect: 'posix' }` and
122
- enables all twenty-five `compat/*` rules, `sh/shebang-matches-dialect`, and
123
- `sh/require-strict-mode` configured as `set -eu`, all at `error`. Strict mode is `set -eu` and not
124
- `set -euo pipefail` because `pipefail` joined POSIX only in POSIX.1-2024, and older `dash` and
125
- BusyBox `ash` reject it, so a `pipefail` requirement would make the autofix break a working
126
- `#!/bin/sh` script.
157
+ enables twenty-four effective `compat/*` rules and `sh/shebang-matches-dialect`, all at `error`.
158
+ The shebang check verifies that the declared interpreter agrees with the target dialect.
159
+ It excludes the Bash-only empty-array nounset rule and imposes no strict-mode policy.
160
+ Compose `recommended` to require its dialect-aware POSIX `set -eu` default.
127
161
 
128
162
  Both presets are single objects with no `files`; extend them from an entry that lists your
129
163
  scripts, after `recommended` if you want its rules too:
@@ -223,6 +257,14 @@ is installed system-wide), and runs every probe in
223
257
  scripts/compat-matrix/run.sh
224
258
  ```
225
259
 
260
+ Builds use at most two compiler jobs and retry serially if parallel `make` fails. Bash 3.2–4.2
261
+ use `config.guess` and `config.sub` from the checksum-pinned Bash 5.3 archive so their configure
262
+ scripts recognize aarch64, including Linux containers on Apple Silicon. Only platform-detection
263
+ helpers are replaced; the shell sources retain their pinned release checksums. The script keeps
264
+ running other shells after a failure, labels the affected column `download failed`,
265
+ `checksum mismatch`, or `build failed`, and exits 1 after printing the table. Invalid arguments,
266
+ including an inaccessible `--probes` directory, exit 2.
267
+
226
268
  A probe is a short script that uses one feature, or one recommended alternative, and prints a known
227
269
  value. "yes" means the shell ran it, exited 0, and printed exactly that value; "no" means it did not.
228
270
  Each Bash column is the x.y release tarball with no upstream patches applied, pinned by SHA-256 in
@@ -282,11 +324,11 @@ the script. The `dash` column is the evidence for the POSIX sh column.
282
324
  | `nounset-empty-array-star-alt` | the suggestion's `"${a[*]-}"` under `set -u` gives one empty word for an empty array, and the joined words otherwise | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | no |
283
325
  | `nounset-empty-array-star` | `"${a[*]}"` and unquoted `${a[@]}` of an empty array under `set -u` | no | no | no | no | no | yes | yes | yes | yes | yes | no |
284
326
  | `nounset-empty-array` | `"${a[@]}"` of an empty array under `set -u` | no | no | no | no | no | yes | yes | yes | yes | yes | no |
285
- | `param-transform-alt-case-operators` | the case messages' Bash 4.0 spellings for a target from 4.0 to 5.0: `"${v^^}"`, `"${v^}"`, `"${V,,}"` | no | yes | yes | yes | yes | yes | yes | yes | yes | yes | no |
327
+ | `param-transform-alt-case-operators` | the case messages' Bash 4.0 spellings when the minimum supported Bash is from 4.0 to 5.0: `"${v^^}"`, `"${v^}"`, `"${V,,}"` | no | yes | yes | yes | yes | yes | yes | yes | yes | yes | no |
286
328
  | `param-transform-alt-declare-p` | the `@A` message's `declare -p`, whose output re-creates the variable | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | no |
287
329
  | `param-transform-alt-printf-b` | the `@E` message's `printf '%b'` expanding backslash escapes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes |
288
330
  | `param-transform-alt-printf-q` | the `@Q` message's `printf '%q'`, whose output `eval` reads back as the same value | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | no |
289
- | `param-transform-alt-tr` | the `tr` examples the `@U`, `@u` and `@L` messages print for a target older than 4.0, written exactly as printed | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes |
331
+ | `param-transform-alt-tr` | the `tr` examples the `@U`, `@u` and `@L` messages print when the minimum supported Bash is older than 4.0, written exactly as printed | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes |
290
332
  | `param-transform-eapa` | the other Bash 4.4 operators `${v@E}`, `${v@P}`, `${v@A}`, `${v@a}` | no | no | no | no | no | yes | yes | yes | yes | yes | no |
291
333
  | `param-transform-k-lower` | `${a[@]@k}` key-value pairs as separate words | no | no | no | no | no | no | no | no | yes | yes | no |
292
334
  | `param-transform-k-upper` | `${a[@]@K}` quoted key-value pairs | no | no | no | no | no | no | no | yes | yes | yes | no |
@@ -315,7 +357,7 @@ How to read it:
315
357
  matrix because it is the release just before the 4.2 boundary of `declare -g` and `lastpipe`.
316
358
  Bash 4.0 is the release just before the 4.1 boundary of `{fd}` redirections.
317
359
  - **POSIX-only gates.** The rows for `[[`, `let` and `source`, the rule table's `every`, are "yes" on
318
- every Bash in the matrix and "no" under dash, so no `shellVersion` can change whether they report.
360
+ every Bash in the matrix and "no" under dash, so no `minBashVersion` can change whether they report.
319
361
  dash runs a script past each one without a syntax error, which is why a shell's own version check
320
362
  can guard them; see [A branch for one shell](#a-branch-for-one-shell).
321
363
  - **Parameter transformations.** `@Q`, `@E`, `@P`, `@A` and `@a` start working in 4.4; `@U`, `@u`,
@@ -340,7 +382,7 @@ How to read it:
340
382
  running `scripts/compat-matrix/run.sh`.
341
383
  - **Alternatives.** Every alternative a message recommends for a Bash target works on Bash 3.2,
342
384
  except `param-transform-alt-case-operators` (`"${v^^}"` and its twins), which the
343
- `no-parameter-transformation` message offers only for a target from 4.0 to 5.0, where it works.
385
+ `no-parameter-transformation` message offers only when the minimum supported Bash is from 4.0 to 5.0, where it works.
344
386
  The ones that are "no" under dash (`< <(cmd)`, the `mapfile` suggestion's array loop, the
345
387
  `${arr[$((${#arr[@]}-1))]}` count, `printf -v`, `printf '%q'`, `declare -p`, the `${a[@]+…}` and
346
388
  `${a[*]-}` guards, `$'\303\251'`) use Bash syntax and appear only in Bash-target messages; the
@@ -351,4 +393,10 @@ How to read it:
351
393
  `date`. `%s` is not in POSIX `date`; the message says so.
352
394
  - **`jq`.** The `no-associative-arrays` advice runs an external program, so its row shows that the
353
395
  command as written works wherever `jq` is installed, not that a shell provides it.
396
+ - **Plain assignments.** `declare-g-alt-assign` confirms that `name=value` and `export name=value`
397
+ inside a function leave values visible after the function returns when no caller has a
398
+ same-named local. It is not a discriminating test of `declare -g`: ordinary assignment follows
399
+ a caller's local scope, whereas `declare -g` explicitly targets the global in Bash 4.3–5.3 but
400
+ assigns a same-named caller local in Bash 4.2, leaving the global unset. The row does not
401
+ establish that the plain-assignment advice is interchangeable with `declare -g` in that case.
354
402
 
@@ -23,9 +23,12 @@ project's `"type"` field.
23
23
 
24
24
  ## 1. Pick a selector from the cookbook
25
25
 
26
- The cookbook's `:command` [launch class](./selectors.md#the-six-launch-classes) matches every
27
- `CallExpr` node — every shell command invocation. That's the selector this tutorial's rule listens
28
- on; `create()` then narrows further (is the command `rm`? does it pass recursive and force short
26
+ The cookbook's `:command` [launch class](./selectors.md#the-six-launch-classes) matches
27
+ `CallExpr` nodes with a command word, exactly the calls in `sourceCode.getCommandSites()`.
28
+ An assignment-only statement such as `FOO=1` does not match; `FOO=1 jq .`, `true`, `:`, and
29
+ dynamic invocations such as `"$tool" file` do. Select `CallExpr` directly to include
30
+ assignment-only calls. This tutorial's rule listens on `:command`; `create()` then narrows further
31
+ (is the command `rm`? does it pass recursive and force short
29
32
  flags, such as `-rf`, `-fr`, or `-r -f`?) the same way a hand-written rule narrows any other
30
33
  selector-first ESLint rule.
31
34
 
@@ -46,15 +49,15 @@ selector-first ESLint rule.
46
49
  * for it, so ESLint refuses to run the rule on a file of any other language.
47
50
  *
48
51
  * Built on the `:command` launch class from the selector cookbook
49
- * (`../selectors.md`) — `:command` matches every `CallExpr`, so `create()`
52
+ * (`../selectors.md`) — `:command` matches calls with a command word, so `create()`
50
53
  * narrows further by inspecting the command word and its flag arguments,
51
54
  * exactly the pattern the cookbook's intro describes ("writing a rule as a
52
55
  * selector string rather than a `create()` full of manual type checks" —
53
56
  * here the selector does the node-type narrowing, `create()` only does the
54
57
  * domain-specific check).
55
58
  *
56
- * Flag words are resolved with `@eslint-sh/eslint-plugin`'s view-aware
57
- * `resolveWord` (backed by `sh-ast/analyze`) rather than a
59
+ * Flag words are resolved with `context.sourceCode.resolveWord`
60
+ * (backed by `sh-ast/analyze`) rather than a
58
61
  * hand-rolled scan: a word is only treated as a short-option cluster
59
62
  * when it is *statically* that string (bare or
60
63
  * quoted literal concatenations). Recursive (`r`/`R`) and force (`f`)
@@ -64,16 +67,14 @@ selector-first ESLint rule.
64
67
  * A word containing a `ParamExp`/`CmdSubst`/`ArithmExp`/
65
68
  * `ProcSubst` resolves to `{ static: false, reason }` (`'expansion'`,
66
69
  * `'tilde'`, `'glob'`, …) rather than being silently erased into a static
67
- * match — see `resolveWord`'s API docs. Importing
68
- * it from the plugin package (rather than `sh-ast/analyze` directly) means
69
- * a project that installs only `@eslint-sh/eslint-plugin` has everything
70
- * this rule needs, with no separate `sh-ast` install or npm-hoisting
71
- * reliance.
70
+ * match — see `ShellSourceCode.resolveWord`'s API docs. The source instance
71
+ * comes from ESLint, so the rule needs no separate `sh-ast` install or
72
+ * dependency-hoisting reliance.
72
73
  *
73
74
  * @see ../custom-rule-tutorial.md — the tutorial this rule backs
74
75
  * @see ../selectors.md — the `:command` launch class
75
76
  */
76
- import { defineShellRule, resolveWord } from '@eslint-sh/eslint-plugin';
77
+ import { defineShellRule } from '@eslint-sh/eslint-plugin';
77
78
 
78
79
  const noRmRf = defineShellRule({
79
80
  meta: {
@@ -91,7 +92,7 @@ const noRmRf = defineShellRule({
91
92
  ':command'(node) {
92
93
  const args = node.args ?? [];
93
94
  const words = args.map((arg) => {
94
- const resolved = resolveWord(arg, { context: 'command-argument' });
95
+ const resolved = context.sourceCode.resolveWord(arg);
95
96
  return resolved.static ? resolved.text : null;
96
97
  });
97
98
 
@@ -138,14 +139,15 @@ compile error. Everything else in `meta`, including your own `docs.url`, is kept
138
139
 
139
140
  A few things worth calling out:
140
141
 
141
- - `defineShellRule` and `resolveWord` both come from `@eslint-sh/eslint-plugin` (or the umbrella
142
- `eslint-sh`). A rule needs no other package: not `sh-ast`, and not `@eslint/core`.
142
+ - `defineShellRule` comes from `@eslint-sh/eslint-plugin` (or the umbrella `eslint-sh`).
143
+ ESLint supplies `context.sourceCode`, including its word-resolution method. A rule needs no
144
+ separate `sh-ast` or `@eslint/core` dependency.
143
145
  - The listener key, `':command'`, is a selector string — one of the [six launch
144
146
  classes](./selectors.md#the-six-launch-classes) — not a bare node-type name. ESLint's
145
147
  `esquery`-based rule-listener matching (via `ShellLanguage.matchesSelectorClass`) treats it
146
148
  exactly like any other selector key such as `CallExpr` or `CallExpr[args.0.parts.0.value='jq']`.
147
- - `resolveWord(arg, { context: 'command-argument' })` — exported from `@eslint-sh/eslint-plugin`
148
- (using the raw Word associated with the lint view) — is the correct way to ask "is this word statically the string X":
149
+ - `context.sourceCode.resolveWord(arg)` uses the raw Word associated with the lint view and
150
+ defaults to command-argument context for `CallExpr.args`. It is the way to ask "is this word statically the string X":
149
151
  it returns `{ static: true, text }` for a bare or
150
152
  quoted literal (`rm`, `'r'm`, `"-rf"` all resolve), and `{ static: false, reason }` the moment any
151
153
  part of the word depends on a `ParamExp`/`CmdSubst`/`ArithmExp`/`ProcSubst` — never inventing a
@@ -421,6 +423,11 @@ with, so you don't install `sh-ast` and its version always matches the records `
421
423
  They track the plugin's pinned `sh-ast` minor: an `sh-ast` 0.x minor bump is a minor release of the
422
424
  plugin.
423
425
 
426
+ The low-level `/syntax` export `printSync` retains upstream behavior: literal vertical tabs and
427
+ form feeds can change during printing, including inside quotes. It does not apply the high-level
428
+ content refusal used by `format` or `getPrintedReplacement`. For an ESLint printed fix, use
429
+ `getPrintedReplacement`, which refuses these values with `TypeError`.
430
+
424
431
  ## 8. Printed fixes
425
432
 
426
433
  Some fixes are easier to describe as an edit to the syntax than as new text. Turning
@@ -431,13 +438,14 @@ into an ESLint fix:
431
438
  - `getEditableSyntax(node)` returns an independent copy of the sh-ast record `node` was parsed
432
439
  from. It is an ordinary `structuredClone` of that record, which sh-ast documents as the supported
433
440
  way to get an editable copy. Edit the copy freely: the original record that `getSyntax` returns,
434
- the lint view, and helpers such as `resolveWord` keep seeing the original source. It throws a
441
+ the lint view, and helpers such as `context.sourceCode.resolveWord` keep seeing the original source. It throws a
435
442
  `TypeError` for a node that has no record of its own, such as one you built yourself.
436
443
  - `getPrintedReplacement(node, edited, options)` prints `edited` with sh-ast's `printSync` and
437
444
  returns `{ range, text }`, ready for `fixer.replaceTextRange(range, text)`. The range is
438
445
  `node.range`, or the whole file when `edited` is a `File`. `edited` must be a root `printSync`
439
446
  accepts (`File`, `Stmt`, `Word`, `Assign`, a `Command` or a `WordPart`), and output that is not
440
- valid UTF-8 throws a `TypeError` instead of becoming a fix.
447
+ valid UTF-8 or edited syntax containing literal vertical tabs or form feeds throws a `TypeError`
448
+ instead of becoming a fix. A `File`'s `Name` is unprinted metadata and does not trigger that refusal.
441
449
 
442
450
  `docs/examples/no-backticks-rule.mjs` reports backtick command substitution and fixes it to `$(…)`:
443
451
 
@@ -714,13 +722,13 @@ import type { ShellCommandSite, ShellRuleContext } from '@eslint-sh/eslint-plugi
714
722
  /** The rule's one options object; `commands` defaults to `[]`. */
715
723
  type Options = [{ commands?: string[] }?];
716
724
 
717
- /** Reports `site` when the command it runs, after wrappers, is in `listed`. */
725
+ /** Reports the program named by `site`, after wrappers, including interpreters running strings. */
718
726
  function reportIfListed(
719
727
  context: ShellRuleContext<Options, 'listed'>,
720
728
  site: ShellCommandSite,
721
729
  listed: ReadonlySet<string>,
722
730
  ): void {
723
- const { effective } = site.resolveInvokedCommand();
731
+ const { effective } = site.resolveInvokedCommand({ embeddedCommandInterpreters: [] });
724
732
  if (effective.static && listed.has(effective.text)) {
725
733
  context.report({ node: site.node, messageId: 'listed', data: { name: effective.text } });
726
734
  }
@@ -924,3 +932,5 @@ TypeError: ESLint configuration in rule-tester is invalid: Key "language": Could
924
932
 
925
933
  Both appear when the test file runs, before any case is checked. A rule built with `defineShellRule`
926
934
  declares `meta.languages: ['sh/sh']`, so ESLint refuses to run it under any other language.
935
+
936
+ See [error codes](error-codes.md) for stable failure identities, source-helper argument boundaries, and dependency pass-through behavior.
@@ -395,20 +395,20 @@ cache and the snapshot that invalidates it, are tested in this package's test su
395
395
  ## Reading the convention in your own rule
396
396
 
397
397
  `sh/no-undeclared-commands` and `sh/no-unused-declarations` are the built-in rules that read the
398
- bound convention. A rule of your own reads it through the same two functions from
399
- `@eslint-sh/eslint-plugin`, so it gets the same behavior without re-implementing it:
400
-
401
- - **`resolveDeclarationConvention(context)`**, from `create()`, returns the convention from the
402
- rule's own `declarationConvention` option, else from `settings.sh.declarationConvention`, else
403
- `null`. With `null`, return no listeners: there is nothing to check. A bound value that isn't a
404
- convention throws the configuration error the built-in rules throw, naming the setting:
405
- `Invalid settings.sh.declarationConvention: expected a declaration convention`, and so on.
406
- - **`readDeclaredCommands(convention, context)`**, from a listener, returns the declarations for
407
- the file `context` is linting. It hands the convention the `LintedFile`, so a sidecar
408
- convention works in your rule too, and it checks every declaration exactly as the built-in
409
- rules do. A missing or unknown `kind`, a missing field, or a `range` outside the text throws
410
- `Invalid settings.sh.declarationConvention: …`. Don't call `convention.declaredCommands` directly: you would get unchecked
411
- values.
398
+ bound convention. A rule of your own calls **`getDeclaredCommands(context)`** from a listener.
399
+ It resolves `settings.sh.declarationConvention` and returns validated declarations, or `null`
400
+ when no convention is bound. A bound convention that declares nothing returns `[]`.
401
+
402
+ The convention receives a frozen `LintedFile` with only `filename`, `physicalFilename` and
403
+ `cwd`, so sidecar conventions work in custom rules too. Invalid bindings or declarations
404
+ (missing or unknown `kind`, missing fields, invalid provenance or a `range` outside the text)
405
+ throw `Invalid settings.sh.declarationConvention: …`. Calling `declaredCommands` directly
406
+ would bypass those checks.
407
+
408
+ A rule that also needs a hook such as `removeDeclaration` can call
409
+ `resolveDeclarationConvention({ settings: context.settings })` to get the validated convention
410
+ object. Shared settings are the only binding route; rule options do not bind conventions.
411
+
412
412
  - Only in-script declarations have a `range`. Check `kind` before reading it: a declaration with
413
413
  `kind` `'file'` or `'described'` lives somewhere your rule can't point at.
414
414
 
@@ -426,8 +426,7 @@ this package's test suite runs it in CI with both `commentPragma` and the
426
426
  */
427
427
  import {
428
428
  defineShellRule,
429
- readDeclaredCommands,
430
- resolveDeclarationConvention,
429
+ getDeclaredCommands,
431
430
  } from '@eslint-sh/eslint-plugin';
432
431
 
433
432
  const sortedDeclarations = defineShellRule({
@@ -437,18 +436,16 @@ const sortedDeclarations = defineShellRule({
437
436
  messages: { unsorted: 'Declare `{{name}}` before `{{previous}}`.' },
438
437
  },
439
438
  create(context) {
440
- // The bound convention, checked exactly as the built-in rules check it;
441
- // `null` when none is bound, and then the rule has nothing to check.
442
- const convention = resolveDeclarationConvention(context);
443
- if (convention === null) {
444
- return {};
445
- }
446
439
  return {
447
440
  File() {
448
441
  const { sourceCode } = context;
449
442
  // The file's declarations, checked as the built-in rules check them.
450
443
  // Only those written in the script have a range to report at.
451
- const declared = readDeclaredCommands(convention, context).filter(
444
+ const declarations = getDeclaredCommands(context);
445
+ if (declarations === null) {
446
+ return;
447
+ }
448
+ const declared = declarations.filter(
452
449
  (each) => each.kind === 'script',
453
450
  );
454
451
  for (let i = 1; i < declared.length; i++) {
@@ -0,0 +1,93 @@
1
+ # Error codes
2
+
3
+ Every deliberate project error has a stable `ESLINT_SH_` code. Match `code` to
4
+ identify a failure; human message text may change. Plain argument/configuration
5
+ errors retain their native `TypeError`, `RangeError` or `Error` prototype. Named
6
+ classes exist where callers need structured data, as listed below.
7
+
8
+ Configuration messages have the shape `<where>: <what is wrong>; received <value>.`
9
+ The path names the binding the caller wrote, including a list index when one
10
+ entry is wrong. Rule-option paths use the configured rule ID, including plugin
11
+ registration aliases; shared settings retain the canonical `settings.sh` namespace.
12
+ Nonfinite numbers are shown as `NaN`, `Infinity` or `-Infinity`, rather than `null`.
13
+ Other values use a short JSON-first rendering, with a fallback for
14
+ undefined, bigint, symbols, functions and values that cannot be serialized.
15
+ Messages are diagnostics, not a serialization format.
16
+
17
+ ```js
18
+ try {
19
+ // Configure the shell language or call a source helper.
20
+ } catch (error) {
21
+ if (error instanceof Error && 'code' in error) {
22
+ console.error(error.code, error.message);
23
+ } else {
24
+ throw error;
25
+ }
26
+ }
27
+ ```
28
+
29
+ ## Project codes
30
+
31
+ | Code | Base/class | Meaning and boundary |
32
+ | --- | --- | --- |
33
+ | `ESLINT_SH_LANGUAGE_OPTION` | `TypeError` | A `languageOptions` value or combination cannot be honored. |
34
+ | `ESLINT_SH_STRICT_MODE_SETTING` | `Error` | The shared `settings.sh.strictModePrologue` fact or one of its fields is malformed. |
35
+ | `ESLINT_SH_WRAPPER_CONFIG` | `TypeError` | A `createWrapperRule config` binding is malformed. |
36
+ | `ESLINT_SH_WRAPPER_SETTING` | `Error` | A shared wrapper binding or spec field is malformed. |
37
+ | `ESLINT_SH_WRAPPER_CONFLICT` | `Error` | Wrapper policies contradict each other or repeat a project name. |
38
+ | `ESLINT_SH_DECLARATION_CONVENTION` | `Error` | The declaration convention or an optional hook has the wrong shape. |
39
+ | `ESLINT_SH_DECLARATION_OUTPUT` | `Error` | A convention returns invalid declarations or a malformed hint. A hook's own exception propagates unchanged. |
40
+ | `ESLINT_SH_PATTERN_SYNTAX` | `TypeError` | A rule option is not a valid Unicode regular expression. `cause` preserves the JavaScript compiler's error. |
41
+ | `ESLINT_SH_PATTERN_REPETITION` | `TypeError` | A valid pattern nests repeating quantifiers and is refused by the documented pattern policy. |
42
+ | `ESLINT_SH_FILE_NODE` | `TypeError` | A helper requires a file associated with this adapter's parse. |
43
+ | `ESLINT_SH_CALL_NODE` | `TypeError` | A command helper requires a parsed `CallExpr` view. |
44
+ | `ESLINT_SH_WORD_NODE` | `TypeError` | A word helper requires a parsed `Word` view. A dynamic word is a normal resolution result. |
45
+ | `ESLINT_SH_COMMAND_SITE_VIEW` | `Error` | An analyzed command site has no corresponding view in the supplied file. |
46
+ | `ESLINT_SH_FOREIGN_VIEW_NODE` | `TypeError` | A printed-fix helper received a view with no original syntax in this file. |
47
+ | `ESLINT_SH_SYNTAX_POSITION` | `TypeError` | A position argument does not have the required `SyntaxPos` shape. |
48
+ | `ESLINT_SH_SOURCE_INDEX` | `TypeError` | A source index is not numeric. |
49
+ | `ESLINT_SH_SOURCE_LOCATION` | `TypeError` | A source location lacks numeric line/column fields. |
50
+ | `ESLINT_SH_SOURCE_RANGE` | `RangeError` | A position is inexact, outside the source, or inside a UTF-8 character. |
51
+ | `ESLINT_SH_SYNTAX_VIEW` | `TypeError` | Upstream records and their position snapshot cannot produce a faithful lint view. This is a projection invariant failure, not a syntax diagnostic. |
52
+ | `ESLINT_SH_PRINT_ROOT` | `TypeError` | Edited syntax is missing a record type or uses an unsupported printable root. |
53
+ | `ESLINT_SH_PRINT_ENCODING` | `TypeError` | Printed bytes cannot become a UTF-8 text fix without loss. |
54
+ | `ESLINT_SH_PRINT_UNSAFE_TEXT` | `TypeError` | Edited syntax contains literal vertical tabs or form feeds the printer changes. |
55
+ | `ESLINT_SH_PACKAGE_METADATA` | `Error` | The plugin package lacks a string version. Filesystem/JSON errors keep their native identity. |
56
+
57
+ Formatting/editor failures are documented by the independently maintained
58
+ [sh-codemod](https://github.com/mike-north/sh-codemod#readme) project and use its
59
+ `SH_CODEMOD_` namespace. They are not plugin errors.
60
+
61
+ ## Dependency boundaries
62
+
63
+ `./syntax` and `./syntax/analyze` faithfully re-export `sh-ast` and
64
+ `sh-ast/analyze`. They retain upstream errors and codes without aliases. The
65
+ plugin's source helpers also preserve analysis resource/invalid-wrapper failures,
66
+ and printed replacements preserve upstream printer errors. Returning a partial
67
+ command inventory on a depth refusal would silently omit real commands.
68
+
69
+ | Dependency code | Meaning |
70
+ | --- | --- |
71
+ | `SH_AST_SYNTAX_PARSE` | Invalid shell source. The language presents fatal diagnostics; raw syntax calls retain the error. |
72
+ | `SH_AST_SYNTAX_LANG` | Source is invalid in the selected dialect. Same boundary as parse errors. |
73
+ | `SH_AST_SYNTAX_INPUT` | The raw parser/printer rejects an input value. High-level project option validation happens before parsing; non-option input errors pass through. |
74
+ | `SH_AST_SYNTAX_PRINT` | Printer request cannot be honored. |
75
+ | `SH_AST_SYNTAX_PRINT_PANIC` | Upstream printer failure. |
76
+ | `SH_AST_WALK_PANIC` | Upstream syntax traversal failure. |
77
+ | `SH_AST_PARSE_MAX_DEPTH` | Parser resource limit; no partial tree is returned. |
78
+ | `SH_AST_ANALYZE_MAX_DEPTH` | Analysis resource limit; no partial inventory is returned. |
79
+ | `SH_AST_ANALYZE_INVALID_WRAPPER_SPEC` | A raw analysis wrapper spec is invalid. Shared JSON settings are validated at their own project boundary. |
80
+ | `SH_AST_INTERNAL` | Upstream bridge/internal failure. |
81
+
82
+ ESLint wraps errors from language-option validation in its own `TypeError`.
83
+ Direct calls to `plugin.languages.sh.validateLanguageOptions` expose the project
84
+ code on the thrown error; an ESLint configuration failure preserves that error
85
+ and its code on `cause`. Shared-setting and rule-factory errors propagate through
86
+ ESLint rule loading with their project codes intact.
87
+
88
+ The language's `parse` entry point returns ESLint fatal diagnostics rather than
89
+ throwing. Syntax diagnostics retain their source positions, resource refusals
90
+ remain resource diagnostics, and runtime failures remain distinguished from
91
+ invalid shell. ESLint's own schema errors, third-party hook exceptions and native
92
+ runtime failures are not project-owned intentional errors and keep their
93
+ existing contracts. Check each method's `@throws` for its precise boundary.
@@ -19,13 +19,13 @@ import type { ShellCommandSite, ShellRuleContext } from '@eslint-sh/eslint-plugi
19
19
  /** The rule's one options object; `commands` defaults to `[]`. */
20
20
  type Options = [{ commands?: string[] }?];
21
21
 
22
- /** Reports `site` when the command it runs, after wrappers, is in `listed`. */
22
+ /** Reports the program named by `site`, after wrappers, including interpreters running strings. */
23
23
  function reportIfListed(
24
24
  context: ShellRuleContext<Options, 'listed'>,
25
25
  site: ShellCommandSite,
26
26
  listed: ReadonlySet<string>,
27
27
  ): void {
28
- const { effective } = site.resolveInvokedCommand();
28
+ const { effective } = site.resolveInvokedCommand({ embeddedCommandInterpreters: [] });
29
29
  if (effective.static && listed.has(effective.text)) {
30
30
  context.report({ node: site.node, messageId: 'listed', data: { name: effective.text } });
31
31
  }
@@ -10,15 +10,15 @@
10
10
  * for it, so ESLint refuses to run the rule on a file of any other language.
11
11
  *
12
12
  * Built on the `:command` launch class from the selector cookbook
13
- * (`../selectors.md`) — `:command` matches every `CallExpr`, so `create()`
13
+ * (`../selectors.md`) — `:command` matches calls with a command word, so `create()`
14
14
  * narrows further by inspecting the command word and its flag arguments,
15
15
  * exactly the pattern the cookbook's intro describes ("writing a rule as a
16
16
  * selector string rather than a `create()` full of manual type checks" —
17
17
  * here the selector does the node-type narrowing, `create()` only does the
18
18
  * domain-specific check).
19
19
  *
20
- * Flag words are resolved with `@eslint-sh/eslint-plugin`'s view-aware
21
- * `resolveWord` (backed by `sh-ast/analyze`) rather than a
20
+ * Flag words are resolved with `context.sourceCode.resolveWord`
21
+ * (backed by `sh-ast/analyze`) rather than a
22
22
  * hand-rolled scan: a word is only treated as a short-option cluster
23
23
  * when it is *statically* that string (bare or
24
24
  * quoted literal concatenations). Recursive (`r`/`R`) and force (`f`)
@@ -28,16 +28,14 @@
28
28
  * A word containing a `ParamExp`/`CmdSubst`/`ArithmExp`/
29
29
  * `ProcSubst` resolves to `{ static: false, reason }` (`'expansion'`,
30
30
  * `'tilde'`, `'glob'`, …) rather than being silently erased into a static
31
- * match — see `resolveWord`'s API docs. Importing
32
- * it from the plugin package (rather than `sh-ast/analyze` directly) means
33
- * a project that installs only `@eslint-sh/eslint-plugin` has everything
34
- * this rule needs, with no separate `sh-ast` install or npm-hoisting
35
- * reliance.
31
+ * match — see `ShellSourceCode.resolveWord`'s API docs. The source instance
32
+ * comes from ESLint, so the rule needs no separate `sh-ast` install or
33
+ * dependency-hoisting reliance.
36
34
  *
37
35
  * @see ../custom-rule-tutorial.md — the tutorial this rule backs
38
36
  * @see ../selectors.md — the `:command` launch class
39
37
  */
40
- import { defineShellRule, resolveWord } from '@eslint-sh/eslint-plugin';
38
+ import { defineShellRule } from '@eslint-sh/eslint-plugin';
41
39
 
42
40
  const noRmRf = defineShellRule({
43
41
  meta: {
@@ -55,7 +53,7 @@ const noRmRf = defineShellRule({
55
53
  ':command'(node) {
56
54
  const args = node.args ?? [];
57
55
  const words = args.map((arg) => {
58
- const resolved = resolveWord(arg, { context: 'command-argument' });
56
+ const resolved = context.sourceCode.resolveWord(arg);
59
57
  return resolved.static ? resolved.text : null;
60
58
  });
61
59
 
@@ -5,8 +5,7 @@
5
5
  */
6
6
  import {
7
7
  defineShellRule,
8
- readDeclaredCommands,
9
- resolveDeclarationConvention,
8
+ getDeclaredCommands,
10
9
  } from '@eslint-sh/eslint-plugin';
11
10
 
12
11
  const sortedDeclarations = defineShellRule({
@@ -16,18 +15,16 @@ const sortedDeclarations = defineShellRule({
16
15
  messages: { unsorted: 'Declare `{{name}}` before `{{previous}}`.' },
17
16
  },
18
17
  create(context) {
19
- // The bound convention, checked exactly as the built-in rules check it;
20
- // `null` when none is bound, and then the rule has nothing to check.
21
- const convention = resolveDeclarationConvention(context);
22
- if (convention === null) {
23
- return {};
24
- }
25
18
  return {
26
19
  File() {
27
20
  const { sourceCode } = context;
28
21
  // The file's declarations, checked as the built-in rules check them.
29
22
  // Only those written in the script have a range to report at.
30
- const declared = readDeclaredCommands(convention, context).filter(
23
+ const declarations = getDeclaredCommands(context);
24
+ if (declarations === null) {
25
+ return;
26
+ }
27
+ const declared = declarations.filter(
31
28
  (each) => each.kind === 'script',
32
29
  );
33
30
  for (let i = 1; i < declared.length; i++) {
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "composite": false
6
+ },
7
+ "include": [
8
+ "*.ts"
9
+ ]
10
+ }