@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
|
@@ -5,7 +5,8 @@ import { type NormalizedShellLanguageOptions, type ShellLanguageOptions } from '
|
|
|
5
5
|
/**
|
|
6
6
|
* `ShellLanguage` — the `@eslint/core` `Language` implementation for shell
|
|
7
7
|
* scripts. Registered by the plugin as `languages.sh`, so consumers select
|
|
8
|
-
* it via `language: "sh/sh"`.
|
|
8
|
+
* it via `language: "sh/sh"`. Its root export is type-only: `plugin.languages.sh`
|
|
9
|
+
* is the single runtime language handle, and the language pipeline owns source construction.
|
|
9
10
|
*
|
|
10
11
|
* Implements `matchesSelectorClass` (the six launch esquery selector
|
|
11
12
|
* classes — see `./selector-classes.js`), so rules and end users can write
|
|
@@ -26,12 +27,14 @@ export declare class ShellLanguage implements Language {
|
|
|
26
27
|
readonly defaultLanguageOptions: ShellLanguageOptions;
|
|
27
28
|
/**
|
|
28
29
|
* Validates `languageOptions.dialect` (must be one of the five supported
|
|
29
|
-
* dialects, if present), `languageOptions.
|
|
30
|
-
* string matching the `MAJOR[.MINOR]` numeric shape, if present
|
|
30
|
+
* dialects, if present), `languageOptions.minBashVersion` (must be a
|
|
31
|
+
* string matching the `MAJOR[.MINOR]` numeric shape, if present, and
|
|
32
|
+
* applies only to `bash` and `bats`), and
|
|
31
33
|
* `languageOptions.directivePrefix` (must be a valid directive-comment
|
|
32
|
-
* label, if present).
|
|
33
|
-
*
|
|
34
|
+
* label, if present). The removed `shellVersion` key throws with
|
|
35
|
+
* migration guidance; other unknown keys are silently ignored. See `shell-language-options.ts`'s
|
|
34
36
|
* `validateShellLanguageOptions` for the full rationale.
|
|
37
|
+
* @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
|
|
35
38
|
*/
|
|
36
39
|
validateLanguageOptions(languageOptions: ShellLanguageOptions): void;
|
|
37
40
|
/**
|
|
@@ -64,9 +67,9 @@ export declare class ShellLanguage implements Language {
|
|
|
64
67
|
* A file whose extension marks it as a known non-shell source type (for
|
|
65
68
|
* example `.js` or `.json`) is never shell-parsed: it fails with a single
|
|
66
69
|
* diagnostic explaining that a `language: 'sh/sh'` config entry without
|
|
67
|
-
* `files` reached it, and how to scope that entry.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
+
* `files` reached it, and how to scope that entry. Unicode characters remain
|
|
71
|
+
* source text. A native nesting-budget refusal returns no partial tree and
|
|
72
|
+
* becomes a fatal resource diagnostic at 1:1.
|
|
70
73
|
*/
|
|
71
74
|
parse(file: File, context: {
|
|
72
75
|
languageOptions: ShellLanguageOptions;
|
|
@@ -81,8 +84,8 @@ export declare class ShellLanguage implements Language {
|
|
|
81
84
|
* present, but `?? 'eslint'` stays as an explicit, honest fallback for
|
|
82
85
|
* direct construction (e.g. tests that skip the `Language` normalization
|
|
83
86
|
* step), mirroring `parse()`'s `dialect` default above. `dialect` and
|
|
84
|
-
* `
|
|
85
|
-
* through `sourceCode.dialect` / `sourceCode.
|
|
87
|
+
* `minBashVersion` are forwarded so rules read the same normalized values
|
|
88
|
+
* through `sourceCode.dialect` / `sourceCode.minBashVersion`.
|
|
86
89
|
*/
|
|
87
90
|
createSourceCode(file: File, parseResult: OkParseResult<ShellFile>, context: {
|
|
88
91
|
languageOptions: ShellLanguageOptions;
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
/** Adapts upstream parsing and diagnostics to ESLint's synchronous Language contract. */
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { LangError, ParseError, ShParseMaxDepthError, parseWithPositionsSync, } from 'sh-ast';
|
|
3
|
+
import { SHELL_VARIANTS } from '../shell-dialect.js';
|
|
4
4
|
import { nonShellFileError } from './non-shell-file-guard.js';
|
|
5
5
|
import { matchesSelectorClass as matchesShellSelectorClass } from './selector-classes.js';
|
|
6
6
|
import { ShellSourceCode } from './shell-source-code.js';
|
|
7
7
|
import { SourceCoordinates } from './source-coordinates.js';
|
|
8
8
|
import { adaptSyntaxFile, shellVisitorKeys } from './syntax-view.js';
|
|
9
9
|
import { normalizeShellLanguageOptions, validateShellLanguageOptions, } from './shell-language-options.js';
|
|
10
|
-
/** Configuration labels map to exact upstream constants; no shell-version policy is added to parsing. */
|
|
11
|
-
const DIALECT_VARIANTS = {
|
|
12
|
-
bash: LangBash,
|
|
13
|
-
posix: LangPOSIX,
|
|
14
|
-
mksh: LangMirBSDKorn,
|
|
15
|
-
bats: LangBats,
|
|
16
|
-
zsh: LangZsh,
|
|
17
|
-
};
|
|
18
10
|
/** ESLint declares mutable visitor arrays; give it its own copy of the shared consumer relationships. */
|
|
19
11
|
const mutableShellVisitorKeys = Object.fromEntries(Object.entries(shellVisitorKeys).map(([type, keys]) => [type, [...keys]]));
|
|
20
12
|
/**
|
|
@@ -50,32 +42,20 @@ function toFileError(error, source) {
|
|
|
50
42
|
column: location.column,
|
|
51
43
|
};
|
|
52
44
|
}
|
|
45
|
+
// A native budget refusal carries no partial tree or source position. It is
|
|
46
|
+
// an input resource limit, not a broken parser runtime; later files may parse.
|
|
47
|
+
if (error instanceof ShParseMaxDepthError) {
|
|
48
|
+
return { message: error.message, line: 1, column: 1 };
|
|
49
|
+
}
|
|
53
50
|
// Bridge/input failures carry no asserted syntax position. The fallback is an ESLint presentation policy.
|
|
54
51
|
const detail = error instanceof Error ? error.message : String(error);
|
|
55
52
|
return { message: `${PARSER_RUNTIME_FAILURE_PREFIX}${detail}`, line: 1, column: 1 };
|
|
56
53
|
}
|
|
57
|
-
/**
|
|
58
|
-
* The fatal parse error for a source in which the parser drops text at a U+0080, at that
|
|
59
|
-
* character, or `undefined` when nothing is dropped. Checked before parsing so a silently
|
|
60
|
-
* truncated tree never reaches the rules. A U+0080 the parser reads as an ordinary character
|
|
61
|
-
* (inside a quoted-delimiter heredoc body, after a backslash) is not an error; one the parser
|
|
62
|
-
* rejects (inside quotes or an expansion) is reported by the parser itself.
|
|
63
|
-
*/
|
|
64
|
-
function endOfInputMarkerError(source, options) {
|
|
65
|
-
const index = firstDroppedTextIndex(source, options);
|
|
66
|
-
if (index === undefined)
|
|
67
|
-
return undefined;
|
|
68
|
-
const location = new SourceCoordinates(source).atIndex(index);
|
|
69
|
-
return {
|
|
70
|
-
message: 'the character U+0080 is not supported: the parser reads it as end of input',
|
|
71
|
-
line: location.line,
|
|
72
|
-
column: location.column,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
54
|
/**
|
|
76
55
|
* `ShellLanguage` — the `@eslint/core` `Language` implementation for shell
|
|
77
56
|
* scripts. Registered by the plugin as `languages.sh`, so consumers select
|
|
78
|
-
* it via `language: "sh/sh"`.
|
|
57
|
+
* it via `language: "sh/sh"`. Its root export is type-only: `plugin.languages.sh`
|
|
58
|
+
* is the single runtime language handle, and the language pipeline owns source construction.
|
|
79
59
|
*
|
|
80
60
|
* Implements `matchesSelectorClass` (the six launch esquery selector
|
|
81
61
|
* classes — see `./selector-classes.js`), so rules and end users can write
|
|
@@ -96,12 +76,14 @@ export class ShellLanguage {
|
|
|
96
76
|
defaultLanguageOptions = { dialect: 'bash' };
|
|
97
77
|
/**
|
|
98
78
|
* Validates `languageOptions.dialect` (must be one of the five supported
|
|
99
|
-
* dialects, if present), `languageOptions.
|
|
100
|
-
* string matching the `MAJOR[.MINOR]` numeric shape, if present
|
|
79
|
+
* dialects, if present), `languageOptions.minBashVersion` (must be a
|
|
80
|
+
* string matching the `MAJOR[.MINOR]` numeric shape, if present, and
|
|
81
|
+
* applies only to `bash` and `bats`), and
|
|
101
82
|
* `languageOptions.directivePrefix` (must be a valid directive-comment
|
|
102
|
-
* label, if present).
|
|
103
|
-
*
|
|
83
|
+
* label, if present). The removed `shellVersion` key throws with
|
|
84
|
+
* migration guidance; other unknown keys are silently ignored. See `shell-language-options.ts`'s
|
|
104
85
|
* `validateShellLanguageOptions` for the full rationale.
|
|
86
|
+
* @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
|
|
105
87
|
*/
|
|
106
88
|
validateLanguageOptions(languageOptions) {
|
|
107
89
|
validateShellLanguageOptions(languageOptions);
|
|
@@ -140,9 +122,9 @@ export class ShellLanguage {
|
|
|
140
122
|
* A file whose extension marks it as a known non-shell source type (for
|
|
141
123
|
* example `.js` or `.json`) is never shell-parsed: it fails with a single
|
|
142
124
|
* diagnostic explaining that a `language: 'sh/sh'` config entry without
|
|
143
|
-
* `files` reached it, and how to scope that entry.
|
|
144
|
-
*
|
|
145
|
-
*
|
|
125
|
+
* `files` reached it, and how to scope that entry. Unicode characters remain
|
|
126
|
+
* source text. A native nesting-budget refusal returns no partial tree and
|
|
127
|
+
* becomes a fatal resource diagnostic at 1:1.
|
|
146
128
|
*/
|
|
147
129
|
parse(file, context) {
|
|
148
130
|
const misappliedError = nonShellFileError(file.path);
|
|
@@ -152,14 +134,10 @@ export class ShellLanguage {
|
|
|
152
134
|
const text = file.body;
|
|
153
135
|
const dialect = context.languageOptions.dialect ?? 'bash';
|
|
154
136
|
const parseOptions = {
|
|
155
|
-
Variant:
|
|
137
|
+
Variant: SHELL_VARIANTS[dialect],
|
|
156
138
|
Filename: file.path,
|
|
157
139
|
KeepComments: true,
|
|
158
140
|
};
|
|
159
|
-
const unsupported = endOfInputMarkerError(text, parseOptions);
|
|
160
|
-
if (unsupported !== undefined) {
|
|
161
|
-
return { ok: false, errors: [unsupported] };
|
|
162
|
-
}
|
|
163
141
|
try {
|
|
164
142
|
const parsed = parseWithPositionsSync(text, parseOptions);
|
|
165
143
|
const ast = adaptSyntaxFile(parsed.File, text, parsed.Positions);
|
|
@@ -179,8 +157,8 @@ export class ShellLanguage {
|
|
|
179
157
|
* present, but `?? 'eslint'` stays as an explicit, honest fallback for
|
|
180
158
|
* direct construction (e.g. tests that skip the `Language` normalization
|
|
181
159
|
* step), mirroring `parse()`'s `dialect` default above. `dialect` and
|
|
182
|
-
* `
|
|
183
|
-
* through `sourceCode.dialect` / `sourceCode.
|
|
160
|
+
* `minBashVersion` are forwarded so rules read the same normalized values
|
|
161
|
+
* through `sourceCode.dialect` / `sourceCode.minBashVersion`.
|
|
184
162
|
*/
|
|
185
163
|
createSourceCode(file, parseResult, context) {
|
|
186
164
|
return new ShellSourceCode({
|
|
@@ -188,9 +166,9 @@ export class ShellLanguage {
|
|
|
188
166
|
ast: parseResult.ast,
|
|
189
167
|
directivePrefix: context.languageOptions.directivePrefix ?? 'eslint',
|
|
190
168
|
dialect: context.languageOptions.dialect ?? 'bash',
|
|
191
|
-
...(context.languageOptions.
|
|
169
|
+
...(context.languageOptions.minBashVersion === undefined
|
|
192
170
|
? {}
|
|
193
|
-
: {
|
|
171
|
+
: { minBashVersion: context.languageOptions.minBashVersion }),
|
|
194
172
|
});
|
|
195
173
|
}
|
|
196
174
|
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESLint's per-file shell view: source coordinates, grammar-aware analysis and
|
|
3
|
+
* checked syntax edits for rules. The language pipeline owns construction;
|
|
4
|
+
* consumers receive this instance through their rule context.
|
|
5
|
+
* Guard codes distinguish malformed argument shapes, foreign views, inexact
|
|
6
|
+
* ranges and printer content loss. Dependency analysis/printing errors retain
|
|
7
|
+
* their classes, codes and causes.
|
|
8
|
+
*/
|
|
1
9
|
import { TextSourceCodeBase } from '@eslint/plugin-kit';
|
|
2
10
|
import type { ShellFile as ShFile, ShellNode as ShNode, ShellNodeOf, ShellComment } from './syntax-view.js';
|
|
3
11
|
import type { Directive as IDirective, FileProblem, RulesConfig, SourceLocation, TraversalStep } from '@eslint/core';
|
|
4
12
|
import type { Node as SyntaxNode, PrintOptions, SyntaxPos } from 'sh-ast';
|
|
5
|
-
import type { Argv0Resolution, ResolveArgv0Options, ResolveWordOptions } from 'sh-ast/analyze';
|
|
13
|
+
import type { Argv0Resolution, ResolveArgv0Options, ResolveWordOptions, WordResolution } from 'sh-ast/analyze';
|
|
6
14
|
import type { ShellDialect, ShellLanguageOptions } from './shell-language-options.js';
|
|
7
15
|
import type { ShellCommandSite } from './command-resolution.js';
|
|
8
16
|
/**
|
|
@@ -32,12 +40,15 @@ import type { ShellCommandSite } from './command-resolution.js';
|
|
|
32
40
|
* classes) is implemented on `ShellLanguage` — see `shell-language.ts` and
|
|
33
41
|
* `selector-classes.ts`.
|
|
34
42
|
*
|
|
35
|
-
*
|
|
43
|
+
* Exported from the package root as a type only. Rules receive the instance
|
|
44
|
+
* from `context.sourceCode`; its constructor is internal language plumbing.
|
|
45
|
+
*
|
|
46
|
+
* Rule-author helpers (`resolveWord`, `resolveWordText`, `getCommandName`,
|
|
36
47
|
* `resolveInvokedCommand`, `getCommandSites`) answer "is this word statically
|
|
37
48
|
* the string `jq`?", "which command does this invocation run?", and "which
|
|
38
49
|
* commands does this file run, and where?" by delegating to
|
|
39
50
|
* `sh-ast/analyze`. They never reinterpret words themselves, so every rule
|
|
40
|
-
* gets the same answer for the same syntax. `dialect` and `
|
|
51
|
+
* gets the same answer for the same syntax. `dialect` and `minBashVersion`
|
|
41
52
|
* expose the file's normalized language options.
|
|
42
53
|
*
|
|
43
54
|
* Syntax access (`getSyntax`, `getViewNode`, `getIndexFromSyntaxPos`,
|
|
@@ -64,7 +75,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
64
75
|
ast: ShFile;
|
|
65
76
|
directivePrefix?: string;
|
|
66
77
|
dialect?: ShellDialect;
|
|
67
|
-
|
|
78
|
+
minBashVersion?: string;
|
|
68
79
|
});
|
|
69
80
|
/**
|
|
70
81
|
* The shell dialect this file was parsed as: the normalized
|
|
@@ -73,11 +84,12 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
73
84
|
*/
|
|
74
85
|
get dialect(): ShellDialect;
|
|
75
86
|
/**
|
|
76
|
-
* The configured `languageOptions.
|
|
87
|
+
* The configured `languageOptions.minBashVersion` (a `MAJOR[.MINOR]` string
|
|
77
88
|
* such as `"3.2"`), or `undefined` when the config does not set one. The
|
|
78
|
-
*
|
|
89
|
+
* script must support this Bash and every newer release. The parser never
|
|
90
|
+
* reads it; compatibility rules use it as a floor with no upper limit.
|
|
79
91
|
*/
|
|
80
|
-
get
|
|
92
|
+
get minBashVersion(): string | undefined;
|
|
81
93
|
/**
|
|
82
94
|
* The one-based location of a UTF-16 `index` in this file's text, where
|
|
83
95
|
* `index` may be anywhere from 0 to `text.length`. CRLF counts as one line
|
|
@@ -88,8 +100,8 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
88
100
|
* file's root starts at its first statement or comment, so the base answer
|
|
89
101
|
* was shifted by any leading blank lines or indentation.
|
|
90
102
|
*
|
|
91
|
-
* @throws TypeError when `index` is not a number.
|
|
92
|
-
* @throws RangeError when `index` is not an integer from 0 to `text.length`.
|
|
103
|
+
* @throws TypeError with `ESLINT_SH_SOURCE_INDEX` when `index` is not a number.
|
|
104
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `index` is not an integer from 0 to `text.length`.
|
|
93
105
|
*/
|
|
94
106
|
getLocFromIndex(index: number): {
|
|
95
107
|
line: number;
|
|
@@ -102,35 +114,40 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
102
114
|
*
|
|
103
115
|
* Overrides the base class for the same reason as `getLocFromIndex`.
|
|
104
116
|
*
|
|
105
|
-
* @throws TypeError when `loc` is not an object with numeric `line` and `column`.
|
|
106
|
-
* @throws RangeError when `loc` is not inside the text.
|
|
117
|
+
* @throws TypeError with `ESLINT_SH_SOURCE_LOCATION` when `loc` is not an object with numeric `line` and `column`.
|
|
118
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `loc` is not inside the text.
|
|
107
119
|
*/
|
|
108
120
|
getIndexFromLoc(loc: {
|
|
109
121
|
line: number;
|
|
110
122
|
column: number;
|
|
111
123
|
}): number;
|
|
112
124
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
125
|
+
* Resolves a lint-view word using its original syntax and grammar position.
|
|
126
|
+
* `sh-ast/analyze` owns static-word interpretation and dynamic reasons; this
|
|
127
|
+
* method supplies the lint tree's position-based policy, without executing shell.
|
|
115
128
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* Call the root `resolveWord` export instead when the reason matters.
|
|
129
|
+
* Without explicit options, `CallExpr.args` use command-argument context, so
|
|
130
|
+
* `PATH=a:~/bin` is literal there. Other positions retain the analyzer's
|
|
131
|
+
* conservative default, including tilde expansion after an unquoted colon.
|
|
132
|
+
* Explicit options are forwarded unchanged, even when empty.
|
|
121
133
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* `
|
|
126
|
-
*
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
* @param word - A parsed Word from the lint view.
|
|
135
|
+
* @param options - Explicit analysis policy overriding grammar defaults.
|
|
136
|
+
* @returns Static text or the analyzer's reason the word is dynamic.
|
|
137
|
+
* @throws TypeError with `ESLINT_SH_WORD_NODE` when the word has no associated parsed shell syntax.
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
resolveWord(word: ShellNodeOf<'Word'>, options?: ResolveWordOptions): WordResolution;
|
|
141
|
+
/**
|
|
142
|
+
* The text-only form of {@link ShellSourceCode.resolveWord}: returns its text
|
|
143
|
+
* exactly when static, otherwise `null`. Both methods share one policy path
|
|
144
|
+
* through `sh-ast/analyze`.
|
|
129
145
|
*
|
|
130
|
-
* @param word - A parsed
|
|
131
|
-
* @param options -
|
|
146
|
+
* @param word - A parsed Word from the lint view.
|
|
147
|
+
* @param options - Explicit analysis policy overriding grammar defaults.
|
|
132
148
|
* @returns The resolved text, or `null` when the word is not static.
|
|
133
|
-
* @throws TypeError when `word` is not a parsed shell `Word`.
|
|
149
|
+
* @throws TypeError with `ESLINT_SH_WORD_NODE` when `word` is not a parsed shell `Word`.
|
|
150
|
+
* @public
|
|
134
151
|
*/
|
|
135
152
|
resolveWordText(word: ShellNodeOf<'Word'>, options?: ResolveWordOptions): string | null;
|
|
136
153
|
/**
|
|
@@ -148,8 +165,8 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
148
165
|
*
|
|
149
166
|
* @param callExpr - A parsed `CallExpr` node from this file's lint tree.
|
|
150
167
|
* @returns The command word's static text, or `null`.
|
|
151
|
-
* @throws TypeError when `callExpr` is not a parsed shell `CallExpr`.
|
|
152
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
|
|
168
|
+
* @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
|
|
169
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
|
|
153
170
|
* nesting exceeds analysis's recursion guard; see
|
|
154
171
|
* {@link ShellSourceCode.resolveInvokedCommand}.
|
|
155
172
|
*/
|
|
@@ -166,13 +183,19 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
166
183
|
* effective command's name as
|
|
167
184
|
* `res.effective.static ? res.effective.text : null`.
|
|
168
185
|
* `sudo -u x "$prog"` and `exec "$@"` have a non-static `effective` with
|
|
169
|
-
* reason `expansion`; `env -S '…'`
|
|
186
|
+
* reason `expansion`; `env -S '…'` and `bash -c '…'` have reason
|
|
187
|
+
* `embedded-command`; `chain`
|
|
170
188
|
* lists every word resolved along the way, outermost wrapper first, and
|
|
171
189
|
* `chainIndices` gives each entry's position in the command's `argv` (as
|
|
172
190
|
* {@link ShellSourceCode.getCommandSites} reports it). When `effective` is
|
|
173
191
|
* static, the effective command's arguments are
|
|
174
192
|
* `argv.slice(chainIndices.at(-1)! + 1)`: every entry after the effective
|
|
175
|
-
* command's own index.
|
|
193
|
+
* command's own index. For an interpreter command string the final chain
|
|
194
|
+
* index instead locates the selector flag; the interpreter is in `chain.at(-2)`.
|
|
195
|
+
* `embeddedCommandInterpreters: []` retains the interpreter as the static
|
|
196
|
+
* effective command when a policy needs program identity. Utility wrappers
|
|
197
|
+
* can match absolute-path basenames; `shellBuiltin: true` entries require
|
|
198
|
+
* exact names, so external paths do not acquire in-process semantics.
|
|
176
199
|
*
|
|
177
200
|
* Enumeration runs once per file, the first time any command helper is
|
|
178
201
|
* called. If the file's nesting exceeds `enumerateCommands`'s recursion
|
|
@@ -186,10 +209,10 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
186
209
|
* `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
|
|
187
210
|
* extend them instead.
|
|
188
211
|
* @returns The resolution, or `null` when `callExpr` invokes no command.
|
|
189
|
-
* @throws TypeError when `callExpr` is not a parsed shell `CallExpr`.
|
|
190
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
|
|
212
|
+
* @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
|
|
213
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
|
|
191
214
|
* nesting exceeds analysis's recursion guard.
|
|
192
|
-
* @throws `ShAnalyzeInvalidWrapperSpecError` (from `sh-ast/analyze`) when
|
|
215
|
+
* @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
|
|
193
216
|
* `options.transparentWrappers` contains a malformed entry.
|
|
194
217
|
*/
|
|
195
218
|
resolveInvokedCommand(callExpr: ShellNodeOf<'CallExpr'>, options?: ResolveArgv0Options): Argv0Resolution | null;
|
|
@@ -221,7 +244,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
221
244
|
* does for those helpers: a partial list would silently omit real commands.
|
|
222
245
|
*
|
|
223
246
|
* @returns This file's command sites, in source order.
|
|
224
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
|
|
247
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
|
|
225
248
|
* nesting exceeds analysis's recursion guard.
|
|
226
249
|
*/
|
|
227
250
|
getCommandSites(): readonly ShellCommandSite[];
|
|
@@ -280,7 +303,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
280
303
|
* printing"), so no second parse is involved. The copy owns its records,
|
|
281
304
|
* arrays, positions and byte buffers. Editing it leaves this file's original
|
|
282
305
|
* syntax, its lint view, its cached traversal and the answers of view-aware
|
|
283
|
-
* helpers such as
|
|
306
|
+
* helpers such as {@link ShellSourceCode.resolveWord} and
|
|
284
307
|
* {@link ShellSourceCode.resolveWordText} unchanged. Each call returns a new
|
|
285
308
|
* copy.
|
|
286
309
|
*
|
|
@@ -292,7 +315,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
292
315
|
*
|
|
293
316
|
* @param node - A view node from this file's lint tree.
|
|
294
317
|
* @returns A deep copy of `node`'s original sh-ast record.
|
|
295
|
-
* @throws TypeError when `node` has no original record in this file: an
|
|
318
|
+
* @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file: an
|
|
296
319
|
* auxiliary view (such as the `Slice` of `${x:1:2}`), a view node of another
|
|
297
320
|
* file, or an object that did not come from the parser.
|
|
298
321
|
*/
|
|
@@ -330,12 +353,14 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
330
353
|
* `Command` or `WordPart`.
|
|
331
354
|
* @param options - Forwarded to `printSync` unchanged.
|
|
332
355
|
* @returns The range to replace and the printed text to put there.
|
|
333
|
-
* @throws TypeError when `node` has no original record in this file (see
|
|
356
|
+
* @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file (see
|
|
334
357
|
* {@link ShellSourceCode.getEditableSyntax}), when `edited` is not a
|
|
335
|
-
* printable root (the message names its type), or when the printer's output
|
|
336
|
-
* is not valid UTF-8
|
|
337
|
-
*
|
|
338
|
-
*
|
|
358
|
+
* printable root (`ESLINT_SH_PRINT_ROOT`; the message names its type), or when the printer's output
|
|
359
|
+
* is not valid UTF-8 (`ESLINT_SH_PRINT_ENCODING`), or the edited syntax contains literal vertical tabs or
|
|
360
|
+
* form feeds that the printer cannot preserve (`ESLINT_SH_PRINT_UNSAFE_TEXT`). Non-UTF-8 output comes back
|
|
361
|
+
* from `printSync` as a `Uint8Array` and is never decoded lossily into a fix.
|
|
362
|
+
* @throws `PrintError` (`SH_AST_SYNTAX_PRINT`), `PrintPanicError` (`SH_AST_SYNTAX_PRINT_PANIC`),
|
|
363
|
+
* or `InputError` (`SH_AST_SYNTAX_INPUT`), passed through unchanged from sh-ast, when upstream's
|
|
339
364
|
* printer fails for `edited` or `options`.
|
|
340
365
|
*/
|
|
341
366
|
getPrintedReplacement(node: ShNode, edited: SyntaxNode, options?: PrintOptions): {
|
|
@@ -356,12 +381,12 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
356
381
|
*
|
|
357
382
|
* @param pos - A `SyntaxPos` from one of this file's original records.
|
|
358
383
|
* @returns The UTF-16 index of `pos` in this file's text.
|
|
359
|
-
* @throws RangeError when `pos` is invalid (`IsValid === false`), recovered
|
|
384
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid (`IsValid === false`), recovered
|
|
360
385
|
* (`IsRecovered === true`), or overflowed (`OffsetOverflow === true`), or
|
|
361
386
|
* when its offset is not a UTF-8 character boundary of this source. Such a
|
|
362
387
|
* position is never rounded to a nearby boundary.
|
|
363
|
-
* @throws TypeError when `pos` is not a `SyntaxPos`, or when this source
|
|
364
|
-
* code's tree was not built by this language's parser.
|
|
388
|
+
* @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
|
|
389
|
+
* code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
|
|
365
390
|
*/
|
|
366
391
|
getIndexFromSyntaxPos(pos: SyntaxPos): number;
|
|
367
392
|
/**
|
|
@@ -372,10 +397,10 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
372
397
|
*
|
|
373
398
|
* @param pos - A `SyntaxPos` from one of this file's original records.
|
|
374
399
|
* @returns The one-based line and UTF-16 column of `pos`.
|
|
375
|
-
* @throws RangeError when `pos` is invalid, recovered, or overflowed, or
|
|
400
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid, recovered, or overflowed, or
|
|
376
401
|
* when its offset is not a UTF-8 character boundary of this source.
|
|
377
|
-
* @throws TypeError when `pos` is not a `SyntaxPos`, or when this source
|
|
378
|
-
* code's tree was not built by this language's parser.
|
|
402
|
+
* @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
|
|
403
|
+
* code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
|
|
379
404
|
*/
|
|
380
405
|
getLocFromSyntaxPos(pos: SyntaxPos): {
|
|
381
406
|
line: number;
|