@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.
- package/README.md +53 -40
- package/dist/api.d.ts +92 -0
- package/dist/api.js +83 -0
- package/dist/command-harvest/builtins/bash.d.ts +1 -1
- package/dist/command-harvest/builtins/bash.js +1 -1
- package/dist/command-harvest/builtins/bats.d.ts +2 -0
- package/dist/command-harvest/builtins/bats.js +3 -0
- package/dist/command-harvest/harvest-commands.d.ts +2 -2
- package/dist/command-harvest/harvest-commands.js +2 -2
- package/dist/command-harvest/wrapper-table.d.ts +3 -19
- package/dist/command-harvest/wrapper-table.js +8 -38
- package/dist/configs/bash-3-2.d.ts +7 -6
- package/dist/configs/bash-3-2.js +4 -3
- package/dist/configs/posix-portable.d.ts +7 -11
- package/dist/configs/posix-portable.js +4 -6
- package/dist/configuration-message.d.ts +14 -0
- package/dist/configuration-message.js +33 -0
- package/dist/declaration-conventions/get-declared-commands.d.ts +41 -0
- package/dist/declaration-conventions/{read-declared-commands.js → get-declared-commands.js} +43 -43
- package/dist/eslint-plugin-api.d.ts +1506 -0
- package/dist/eslint-plugin-syntax-analyze.d.ts +3 -3
- package/dist/eslint-plugin-syntax.d.ts +7 -4
- package/dist/eslint-plugin.d.ts +16 -1514
- package/dist/index.d.ts +14 -78
- package/dist/index.js +22 -74
- package/dist/language/command-resolution.d.ts +5 -5
- package/dist/language/command-resolution.js +11 -7
- package/dist/language/selector-classes.d.ts +7 -3
- package/dist/language/selector-classes.js +13 -4
- package/dist/language/shell-language-options.d.ts +21 -18
- package/dist/language/shell-language-options.js +41 -39
- package/dist/language/shell-language.d.ts +13 -10
- package/dist/language/shell-language.js +23 -45
- package/dist/language/shell-source-code.d.ts +74 -49
- package/dist/language/shell-source-code.js +135 -68
- package/dist/language/source-coordinates.d.ts +2 -0
- package/dist/language/source-coordinates.js +8 -4
- package/dist/language/syntax-view.js +19 -7
- package/dist/language/word-resolution.d.ts +2 -1
- package/dist/language/word-resolution.js +8 -3
- package/dist/rules/bash-variable-semantics.d.ts +22 -0
- package/dist/rules/bash-variable-semantics.js +41 -0
- package/dist/rules/compat/create-compat-rule.js +1 -1
- package/dist/rules/compat/declaration-options.d.ts +2 -2
- package/dist/rules/compat/declaration-options.js +5 -2
- package/dist/rules/compat/no-append-all-redirect.js +1 -1
- package/dist/rules/compat/no-associative-arrays.js +2 -2
- package/dist/rules/compat/no-brace-sequence-padding-step.js +4 -4
- package/dist/rules/compat/no-case-attributes.js +3 -3
- package/dist/rules/compat/no-case-fallthrough.js +2 -2
- package/dist/rules/compat/no-case-modification.js +2 -2
- package/dist/rules/compat/no-coproc.js +1 -1
- package/dist/rules/compat/no-declare-g.js +3 -3
- package/dist/rules/compat/no-double-bracket.js +2 -2
- package/dist/rules/compat/no-epoch-variables.js +2 -2
- package/dist/rules/compat/no-fd-variable.js +1 -1
- package/dist/rules/compat/no-globstar.js +1 -1
- package/dist/rules/compat/no-lastpipe-semantics.js +2 -2
- package/dist/rules/compat/no-let.js +2 -1
- package/dist/rules/compat/no-mapfile.js +4 -2
- package/dist/rules/compat/no-nameref.js +3 -3
- package/dist/rules/compat/no-negative-array-index.js +39 -9
- package/dist/rules/compat/no-nounset-empty-array.js +15 -4
- package/dist/rules/compat/no-parameter-transformation.js +2 -2
- package/dist/rules/compat/no-pipe-all.js +1 -1
- package/dist/rules/compat/no-printf-time-format.js +4 -2
- package/dist/rules/compat/no-source.js +2 -1
- package/dist/rules/compat/no-test-v.js +4 -2
- package/dist/rules/compat/no-unicode-escape.js +2 -2
- package/dist/rules/compat/no-wait-n.js +4 -2
- package/dist/rules/compat/nounset-array-proof.d.ts +8 -0
- package/dist/rules/compat/nounset-array-proof.js +563 -0
- package/dist/rules/compat/posix-absent-command.d.ts +7 -8
- package/dist/rules/compat/posix-absent-command.js +17 -15
- package/dist/rules/compat/shopt-options.js +3 -1
- package/dist/rules/compat/version-gates.d.ts +9 -9
- package/dist/rules/compat/version-gates.js +13 -13
- package/dist/rules/create-wrapper-rule.d.ts +1 -1
- package/dist/rules/create-wrapper-rule.js +23 -16
- package/dist/rules/define-shell-rule.js +1 -1
- package/dist/rules/no-dynamic-invocation.d.ts +0 -8
- package/dist/rules/no-dynamic-invocation.js +7 -15
- package/dist/rules/no-eval.js +3 -1
- package/dist/rules/no-masked-exit-status.d.ts +4 -3
- package/dist/rules/no-masked-exit-status.js +18 -10
- package/dist/rules/no-secret-env-reads.d.ts +6 -3
- package/dist/rules/no-secret-env-reads.js +49 -15
- package/dist/rules/no-secret-flags.d.ts +4 -1
- package/dist/rules/no-secret-flags.js +21 -11
- package/dist/rules/no-unchecked-cd.js +6 -3
- package/dist/rules/no-undeclared-commands.d.ts +1 -15
- package/dist/rules/no-undeclared-commands.js +11 -18
- package/dist/rules/no-unused-declarations.d.ts +1 -18
- package/dist/rules/no-unused-declarations.js +15 -36
- package/dist/rules/prefer-local.d.ts +3 -2
- package/dist/rules/prefer-local.js +7 -4
- package/dist/rules/quote-expansions.js +3 -28
- package/dist/rules/require-network-wrapper.d.ts +3 -18
- package/dist/rules/require-network-wrapper.js +43 -10
- package/dist/rules/require-strict-mode.d.ts +5 -46
- package/dist/rules/require-strict-mode.js +17 -107
- package/dist/rules/require-tty-guard.d.ts +2 -0
- package/dist/rules/require-tty-guard.js +8 -1
- package/dist/rules/resolve-declaration-convention.d.ts +9 -89
- package/dist/rules/resolve-declaration-convention.js +19 -72
- package/dist/rules/resolve-network-wrapper.d.ts +20 -2
- package/dist/rules/resolve-network-wrapper.js +71 -36
- package/dist/rules/resolve-transparent-wrappers.d.ts +38 -0
- package/dist/rules/resolve-transparent-wrappers.js +108 -0
- package/dist/rules/set-options.d.ts +3 -2
- package/dist/rules/set-options.js +18 -6
- package/dist/rules/shebang-interpreter.js +4 -2
- package/dist/rules/strict-mode-prologue.d.ts +43 -0
- package/dist/rules/strict-mode-prologue.js +91 -0
- package/dist/rules/transparent-wrappers.d.ts +4 -3
- package/dist/rules/transparent-wrappers.js +5 -4
- package/dist/rules/user-pattern.d.ts +9 -6
- package/dist/rules/user-pattern.js +16 -12
- package/dist/shell-dialect.d.ts +8 -0
- package/dist/shell-dialect.js +22 -0
- package/dist/syntax/analyze.d.ts +3 -3
- package/dist/syntax/analyze.js +3 -3
- package/dist/syntax/index.d.ts +7 -4
- package/dist/syntax/index.js +7 -4
- package/dist/version.js +2 -1
- package/docs/compat.md +81 -33
- package/docs/custom-rule-tutorial.md +31 -21
- package/docs/declaration-conventions.md +20 -23
- package/docs/error-codes.md +93 -0
- package/docs/examples/no-listed-commands-rule.ts +2 -2
- package/docs/examples/no-rm-rf-rule.mjs +8 -10
- package/docs/examples/sorted-declarations-rule.mjs +6 -9
- package/docs/examples/tsconfig.json +10 -0
- package/docs/rules/README.md +46 -6
- package/docs/rules/_template.md +2 -2
- package/docs/rules/compat/no-append-all-redirect.md +12 -12
- package/docs/rules/compat/no-associative-arrays.md +14 -14
- package/docs/rules/compat/no-brace-sequence-padding-step.md +12 -12
- package/docs/rules/compat/no-case-attributes.md +13 -13
- package/docs/rules/compat/no-case-fallthrough.md +12 -12
- package/docs/rules/compat/no-case-modification.md +11 -11
- package/docs/rules/compat/no-coproc.md +13 -13
- package/docs/rules/compat/no-declare-g.md +13 -13
- package/docs/rules/compat/no-double-bracket.md +2 -2
- package/docs/rules/compat/no-epoch-variables.md +13 -13
- package/docs/rules/compat/no-fd-variable.md +12 -12
- package/docs/rules/compat/no-globstar.md +13 -13
- package/docs/rules/compat/no-lastpipe-semantics.md +13 -13
- package/docs/rules/compat/no-let.md +2 -2
- package/docs/rules/compat/no-mapfile.md +16 -16
- package/docs/rules/compat/no-nameref.md +13 -13
- package/docs/rules/compat/no-negative-array-index.md +14 -14
- package/docs/rules/compat/no-nounset-empty-array.md +72 -17
- package/docs/rules/compat/no-parameter-transformation.md +19 -19
- package/docs/rules/compat/no-pipe-all.md +13 -13
- package/docs/rules/compat/no-printf-time-format.md +13 -13
- package/docs/rules/compat/no-source.md +2 -2
- package/docs/rules/compat/no-test-v.md +12 -12
- package/docs/rules/compat/no-unicode-escape.md +13 -13
- package/docs/rules/compat/no-wait-n.md +13 -13
- package/docs/rules/no-dynamic-invocation.md +17 -12
- package/docs/rules/no-eval.md +6 -1
- package/docs/rules/no-masked-exit-status.md +6 -2
- package/docs/rules/no-secret-env-reads.md +46 -5
- package/docs/rules/no-secret-flags.md +32 -6
- package/docs/rules/no-unchecked-cd.md +22 -2
- package/docs/rules/no-undeclared-commands.md +16 -15
- package/docs/rules/no-unused-declarations.md +17 -20
- package/docs/rules/prefer-local.md +20 -2
- package/docs/rules/quote-expansions.md +8 -5
- package/docs/rules/require-network-wrapper.md +26 -21
- package/docs/rules/require-shebang.md +10 -4
- package/docs/rules/require-strict-mode.md +31 -23
- package/docs/rules/require-tty-guard.md +12 -3
- package/docs/selectors.md +7 -2
- package/docs/shellcheck.md +9 -5
- package/docs/transparent-wrappers.md +97 -0
- package/docs/wrapper-rules.md +11 -0
- package/package.json +3 -3
- package/dist/declaration-conventions/read-declared-commands.d.ts +0 -70
- package/dist/language/end-of-input-marker.d.ts +0 -29
- package/dist/language/end-of-input-marker.js +0 -88
package/README.md
CHANGED
|
@@ -24,9 +24,10 @@ recipes. Four shared configs ship, each supplying `plugins: { sh }` and `languag
|
|
|
24
24
|
`sh/max-script-complexity`, with every rule at `error`. Its convention and wrapper rules report nothing until you bind a declaration
|
|
25
25
|
convention or a wrapper. The [rules index](./docs/rules/README.md) lists all forty built-in rules,
|
|
26
26
|
their presets, and
|
|
27
|
-
autofix availability. The version-gated rules `sh/compat/no-append-all-redirect`, `sh/compat/no-associative-arrays`, `sh/compat/no-brace-sequence-padding-step`, `sh/compat/no-case-attributes`, `sh/compat/no-case-fallthrough`, `sh/compat/no-case-modification`, `sh/compat/no-coproc`, `sh/compat/no-declare-g`, `sh/compat/no-epoch-variables`, `sh/compat/no-fd-variable`, `sh/compat/no-globstar`, `sh/compat/no-lastpipe-semantics`, `sh/compat/no-mapfile`, `sh/compat/no-nameref`, `sh/compat/no-negative-array-index`, `sh/compat/no-nounset-empty-array`, `sh/compat/no-parameter-transformation`, `sh/compat/no-pipe-all`, `sh/compat/no-printf-time-format`, `sh/compat/no-test-v`, `sh/compat/no-unicode-escape` and `sh/compat/no-wait-n`, report features your
|
|
28
|
-
|
|
29
|
-
`sh/
|
|
27
|
+
autofix availability. The version-gated rules `sh/compat/no-append-all-redirect`, `sh/compat/no-associative-arrays`, `sh/compat/no-brace-sequence-padding-step`, `sh/compat/no-case-attributes`, `sh/compat/no-case-fallthrough`, `sh/compat/no-case-modification`, `sh/compat/no-coproc`, `sh/compat/no-declare-g`, `sh/compat/no-epoch-variables`, `sh/compat/no-fd-variable`, `sh/compat/no-globstar`, `sh/compat/no-lastpipe-semantics`, `sh/compat/no-mapfile`, `sh/compat/no-nameref`, `sh/compat/no-negative-array-index`, `sh/compat/no-nounset-empty-array`, `sh/compat/no-parameter-transformation`, `sh/compat/no-pipe-all`, `sh/compat/no-printf-time-format`, `sh/compat/no-test-v`, `sh/compat/no-unicode-escape` and `sh/compat/no-wait-n`, report features the minimum Bash version your scripts must support lacks; `configs['bash-3.2']` (`minBashVersion: '3.2'`) and `configs['posix-portable']` (`dialect: 'posix'`, with
|
|
28
|
+
`sh/require-strict-mode` as `set -eu`) enable them for those targets, except that
|
|
29
|
+
`sh/compat/no-nounset-empty-array` is an explicit opt-in for `bash-3.2`. Enable it for scripts
|
|
30
|
+
that use `set -u` on Bash below 4.4 and have arrays that can really be empty. `configs['posix-portable']` also reports `[[`, `let` and `source`, which fail on dash (`sh/compat/no-double-bracket`, `sh/compat/no-let`, `sh/compat/no-source`), but not `local`, `echo -e` or the other constructs it leaves to shellcheck, so a clean run does not prove a script runs under every POSIX `sh`; see [version compatibility](./docs/compat.md). Run shellcheck alongside eslint-sh: shellcheck catches shell correctness
|
|
30
31
|
problems; eslint-sh enforces project policy. [Running eslint-sh beside shellcheck](./docs/shellcheck.md)
|
|
31
32
|
covers who owns what and the rules that overlap it deliberately (see also the
|
|
32
33
|
[design rationale](https://github.com/mike-north/eslint-sh/blob/main/design/README.md#eslint-sh-and-shellcheck)).
|
|
@@ -45,16 +46,22 @@ directory it runs in.
|
|
|
45
46
|
## CommonJS config
|
|
46
47
|
|
|
47
48
|
In a package without `"type": "module"` (the ESLint default), `eslint.config.js` is CommonJS, as
|
|
48
|
-
is `eslint.config.cjs` in any package.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
is `eslint.config.cjs` in any package. `require('@eslint-sh/eslint-plugin')` returns the plugin object
|
|
50
|
+
directly. Named helpers such as `commentPragma` are properties of that same object;
|
|
51
|
+
`require('@eslint-sh/eslint-plugin').default` also returns it. These helper/default properties are
|
|
52
|
+
non-enumerable, so they do not change ESLint's plugin or config serialization.
|
|
53
|
+
Both packages remain ESM-only and use Node's synchronous `require(ESM)` support
|
|
54
|
+
(Node 22.13+ on the 22.x line, or Node 24+). ESM default and named imports are unchanged.
|
|
55
|
+
|
|
56
|
+
For TypeScript CommonJS consumers, use `import sh = require('@eslint-sh/eslint-plugin')` with
|
|
57
|
+
`module: "node20"` and `moduleResolution: "node16"`, or `module: "nodenext"` and
|
|
58
|
+
`moduleResolution: "nodenext"`. `module: "node16"` models Node without `require(ESM)`
|
|
59
|
+
and rejects this ESM-only package; `skipLibCheck` is not a remedy.
|
|
53
60
|
|
|
54
61
|
```js
|
|
55
62
|
// eslint.config.js (CommonJS package) or eslint.config.cjs
|
|
56
63
|
const { defineConfig } = require('eslint/config');
|
|
57
|
-
const sh = require('@eslint-sh/eslint-plugin')
|
|
64
|
+
const sh = require('@eslint-sh/eslint-plugin');
|
|
58
65
|
// Named exports need no `.default`.
|
|
59
66
|
const { commentPragma } = require('@eslint-sh/eslint-plugin');
|
|
60
67
|
|
|
@@ -70,30 +77,38 @@ module.exports = defineConfig([
|
|
|
70
77
|
|
|
71
78
|
## Public API
|
|
72
79
|
|
|
80
|
+
- `module.exports` — Node's quoted interop export makes plain `require()` return the plugin
|
|
81
|
+
with its hidden default and named helpers. ESM consumers use the ordinary exports below.
|
|
82
|
+
|
|
73
83
|
- `plugin` (default export) — `{ meta: { name, version, namespace: "sh" }, languages: { sh:
|
|
74
84
|
ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'posix-portable' } }`. `meta.version` always
|
|
75
85
|
matches this package's `package.json`. Each config is a single config object with no `files`
|
|
76
86
|
key (`bash-3.2` and `posix-portable` also set `languageOptions`); extend it under your own `files`:
|
|
77
87
|
`defineConfig({ files: ['**/*.sh'], extends: [sh.configs.recommended] })`.
|
|
78
|
-
- `ShellLanguage` —
|
|
88
|
+
- `ShellLanguage` — type-only annotation for `plugin.languages.sh`, the registered runtime
|
|
89
|
+
language. Select it through `language: 'sh/sh'`; construction is internal. The `@eslint/core`
|
|
90
|
+
`Language` implementation has `fileType: "text"`,
|
|
79
91
|
`lineStart`/`columnStart: 1`, `nodeTypeKey: "type"`, the consumer's schema-derived `visitorKeys`,
|
|
80
92
|
`validateLanguageOptions`/`normalizeLanguageOptions` for the
|
|
81
|
-
`{dialect,
|
|
93
|
+
`{dialect, minBashVersion, directivePrefix}` schema, `parse`/`createSourceCode`, and
|
|
82
94
|
`matchesSelectorClass` for the six launch esquery selector classes (`:command`, `:loop`,
|
|
83
95
|
`:conditional`, `:expansion`, `:quoted`, `:function` — see the
|
|
84
96
|
[selector cookbook](./docs/selectors.md)).
|
|
85
|
-
- `ShellSourceCode` —
|
|
97
|
+
- `ShellSourceCode` — type-only annotation for the instance ESLint supplies as
|
|
98
|
+
`context.sourceCode`; construction belongs to the language pipeline. It extends `@eslint/plugin-kit`'s `TextSourceCodeBase`; implements `traverse()`
|
|
86
99
|
(driven by the consumer's `visitorKeys`, yielding two-phase `VisitNodeStep`s), `getParent()`, and
|
|
87
100
|
the disable-directive surface (`getDisableDirectives()`, `getInlineConfigNodes()`,
|
|
88
101
|
`applyInlineConfig()`). Rule authors get helpers that delegate to `sh-ast/analyze`, so every rule
|
|
89
|
-
gets the same answer: `
|
|
90
|
-
`
|
|
102
|
+
gets the same answer: `resolveWord(word, options?)` (the full `WordResolution`) and
|
|
103
|
+
`resolveWordText(word, options?)` (exactly its static text, or `null`). Both use grammar-position
|
|
104
|
+
defaults: command-argument context for `CallExpr.args`, conservative tilde handling elsewhere;
|
|
105
|
+
explicit options override those defaults. Helpers also include `getCommandName(callExpr)` (the static command word,
|
|
91
106
|
without following wrappers), and `resolveInvokedCommand(callExpr, { transparentWrappers? })` (the
|
|
92
107
|
full `Argv0Resolution` once wrappers such as `env`, `sudo`, and `exec` are followed, including the
|
|
93
108
|
wrapper `chain` and the `effective` command or the reason it is unknowable). The `dialect` and
|
|
94
|
-
`
|
|
109
|
+
`minBashVersion` accessors return the file's normalized language options.
|
|
95
110
|
- `ShellLanguageOptions` / `NormalizedShellLanguageOptions` / `ShellLanguageOptionsJSON` — the
|
|
96
|
-
`languageOptions` types (`dialect`, `
|
|
111
|
+
`languageOptions` types (`dialect`, `minBashVersion`, `directivePrefix`). `directivePrefix` is the
|
|
97
112
|
prefix directive/inline-config comments must start with — e.g. the default `"eslint"` recognizes
|
|
98
113
|
`# eslint-disable-next-line ...`; consumers who already overload `# eslint-*` comments for
|
|
99
114
|
something else can configure a different prefix (e.g. `directivePrefix: 'shellcheck-sh'`).
|
|
@@ -115,7 +130,7 @@ ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'p
|
|
|
115
130
|
which follows wrappers. `ResolveArgv0Options` is that method's option bag (and
|
|
116
131
|
`ShellSourceCode.resolveInvokedCommand`'s): `transparentWrappers` replaces the wrapper table
|
|
117
132
|
followed.
|
|
118
|
-
- `WordResolution` — what `resolveWord` and a site's `argv` words report: `{ static: true, text }`
|
|
133
|
+
- `WordResolution` — what `ShellSourceCode.resolveWord` and a site's `argv` words report: `{ static: true, text }`
|
|
119
134
|
when the word's value is known without running the script, or `{ static: false, reason }` when
|
|
120
135
|
it is not (`reason` is `'expansion'`, `'tilde'`, `'glob'`, `'brace'`, `'locale'` or
|
|
121
136
|
`'unsupported'`; a new reason can appear in a minor release, so keep a `default` branch). Check
|
|
@@ -124,10 +139,6 @@ ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'p
|
|
|
124
139
|
`'bats'` and `'zsh'`.
|
|
125
140
|
- `Argv0Resolution` — the type `ShellSourceCode.resolveInvokedCommand` returns, re-exported from
|
|
126
141
|
`sh-ast/analyze`.
|
|
127
|
-
- `resolveWord` — adapts a parsed lint Word to `sh-ast`'s word-resolution helper, so a project that installs only
|
|
128
|
-
this package can write custom rules that resolve static shell words (e.g. the `no-rm-rf` example
|
|
129
|
-
in the [custom-rule tutorial](./docs/custom-rule-tutorial.md)) without a separate `sh-ast`
|
|
130
|
-
install. Fabricated nodes are rejected because they have no original syntax association.
|
|
131
142
|
- `DeclarationConvention` / `DeclaredCommand` / `commentPragma` — the extension point for how a
|
|
132
143
|
project declares the external commands its scripts use, bound with
|
|
133
144
|
`settings: { sh: { declarationConvention } }`. `commentPragma` is the reference convention,
|
|
@@ -139,8 +150,9 @@ ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'p
|
|
|
139
150
|
snapshot), and the
|
|
140
151
|
linted file a convention is told about so it can find a per-script sidecar. See [declarations
|
|
141
152
|
outside the script](./docs/declaration-conventions.md#declarations-outside-the-script).
|
|
142
|
-
- `
|
|
143
|
-
|
|
153
|
+
- `getDeclaredCommands` — reads validated declarations for the linted file using
|
|
154
|
+
`settings.sh.declarationConvention` only. Returns `null` when no convention is bound and `[]`
|
|
155
|
+
when a bound convention declares nothing. See [reading
|
|
144
156
|
the convention in your own
|
|
145
157
|
rule](./docs/declaration-conventions.md#reading-the-convention-in-your-own-rule).
|
|
146
158
|
- `defineShellRule` / `ShellRule` / `ShellRuleSpec` / `ShellRuleMeta` / `ShellRuleContext` /
|
|
@@ -152,11 +164,16 @@ ShellLanguage }, rules, configs: { recommended, 'agent-authored', 'bash-3.2', 'p
|
|
|
152
164
|
it too. `ShellListener<Node>` is the type of one listener, so a helper that builds listeners for
|
|
153
165
|
several rules can name its return type; `ShellTypedListeners` is the node-type-keyed half of
|
|
154
166
|
`ShellRuleVisitor`. See [Writing your own rules](#writing-your-own-rules).
|
|
155
|
-
- `resolveDeclarationConvention`
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
167
|
+
- `resolveDeclarationConvention` — resolves the convention in
|
|
168
|
+
`settings.sh.declarationConvention`, or `null` when absent. It accepts `{ settings }` and checks
|
|
169
|
+
the convention's hooks for rules that need `removeDeclaration` or another hook. Read
|
|
170
|
+
declarations through `getDeclaredCommands` so their output is validated too. See [declaration
|
|
159
171
|
conventions](./docs/declaration-conventions.md#reading-the-convention-in-your-own-rule).
|
|
172
|
+
- `resolveTransparentWrappers` / `TransparentWrappersBindingContext` — resolves project wrapper
|
|
173
|
+
facts from `settings: { sh: { transparentWrappers: ['with-retry'] } }` and the shared network
|
|
174
|
+
wrapper, composed with a rule's built-in scope. Every wrapper-following built-in uses it;
|
|
175
|
+
rule packs can use the same validation, precedence and path matching. See
|
|
176
|
+
[shared transparent wrappers](./docs/transparent-wrappers.md).
|
|
160
177
|
- `createWrapperRule` / `WrapperRuleConfig` / `WrapperRuleSubcommands` / `WrapperSpec` — the
|
|
161
178
|
factory for "command X must be run through wrapper Y" rules a rule pack
|
|
162
179
|
binds to its own commands and wrapper. `sh/require-network-wrapper` is the built-in rule made
|
|
@@ -174,8 +191,8 @@ the record types (`Node`, `Word`, `CallExpr`, `SyntaxPos`, `GoString`, …), and
|
|
|
174
191
|
helpers. Import them from this package's subpaths, not from `sh-ast`:
|
|
175
192
|
|
|
176
193
|
```js
|
|
177
|
-
//
|
|
178
|
-
import {
|
|
194
|
+
// Rules use context.sourceCode.resolveWord(word) for lint-view Word nodes.
|
|
195
|
+
import { defineShellRule } from '@eslint-sh/eslint-plugin';
|
|
179
196
|
// sh-ast's root entry point: parse, walk, and print faithful records.
|
|
180
197
|
import { parseSync, printSync, walk } from '@eslint-sh/eslint-plugin/syntax';
|
|
181
198
|
// sh-ast/analyze: command enumeration and wrapper resolution over faithful records.
|
|
@@ -190,11 +207,11 @@ import {
|
|
|
190
207
|
`sh-ast` this plugin depends on, the same module instance its language parses with, so you
|
|
191
208
|
don't install `sh-ast` yourself and records always match the parser that made them. Nothing is
|
|
192
209
|
wrapped or renamed; each name keeps `sh-ast`'s own contract and docs.
|
|
193
|
-
-
|
|
194
|
-
`…/syntax/analyze`
|
|
195
|
-
root.
|
|
210
|
+
- `context.sourceCode.resolveWord(word)` accepts a lint-view Word and uses grammar-position
|
|
211
|
+
defaults. `resolveWord` in `…/syntax/analyze` accepts a faithful syntax record and retains
|
|
212
|
+
upstream defaults. The root exports no free word-resolution function.
|
|
196
213
|
- **Versioning.** `…/syntax` and `…/syntax/analyze` track this plugin's pinned `sh-ast` minor
|
|
197
|
-
(currently `sh-ast@^0.
|
|
214
|
+
(currently `sh-ast@^0.10.0`). Under 0.x, a different `sh-ast` minor is a breaking change, so
|
|
198
215
|
an `sh-ast` 0.x minor bump is a minor bump of this plugin, and the changelog entry names the
|
|
199
216
|
new `sh-ast` version.
|
|
200
217
|
|
|
@@ -210,22 +227,16 @@ the file again, or in a fresh process, usually gets past a runtime failure.
|
|
|
210
227
|
|
|
211
228
|
### Known parser gaps
|
|
212
229
|
|
|
213
|
-
The parser is the upstream `sh-ast`, and it rejects
|
|
230
|
+
The parser is the upstream `sh-ast`, and it rejects two valid Bash forms. Each is reported as a
|
|
214
231
|
syntax error. Until the parser accepts them, write the workaround in the right-hand column.
|
|
215
232
|
|
|
216
233
|
| Valid Bash form | Workaround |
|
|
217
234
|
| ------------------------ | -------------------------- |
|
|
218
235
|
| `x=$((a \|\| b) \| c)` | `x=$( (a \|\| b) \| c )` |
|
|
219
|
-
| `x=(${y}[0])` | `word=${y}[0]; x=($word)` |
|
|
220
236
|
| `declare -A m=([a.b]=1)` | `declare -A m=(["a.b"]=1)` |
|
|
221
237
|
|
|
222
238
|
- `x=$((a || b) | c)`: the parser reads `$((` as the start of arithmetic. A space after `$(` makes
|
|
223
239
|
it a command substitution containing a subshell.
|
|
224
|
-
- `x=(${y}[0])`: inside an array literal, any element word that ends in an unquoted `[…]` is read
|
|
225
|
-
as an indexed element (`[0]=value`) and must be followed by `=`. It is not limited to a word
|
|
226
|
-
that starts with an expansion: `x=(a[0])`, `x=(a${y}[0])` and `x=("${y}"[0])` are rejected too
|
|
227
|
-
(a `[0]` that is meant as a glob character class). Building the word in its own statement keeps
|
|
228
|
-
the same splitting and globbing.
|
|
229
240
|
- An associative-array subscript containing a `.` that is not quoted: the parser reads the
|
|
230
241
|
subscript as arithmetic and rejects the dot ("floating point arithmetic is a zsh feature"). The
|
|
231
242
|
gap is wider than the `declare` form above. It also rejects `m[a.b]=1` and `${m[a.b]}`, which
|
|
@@ -273,3 +284,5 @@ fixes (and when a printed fix reflows code, so a position-based text edit is the
|
|
|
273
284
|
and a TypeScript rule. `docs/` ships with this package (see `package.json#files`), so the
|
|
274
285
|
tutorial and its example files (`docs/examples/`) are available in every installed copy — not just
|
|
275
286
|
on GitHub.
|
|
287
|
+
|
|
288
|
+
See the [error-code reference](docs/error-codes.md) for stable failure identities and dependency boundaries.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin boundary: registered runtime language, instance types and rule helpers.
|
|
3
|
+
* Language/source classes are type-only here; ESLint owns their construction and
|
|
4
|
+
* supplies validated source instances to rules through the registered language.
|
|
5
|
+
*/
|
|
6
|
+
import type { ConfigObject } from '@eslint/core';
|
|
7
|
+
import { ShellLanguage } from './language/shell-language.js';
|
|
8
|
+
export type { ShellLanguage } from './language/shell-language.js';
|
|
9
|
+
export type { ShellSourceCode } from './language/shell-source-code.js';
|
|
10
|
+
export type { NormalizedShellLanguageOptions, ShellLanguageOptions, ShellLanguageOptionsJSON, } from './language/shell-language-options.js';
|
|
11
|
+
export type { Argv0Resolution } from 'sh-ast/analyze';
|
|
12
|
+
export type { CommandContext, ResolveArgv0Options, WordResolution } from 'sh-ast/analyze';
|
|
13
|
+
export type { ShellCommandSite } from './language/command-resolution.js';
|
|
14
|
+
export type { ShellComment, ShellFile, ShellNode, ShellNodeField, ShellNodeMap, ShellNodeOf, ShellNodeType, ShellPosition, } from './language/syntax-view.js';
|
|
15
|
+
export type { ShellDialect } from './language/shell-language-options.js';
|
|
16
|
+
export type { DeclarationConvention, DeclaredCommand, FileDeclaredCommand, LintedFile, DescribedDeclaredCommand, ScriptDeclaredCommand, } from './declaration-conventions/declaration-convention.js';
|
|
17
|
+
export { getDeclaredCommands } from './declaration-conventions/get-declared-commands.js';
|
|
18
|
+
export { commentPragma } from './declaration-conventions/comment-pragma.js';
|
|
19
|
+
export { resolveTransparentWrappers } from './rules/resolve-transparent-wrappers.js';
|
|
20
|
+
export type { TransparentWrappersBindingContext } from './rules/resolve-transparent-wrappers.js';
|
|
21
|
+
export { resolveDeclarationConvention } from './rules/resolve-declaration-convention.js';
|
|
22
|
+
export { defineShellRule } from './rules/define-shell-rule.js';
|
|
23
|
+
export type { ShellListener, ShellRule, ShellRuleContext, ShellRuleMeta, ShellRuleSpec, ShellRuleVisitor, ShellTypedListeners, } from './rules/define-shell-rule.js';
|
|
24
|
+
export { createWrapperRule } from './rules/create-wrapper-rule.js';
|
|
25
|
+
export type { WrapperRuleConfig, WrapperRuleLocalInvocation, WrapperRuleLocalOperand, WrapperRuleSubcommands, } from './rules/create-wrapper-rule.js';
|
|
26
|
+
export type { WrapperSpec } from 'sh-ast/analyze';
|
|
27
|
+
/**
|
|
28
|
+
* The `@eslint-sh/eslint-plugin` plugin object, this package's default
|
|
29
|
+
* export (`import sh from '@eslint-sh/eslint-plugin'`). `languages.sh` provides
|
|
30
|
+
* `ShellLanguage` / `ShellSourceCode`, selected in a flat config via
|
|
31
|
+
* `language: "sh/sh"` (`namespace: "sh"`). `meta.version` is read from this
|
|
32
|
+
* package's own `package.json` at runtime — never hardcoded (see
|
|
33
|
+
* `version.ts`).
|
|
34
|
+
*
|
|
35
|
+
* `rules` holds the plugin's built-in rules, each built with
|
|
36
|
+
* `defineShellRule` (so each declares `meta.languages: ["sh/sh"]`) and
|
|
37
|
+
* linking its docs page from `meta.docs.url`. Consumers can also supply their
|
|
38
|
+
* own rules, built with the same `defineShellRule`, while sharing parsing,
|
|
39
|
+
* selectors, source coordinates, and directive semantics.
|
|
40
|
+
*
|
|
41
|
+
* `configs.recommended` is the `sh/recommended` preset: a single config
|
|
42
|
+
* object carrying `plugins: { sh }` and `language: "sh/sh"` but no `files`,
|
|
43
|
+
* so it inherits the globs of the entry that extends it:
|
|
44
|
+
* `{ files: [...], extends: [sh.configs.recommended] }`. It enables the
|
|
45
|
+
* convention-free policy rules. The rules index at
|
|
46
|
+
* https://github.com/mike-north/eslint-sh/blob/main/packages/eslint-plugin/docs/rules/README.md
|
|
47
|
+
* describes preset membership and available autofixes.
|
|
48
|
+
* `configs['agent-authored']` is the strict `sh/agent-authored` preset for
|
|
49
|
+
* machine-written, human-reviewed scripts:
|
|
50
|
+
* every `recommended` rule plus the contract rules, all at `error`.
|
|
51
|
+
* `configs['bash-3.2']` and `configs['posix-portable']` are deployment-target
|
|
52
|
+
* packs: the first sets `languageOptions.minBashVersion: "3.2"` and enables
|
|
53
|
+
* the version-gated `compat/*` rules except the opt-in
|
|
54
|
+
* `compat/no-nounset-empty-array`; the second sets
|
|
55
|
+
* `languageOptions.dialect: "posix"`, enables the effective `compat/*` rules and the
|
|
56
|
+
* shebang/dialect check; it reports named constructs
|
|
57
|
+
* that fail on dash, not every non-POSIX construct, and leaves `local`,
|
|
58
|
+
* `echo -e` and the rest of shellcheck's SC3xxx catalog to shellcheck. Every
|
|
59
|
+
* shipped config is a
|
|
60
|
+
* single object with no `files`; the two packs also carry `languageOptions`,
|
|
61
|
+
* because the target they name is their meaning. Beyond plugin registration
|
|
62
|
+
* and naming, target packs contain only language, languageOptions, and rules
|
|
63
|
+
* whose findings depend on that target. The shebang check belongs because it
|
|
64
|
+
* compares the declared interpreter with the target dialect. Error-handling
|
|
65
|
+
* policy comes from composing recommended, whose POSIX default is `set -eu`.
|
|
66
|
+
* The Bash-only empty-array nounset check cannot report under POSIX and is
|
|
67
|
+
* omitted from posix-portable.
|
|
68
|
+
*
|
|
69
|
+
* Re-exported, unchanged, as the default export of the `eslint-sh` umbrella
|
|
70
|
+
* package: importing this package or the umbrella package both yield the
|
|
71
|
+
* same plugin object.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
declare const plugin: {
|
|
76
|
+
meta: {
|
|
77
|
+
name: string;
|
|
78
|
+
version: string;
|
|
79
|
+
namespace: string;
|
|
80
|
+
};
|
|
81
|
+
languages: {
|
|
82
|
+
sh: ShellLanguage;
|
|
83
|
+
};
|
|
84
|
+
rules: Record<string, import("@eslint/core").RuleDefinition<import("@eslint/core").RuleDefinitionTypeOptions>>;
|
|
85
|
+
configs: {
|
|
86
|
+
recommended: ConfigObject;
|
|
87
|
+
"agent-authored": ConfigObject;
|
|
88
|
+
"bash-3.2": ConfigObject;
|
|
89
|
+
"posix-portable": ConfigObject;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export default plugin;
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createAgentAuthoredConfig } from './configs/agent-authored.js';
|
|
2
|
+
import { createBash32Config } from './configs/bash-3-2.js';
|
|
3
|
+
import { createPosixPortableConfig } from './configs/posix-portable.js';
|
|
4
|
+
import { createRecommendedConfig } from './configs/recommended.js';
|
|
5
|
+
import { ShellLanguage } from './language/shell-language.js';
|
|
6
|
+
import { rules } from './rules/index.js';
|
|
7
|
+
import { readPackageVersion } from './version.js';
|
|
8
|
+
export { getDeclaredCommands } from './declaration-conventions/get-declared-commands.js';
|
|
9
|
+
export { commentPragma } from './declaration-conventions/comment-pragma.js';
|
|
10
|
+
export { resolveTransparentWrappers } from './rules/resolve-transparent-wrappers.js';
|
|
11
|
+
export { resolveDeclarationConvention } from './rules/resolve-declaration-convention.js';
|
|
12
|
+
export { defineShellRule } from './rules/define-shell-rule.js';
|
|
13
|
+
export { createWrapperRule } from './rules/create-wrapper-rule.js';
|
|
14
|
+
/* eslint-disable @api-extractor-tools/public-on-non-exported -- `plugin` is exported below as
|
|
15
|
+
`export default plugin`; the rule only recognizes inline exports. */
|
|
16
|
+
/**
|
|
17
|
+
* The `@eslint-sh/eslint-plugin` plugin object, this package's default
|
|
18
|
+
* export (`import sh from '@eslint-sh/eslint-plugin'`). `languages.sh` provides
|
|
19
|
+
* `ShellLanguage` / `ShellSourceCode`, selected in a flat config via
|
|
20
|
+
* `language: "sh/sh"` (`namespace: "sh"`). `meta.version` is read from this
|
|
21
|
+
* package's own `package.json` at runtime — never hardcoded (see
|
|
22
|
+
* `version.ts`).
|
|
23
|
+
*
|
|
24
|
+
* `rules` holds the plugin's built-in rules, each built with
|
|
25
|
+
* `defineShellRule` (so each declares `meta.languages: ["sh/sh"]`) and
|
|
26
|
+
* linking its docs page from `meta.docs.url`. Consumers can also supply their
|
|
27
|
+
* own rules, built with the same `defineShellRule`, while sharing parsing,
|
|
28
|
+
* selectors, source coordinates, and directive semantics.
|
|
29
|
+
*
|
|
30
|
+
* `configs.recommended` is the `sh/recommended` preset: a single config
|
|
31
|
+
* object carrying `plugins: { sh }` and `language: "sh/sh"` but no `files`,
|
|
32
|
+
* so it inherits the globs of the entry that extends it:
|
|
33
|
+
* `{ files: [...], extends: [sh.configs.recommended] }`. It enables the
|
|
34
|
+
* convention-free policy rules. The rules index at
|
|
35
|
+
* https://github.com/mike-north/eslint-sh/blob/main/packages/eslint-plugin/docs/rules/README.md
|
|
36
|
+
* describes preset membership and available autofixes.
|
|
37
|
+
* `configs['agent-authored']` is the strict `sh/agent-authored` preset for
|
|
38
|
+
* machine-written, human-reviewed scripts:
|
|
39
|
+
* every `recommended` rule plus the contract rules, all at `error`.
|
|
40
|
+
* `configs['bash-3.2']` and `configs['posix-portable']` are deployment-target
|
|
41
|
+
* packs: the first sets `languageOptions.minBashVersion: "3.2"` and enables
|
|
42
|
+
* the version-gated `compat/*` rules except the opt-in
|
|
43
|
+
* `compat/no-nounset-empty-array`; the second sets
|
|
44
|
+
* `languageOptions.dialect: "posix"`, enables the effective `compat/*` rules and the
|
|
45
|
+
* shebang/dialect check; it reports named constructs
|
|
46
|
+
* that fail on dash, not every non-POSIX construct, and leaves `local`,
|
|
47
|
+
* `echo -e` and the rest of shellcheck's SC3xxx catalog to shellcheck. Every
|
|
48
|
+
* shipped config is a
|
|
49
|
+
* single object with no `files`; the two packs also carry `languageOptions`,
|
|
50
|
+
* because the target they name is their meaning. Beyond plugin registration
|
|
51
|
+
* and naming, target packs contain only language, languageOptions, and rules
|
|
52
|
+
* whose findings depend on that target. The shebang check belongs because it
|
|
53
|
+
* compares the declared interpreter with the target dialect. Error-handling
|
|
54
|
+
* policy comes from composing recommended, whose POSIX default is `set -eu`.
|
|
55
|
+
* The Bash-only empty-array nounset check cannot report under POSIX and is
|
|
56
|
+
* omitted from posix-portable.
|
|
57
|
+
*
|
|
58
|
+
* Re-exported, unchanged, as the default export of the `eslint-sh` umbrella
|
|
59
|
+
* package: importing this package or the umbrella package both yield the
|
|
60
|
+
* same plugin object.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
const plugin = {
|
|
65
|
+
meta: {
|
|
66
|
+
name: '@eslint-sh/eslint-plugin',
|
|
67
|
+
version: readPackageVersion(),
|
|
68
|
+
namespace: 'sh',
|
|
69
|
+
},
|
|
70
|
+
languages: {
|
|
71
|
+
sh: new ShellLanguage(),
|
|
72
|
+
},
|
|
73
|
+
rules,
|
|
74
|
+
// Filled in below: each shipped config registers this very object under
|
|
75
|
+
// `plugins.sh`, so the plugin must exist before its configs can.
|
|
76
|
+
configs: {},
|
|
77
|
+
};
|
|
78
|
+
/* eslint-enable @api-extractor-tools/public-on-non-exported */
|
|
79
|
+
plugin.configs.recommended = createRecommendedConfig(plugin);
|
|
80
|
+
plugin.configs['agent-authored'] = createAgentAuthoredConfig(plugin);
|
|
81
|
+
plugin.configs['bash-3.2'] = createBash32Config(plugin);
|
|
82
|
+
plugin.configs['posix-portable'] = createPosixPortableConfig(plugin);
|
|
83
|
+
export default plugin;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* Reserved words (`if`, `time`, `[[`, `function`, …) are not here: the
|
|
18
18
|
* parser never produces them as command words.
|
|
19
19
|
*
|
|
20
|
-
* The list is the latest bash's, and is not narrowed by `
|
|
20
|
+
* The list is the latest bash's, and is not narrowed by `minBashVersion`:
|
|
21
21
|
* `mapfile`, `readarray` and `compopt` (added in bash 4.0) are builtins here
|
|
22
22
|
* even for a file configured as bash 3.2. Whether a script may use them on
|
|
23
23
|
* an old bash is a version-compatibility question, not a dependency one.
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* Reserved words (`if`, `time`, `[[`, `function`, …) are not here: the
|
|
18
18
|
* parser never produces them as command words.
|
|
19
19
|
*
|
|
20
|
-
* The list is the latest bash's, and is not narrowed by `
|
|
20
|
+
* The list is the latest bash's, and is not narrowed by `minBashVersion`:
|
|
21
21
|
* `mapfile`, `readarray` and `compopt` (added in bash 4.0) are builtins here
|
|
22
22
|
* even for a file configured as bash 3.2. Whether a script may use them on
|
|
23
23
|
* an old bash is a version-compatibility question, not a dependency one.
|
|
@@ -32,6 +32,8 @@ export declare const BATS_HELPERS: readonly string[];
|
|
|
32
32
|
/**
|
|
33
33
|
* bats' `run`, as a transparent wrapper: it runs the command after its own
|
|
34
34
|
* options and captures the result, so `run curl x` uses `curl`.
|
|
35
|
+
* Only the exact function name has these semantics; an executable path such
|
|
36
|
+
* as `/tmp/run` is an external dependency whose arguments remain opaque.
|
|
35
37
|
*
|
|
36
38
|
* Its options, all before the command (bats-core manual, "`run`: Test other
|
|
37
39
|
* commands"): `-N` (expect exit status N, 0–255), `!` (expect a nonzero
|
|
@@ -16,6 +16,8 @@ export const BATS_HELPERS = Object.freeze([
|
|
|
16
16
|
/**
|
|
17
17
|
* bats' `run`, as a transparent wrapper: it runs the command after its own
|
|
18
18
|
* options and captures the result, so `run curl x` uses `curl`.
|
|
19
|
+
* Only the exact function name has these semantics; an executable path such
|
|
20
|
+
* as `/tmp/run` is an external dependency whose arguments remain opaque.
|
|
19
21
|
*
|
|
20
22
|
* Its options, all before the command (bats-core manual, "`run`: Test other
|
|
21
23
|
* commands"): `-N` (expect exit status N, 0–255), `!` (expect a nonzero
|
|
@@ -28,6 +30,7 @@ export const BATS_HELPERS = Object.freeze([
|
|
|
28
30
|
*/
|
|
29
31
|
export const BATS_RUN_WRAPPER = Object.freeze({
|
|
30
32
|
names: Object.freeze(['run']),
|
|
33
|
+
shellBuiltin: true,
|
|
31
34
|
noArgFlags: Object.freeze(['!', '--keep-empty-lines', '--separate-stderr']),
|
|
32
35
|
noArgFlagPattern: /^-\d+$/u,
|
|
33
36
|
});
|
|
@@ -56,10 +56,10 @@ export declare function definedFunctionNames(sourceCode: ShellSourceCode): Reado
|
|
|
56
56
|
* - builtins of the file's dialect (`sourceCode.dialect`);
|
|
57
57
|
* - functions the file defines anywhere.
|
|
58
58
|
*
|
|
59
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when the file's
|
|
59
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
|
|
60
60
|
* nesting exceeds analysis's recursion guard: a partial harvest would miss
|
|
61
61
|
* real commands.
|
|
62
|
-
* @throws `ShAnalyzeInvalidWrapperSpecError` (from `sh-ast/analyze`) when
|
|
62
|
+
* @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
|
|
63
63
|
* `options.transparentWrappers` contains a malformed entry.
|
|
64
64
|
* @internal
|
|
65
65
|
*/
|
|
@@ -70,10 +70,10 @@ function wordNodeAt(site, index) {
|
|
|
70
70
|
* - builtins of the file's dialect (`sourceCode.dialect`);
|
|
71
71
|
* - functions the file defines anywhere.
|
|
72
72
|
*
|
|
73
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when the file's
|
|
73
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
|
|
74
74
|
* nesting exceeds analysis's recursion guard: a partial harvest would miss
|
|
75
75
|
* real commands.
|
|
76
|
-
* @throws `ShAnalyzeInvalidWrapperSpecError` (from `sh-ast/analyze`) when
|
|
76
|
+
* @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
|
|
77
77
|
* `options.transparentWrappers` contains a malformed entry.
|
|
78
78
|
* @internal
|
|
79
79
|
*/
|
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
import type { WrapperSpec } from 'sh-ast/analyze';
|
|
2
2
|
import type { ShellDialect } from '../language/shell-language-options.js';
|
|
3
3
|
/**
|
|
4
|
-
* Returns the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 1. `sh-ast/analyze`'s `DEFAULT_TRANSPARENT_WRAPPERS` (`sudo`, `env`, …);
|
|
8
|
-
* 2. the dialect's own wrappers (`run` under `bats`);
|
|
9
|
-
* 3. the project's network wrapper (`settings.sh.networkWrapper`), when set,
|
|
10
|
-
* with the options its spec declares: a wrapper that network commands must
|
|
11
|
-
* run through runs the command after it;
|
|
12
|
-
* 4. one name-only entry per configured name. A name-only entry recognizes
|
|
13
|
-
* no flags, so `with-retry -n 3 curl` stops at `-n` rather than guessing
|
|
14
|
-
* past it.
|
|
15
|
-
*
|
|
16
|
-
* The first entry whose names match is the one used, so a network wrapper
|
|
17
|
-
* spec with options wins over a name-only entry for the same name.
|
|
18
|
-
*
|
|
19
|
-
* @param dialect - The linted file's `sourceCode.dialect`.
|
|
20
|
-
* @param wrapperNames - The rule's `transparentWrappers` option names.
|
|
21
|
-
* @param networkWrapper - The spec from `settings.sh.networkWrapper`, or `null`.
|
|
4
|
+
* Returns the built-in harvest scope for a dialect, including bats' in-process
|
|
5
|
+
* `run` helper only in bats files. Project wrappers are resolved separately.
|
|
22
6
|
* @internal
|
|
23
7
|
*/
|
|
24
|
-
export declare function harvestWrapperTable(dialect: ShellDialect
|
|
8
|
+
export declare function harvestWrapperTable(dialect: ShellDialect): readonly WrapperSpec[];
|
|
@@ -1,49 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* `no-undeclared-commands` and `no-unused-declarations` must agree exactly on
|
|
6
|
-
* which commands a file uses, or one would report a command the other calls
|
|
7
|
-
* unused. Usage depends on the wrapper table, so both build it here from the
|
|
8
|
-
* same inputs: the file's dialect, the network wrapper from
|
|
9
|
-
* `settings.sh.networkWrapper`, and the rule's `transparentWrappers` option
|
|
10
|
-
* names.
|
|
2
|
+
* Built-in wrappers used when comparing command declarations with usage.
|
|
3
|
+
* Both declaration rules compose this dialect scope with the shared project
|
|
4
|
+
* facts through resolveTransparentWrappers, so they compute the same usage.
|
|
11
5
|
*/
|
|
12
6
|
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-ast/analyze';
|
|
13
7
|
import { BATS_RUN_WRAPPER } from './builtins/bats.js';
|
|
14
|
-
/**
|
|
15
|
-
* Wrappers a dialect's runtime provides beyond sh-ast's defaults: bats' `run`
|
|
16
|
-
* for `bats` files.
|
|
17
|
-
*/
|
|
8
|
+
/** Wrappers a dialect runtime provides beyond sh-ast's defaults. */
|
|
18
9
|
const DIALECT_WRAPPERS = {
|
|
19
10
|
bats: [BATS_RUN_WRAPPER],
|
|
20
11
|
};
|
|
21
12
|
/**
|
|
22
|
-
* Returns the
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* 1. `sh-ast/analyze`'s `DEFAULT_TRANSPARENT_WRAPPERS` (`sudo`, `env`, …);
|
|
26
|
-
* 2. the dialect's own wrappers (`run` under `bats`);
|
|
27
|
-
* 3. the project's network wrapper (`settings.sh.networkWrapper`), when set,
|
|
28
|
-
* with the options its spec declares: a wrapper that network commands must
|
|
29
|
-
* run through runs the command after it;
|
|
30
|
-
* 4. one name-only entry per configured name. A name-only entry recognizes
|
|
31
|
-
* no flags, so `with-retry -n 3 curl` stops at `-n` rather than guessing
|
|
32
|
-
* past it.
|
|
33
|
-
*
|
|
34
|
-
* The first entry whose names match is the one used, so a network wrapper
|
|
35
|
-
* spec with options wins over a name-only entry for the same name.
|
|
36
|
-
*
|
|
37
|
-
* @param dialect - The linted file's `sourceCode.dialect`.
|
|
38
|
-
* @param wrapperNames - The rule's `transparentWrappers` option names.
|
|
39
|
-
* @param networkWrapper - The spec from `settings.sh.networkWrapper`, or `null`.
|
|
13
|
+
* Returns the built-in harvest scope for a dialect, including bats' in-process
|
|
14
|
+
* `run` helper only in bats files. Project wrappers are resolved separately.
|
|
40
15
|
* @internal
|
|
41
16
|
*/
|
|
42
|
-
export function harvestWrapperTable(dialect
|
|
43
|
-
return [
|
|
44
|
-
...DEFAULT_TRANSPARENT_WRAPPERS,
|
|
45
|
-
...(DIALECT_WRAPPERS[dialect] ?? []),
|
|
46
|
-
...(networkWrapper === null ? [] : [networkWrapper]),
|
|
47
|
-
...wrapperNames.map((name) => ({ names: [name] })),
|
|
48
|
-
];
|
|
17
|
+
export function harvestWrapperTable(dialect) {
|
|
18
|
+
return [...DEFAULT_TRANSPARENT_WRAPPERS, ...(DIALECT_WRAPPERS[dialect] ?? [])];
|
|
49
19
|
}
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
* The `sh/bash-3.2` shared config: the preset for scripts that must run on the
|
|
3
3
|
* Bash 3.2 that macOS ships as `/bin/bash`.
|
|
4
4
|
*
|
|
5
|
-
* The parser accepts every construct its grammar knows whatever
|
|
6
|
-
* configured, so
|
|
7
|
-
* This preset names that
|
|
8
|
-
* and
|
|
9
|
-
*
|
|
5
|
+
* The parser accepts every construct its grammar knows whatever floor is
|
|
6
|
+
* configured, so required Bash 3.2 support is enforced only by the `compat/*` rules.
|
|
7
|
+
* This preset names that floor once (`languageOptions.minBashVersion: '3.2'`)
|
|
8
|
+
* and enables the version gates except the opt-in empty-array nounset check,
|
|
9
|
+
* so a project states its minimum supported Bash as a config choice instead of
|
|
10
|
+
* enumerating rules.
|
|
10
11
|
*
|
|
11
12
|
* It follows the shape contract in `./recommended.ts`, with one deliberate
|
|
12
|
-
* extension: it carries `languageOptions`, because the
|
|
13
|
+
* extension: it carries `languageOptions`, because the minimum supported version is the
|
|
13
14
|
* preset's whole meaning and a pack that left it to the user would enable
|
|
14
15
|
* rules that report nothing. It still carries no `files` or `ignores`, so it
|
|
15
16
|
* inherits the user's globs, and it composes with the other presets through
|
package/dist/configs/bash-3-2.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The rules `sh/bash-3.2` enables:
|
|
2
|
+
* The rules `sh/bash-3.2` enables: twenty-one version-gated `compat/*` rules, all at
|
|
3
3
|
* `error`, keyed as a user writes them (`sh/<rule-name>`). Each reports a
|
|
4
4
|
* feature that Bash 3.2 lacks and names the portable alternative.
|
|
5
|
+
* `compat/no-nounset-empty-array` is opt-in: caller and helper contracts can
|
|
6
|
+
* guarantee non-empty arrays beyond the rule's local safety proofs.
|
|
5
7
|
* `shebang-matches-dialect` is not a version gate and belongs to the
|
|
6
8
|
* presets whose catalog row names it. The POSIX-only gates
|
|
7
9
|
* (`compat/no-double-bracket`, `compat/no-let`, `compat/no-source`) are not
|
|
@@ -26,7 +28,6 @@ const bash32Rules = {
|
|
|
26
28
|
'sh/compat/no-mapfile': 'error',
|
|
27
29
|
'sh/compat/no-nameref': 'error',
|
|
28
30
|
'sh/compat/no-negative-array-index': 'error',
|
|
29
|
-
'sh/compat/no-nounset-empty-array': 'error',
|
|
30
31
|
'sh/compat/no-parameter-transformation': 'error',
|
|
31
32
|
'sh/compat/no-pipe-all': 'error',
|
|
32
33
|
'sh/compat/no-printf-time-format': 'error',
|
|
@@ -45,7 +46,7 @@ export function createBash32Config(plugin) {
|
|
|
45
46
|
name: 'sh/bash-3.2',
|
|
46
47
|
plugins: { sh: plugin },
|
|
47
48
|
language: 'sh/sh',
|
|
48
|
-
languageOptions: { dialect: 'bash',
|
|
49
|
+
languageOptions: { dialect: 'bash', minBashVersion: '3.2' },
|
|
49
50
|
rules: { ...bash32Rules },
|
|
50
51
|
};
|
|
51
52
|
}
|