@eslint-sh/eslint-plugin 0.8.0 → 0.10.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 +58 -57
- package/dist/api.d.ts +92 -0
- package/dist/api.js +83 -0
- package/dist/command-harvest/builtins/bats.d.ts +1 -1
- package/dist/command-harvest/harvest-commands.d.ts +18 -7
- package/dist/command-harvest/harvest-commands.js +11 -10
- package/dist/command-harvest/wrapper-table.d.ts +1 -1
- package/dist/command-harvest/wrapper-table.js +1 -1
- package/dist/configs/posix-portable.d.ts +6 -10
- 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 +1516 -0
- package/dist/eslint-plugin.d.ts +16 -1560
- package/dist/index.d.ts +14 -81
- package/dist/index.js +22 -76
- package/dist/language/command-resolution.d.ts +47 -13
- package/dist/language/command-resolution.js +48 -18
- 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 +3 -3
- package/dist/language/shell-language-options.js +12 -17
- package/dist/language/shell-language.d.ts +3 -1
- package/dist/language/shell-language.js +6 -11
- package/dist/language/shell-source-code.d.ts +77 -77
- package/dist/language/shell-source-code.js +107 -98
- package/dist/language/source-coordinates.d.ts +2 -0
- package/dist/language/source-coordinates.js +8 -4
- package/dist/language/syntax-view.d.ts +1 -1
- package/dist/language/syntax-view.js +19 -7
- package/dist/language/word-resolution.d.ts +4 -3
- package/dist/language/word-resolution.js +10 -5
- package/dist/rules/compat/declaration-options.js +2 -2
- package/dist/rules/compat/no-brace-sequence-padding-step.js +1 -1
- package/dist/rules/compat/no-mapfile.js +2 -2
- package/dist/rules/compat/no-negative-array-index.js +2 -2
- package/dist/rules/compat/no-printf-time-format.js +2 -2
- package/dist/rules/compat/no-test-v.js +2 -2
- package/dist/rules/compat/no-wait-n.js +2 -2
- package/dist/rules/compat/posix-absent-command.js +2 -2
- package/dist/rules/compat/shopt-options.js +2 -2
- package/dist/rules/create-wrapper-rule.d.ts +4 -4
- package/dist/rules/create-wrapper-rule.js +19 -13
- package/dist/rules/define-shell-rule.js +1 -1
- package/dist/rules/no-dynamic-invocation.d.ts +1 -1
- package/dist/rules/no-dynamic-invocation.js +12 -4
- package/dist/rules/no-eval.js +6 -2
- package/dist/rules/no-masked-exit-status.d.ts +4 -3
- package/dist/rules/no-masked-exit-status.js +4 -3
- package/dist/rules/no-secret-env-reads.d.ts +2 -0
- package/dist/rules/no-secret-env-reads.js +14 -3
- package/dist/rules/no-secret-flags.d.ts +2 -0
- package/dist/rules/no-secret-flags.js +14 -3
- package/dist/rules/no-unchecked-cd.js +4 -3
- package/dist/rules/no-undeclared-commands.js +10 -4
- package/dist/rules/no-unused-declarations.js +13 -4
- package/dist/rules/prefer-local.d.ts +3 -2
- package/dist/rules/prefer-local.js +4 -2
- package/dist/rules/quote-expansions.js +1 -1
- package/dist/rules/require-network-wrapper.d.ts +2 -2
- package/dist/rules/require-network-wrapper.js +21 -11
- 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 +9 -2
- package/dist/rules/resolve-declaration-convention.d.ts +9 -88
- package/dist/rules/resolve-declaration-convention.js +19 -71
- package/dist/rules/resolve-network-wrapper.d.ts +3 -4
- package/dist/rules/resolve-network-wrapper.js +23 -19
- package/dist/rules/resolve-transparent-wrappers.d.ts +3 -8
- package/dist/rules/resolve-transparent-wrappers.js +21 -11
- package/dist/rules/set-options.d.ts +1 -1
- package/dist/rules/set-options.js +1 -1
- 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 +3 -3
- package/dist/rules/transparent-wrappers.js +1 -1
- package/dist/rules/user-pattern.d.ts +4 -3
- package/dist/rules/user-pattern.js +10 -8
- package/dist/shell-dialect.d.ts +8 -0
- package/dist/shell-dialect.js +22 -0
- package/dist/version.js +2 -1
- package/docs/compat.md +5 -6
- package/docs/custom-rule-tutorial.md +55 -51
- package/docs/declaration-conventions.md +20 -23
- package/docs/error-codes.md +94 -0
- package/docs/examples/no-backticks-rule.mjs +1 -1
- package/docs/examples/no-curl-in-functions-rule.mjs +2 -2
- package/docs/examples/no-listed-commands-rule.ts +1 -1
- 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 +12 -4
- package/docs/rules/compat/no-nounset-empty-array.md +1 -1
- package/docs/rules/no-dynamic-invocation.md +5 -0
- package/docs/rules/no-masked-exit-status.md +2 -2
- package/docs/rules/no-secret-env-reads.md +13 -3
- package/docs/rules/no-secret-flags.md +14 -5
- package/docs/rules/no-unchecked-cd.md +15 -2
- package/docs/rules/no-undeclared-commands.md +4 -0
- package/docs/rules/no-unused-declarations.md +4 -0
- package/docs/rules/require-network-wrapper.md +6 -6
- package/docs/rules/require-strict-mode.md +25 -23
- package/docs/rules/require-tty-guard.md +12 -3
- package/docs/selectors.md +7 -2
- package/docs/wrapper-rules.md +3 -1
- package/package.json +9 -20
- package/dist/declaration-conventions/read-declared-commands.d.ts +0 -70
- package/dist/eslint-plugin-syntax-analyze.d.ts +0 -23
- package/dist/eslint-plugin-syntax.d.ts +0 -31
- package/dist/syntax/analyze.d.ts +0 -19
- package/dist/syntax/analyze.js +0 -21
- package/dist/syntax/index.d.ts +0 -27
- package/dist/syntax/index.js +0 -29
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
/** Adapts upstream parsing and diagnostics to ESLint's synchronous Language contract. */
|
|
2
|
-
import {
|
|
2
|
+
import { LangError, ParseError, ShParseMaxDepthError, parseWithPositionsSync, } from 'sh-ast';
|
|
3
|
+
import { SHELL_VARIANTS } from '../shell-dialect.js';
|
|
3
4
|
import { nonShellFileError } from './non-shell-file-guard.js';
|
|
4
5
|
import { matchesSelectorClass as matchesShellSelectorClass } from './selector-classes.js';
|
|
5
6
|
import { ShellSourceCode } from './shell-source-code.js';
|
|
6
7
|
import { SourceCoordinates } from './source-coordinates.js';
|
|
7
8
|
import { adaptSyntaxFile, shellVisitorKeys } from './syntax-view.js';
|
|
8
9
|
import { normalizeShellLanguageOptions, validateShellLanguageOptions, } from './shell-language-options.js';
|
|
9
|
-
/** Configuration labels map to exact upstream constants; no shell-version policy is added to parsing. */
|
|
10
|
-
const DIALECT_VARIANTS = {
|
|
11
|
-
bash: LangBash,
|
|
12
|
-
posix: LangPOSIX,
|
|
13
|
-
mksh: LangMirBSDKorn,
|
|
14
|
-
bats: LangBats,
|
|
15
|
-
zsh: LangZsh,
|
|
16
|
-
};
|
|
17
10
|
/** ESLint declares mutable visitor arrays; give it its own copy of the shared consumer relationships. */
|
|
18
11
|
const mutableShellVisitorKeys = Object.fromEntries(Object.entries(shellVisitorKeys).map(([type, keys]) => [type, [...keys]]));
|
|
19
12
|
/**
|
|
@@ -61,7 +54,8 @@ function toFileError(error, source) {
|
|
|
61
54
|
/**
|
|
62
55
|
* `ShellLanguage` — the `@eslint/core` `Language` implementation for shell
|
|
63
56
|
* scripts. Registered by the plugin as `languages.sh`, so consumers select
|
|
64
|
-
* 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.
|
|
65
59
|
*
|
|
66
60
|
* Implements `matchesSelectorClass` (the six launch esquery selector
|
|
67
61
|
* classes — see `./selector-classes.js`), so rules and end users can write
|
|
@@ -89,6 +83,7 @@ export class ShellLanguage {
|
|
|
89
83
|
* label, if present). The removed `shellVersion` key throws with
|
|
90
84
|
* migration guidance; other unknown keys are silently ignored. See `shell-language-options.ts`'s
|
|
91
85
|
* `validateShellLanguageOptions` for the full rationale.
|
|
86
|
+
* @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
|
|
92
87
|
*/
|
|
93
88
|
validateLanguageOptions(languageOptions) {
|
|
94
89
|
validateShellLanguageOptions(languageOptions);
|
|
@@ -139,7 +134,7 @@ export class ShellLanguage {
|
|
|
139
134
|
const text = file.body;
|
|
140
135
|
const dialect = context.languageOptions.dialect ?? 'bash';
|
|
141
136
|
const parseOptions = {
|
|
142
|
-
Variant:
|
|
137
|
+
Variant: SHELL_VARIANTS[dialect],
|
|
143
138
|
Filename: file.path,
|
|
144
139
|
KeepComments: true,
|
|
145
140
|
};
|
|
@@ -1,10 +1,18 @@
|
|
|
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-
|
|
13
|
+
import type { Argv0Resolution, ResolveArgv0Options, ResolveWordOptions, WordResolution } from 'sh-analysis';
|
|
6
14
|
import type { ShellDialect, ShellLanguageOptions } from './shell-language-options.js';
|
|
7
|
-
import type {
|
|
15
|
+
import type { ShellCommandInventory } from './command-resolution.js';
|
|
8
16
|
/**
|
|
9
17
|
* `ShellSourceCode` — the `SourceCode` object ESLint uses to work with a
|
|
10
18
|
* parsed shell file. Extends `@eslint/plugin-kit`'s `TextSourceCodeBase`, which
|
|
@@ -32,11 +40,14 @@ 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
|
-
*
|
|
36
|
-
*
|
|
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`,
|
|
47
|
+
* `resolveInvokedCommand`, `getCommandInventory`) 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
|
-
* `sh-
|
|
50
|
+
* `sh-analysis`. They never reinterpret words themselves, so every rule
|
|
40
51
|
* gets the same answer for the same syntax. `dialect` and `minBashVersion`
|
|
41
52
|
* expose the file's normalized language options.
|
|
42
53
|
*
|
|
@@ -89,8 +100,8 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
89
100
|
* file's root starts at its first statement or comment, so the base answer
|
|
90
101
|
* was shifted by any leading blank lines or indentation.
|
|
91
102
|
*
|
|
92
|
-
* @throws TypeError when `index` is not a number.
|
|
93
|
-
* @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`.
|
|
94
105
|
*/
|
|
95
106
|
getLocFromIndex(index: number): {
|
|
96
107
|
line: number;
|
|
@@ -103,35 +114,40 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
103
114
|
*
|
|
104
115
|
* Overrides the base class for the same reason as `getLocFromIndex`.
|
|
105
116
|
*
|
|
106
|
-
* @throws TypeError when `loc` is not an object with numeric `line` and `column`.
|
|
107
|
-
* @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.
|
|
108
119
|
*/
|
|
109
120
|
getIndexFromLoc(loc: {
|
|
110
121
|
line: number;
|
|
111
122
|
column: number;
|
|
112
123
|
}): number;
|
|
113
124
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
125
|
+
* Resolves a lint-view word using its original syntax and grammar position.
|
|
126
|
+
* `sh-analysis` owns static-word interpretation and dynamic reasons; this
|
|
127
|
+
* method supplies the lint tree's position-based policy, without executing shell.
|
|
116
128
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* 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.
|
|
122
133
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* `
|
|
127
|
-
*
|
|
128
|
-
|
|
129
|
-
|
|
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-analysis`.
|
|
130
145
|
*
|
|
131
|
-
* @param word - A parsed
|
|
132
|
-
* @param options -
|
|
146
|
+
* @param word - A parsed Word from the lint view.
|
|
147
|
+
* @param options - Explicit analysis policy overriding grammar defaults.
|
|
133
148
|
* @returns The resolved text, or `null` when the word is not static.
|
|
134
|
-
* @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
|
|
135
151
|
*/
|
|
136
152
|
resolveWordText(word: ShellNodeOf<'Word'>, options?: ResolveWordOptions): string | null;
|
|
137
153
|
/**
|
|
@@ -141,7 +157,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
141
157
|
* {@link ShellSourceCode.resolveInvokedCommand} for the command a wrapper
|
|
142
158
|
* chain actually runs.
|
|
143
159
|
*
|
|
144
|
-
* Delegates to `sh-
|
|
160
|
+
* Delegates to `sh-analysis`: the answer is the `argv0` resolution of the
|
|
145
161
|
* `CommandSite` that `enumerateCommands` reports for this `CallExpr` in this
|
|
146
162
|
* file. Leading `VAR=val` assignments are not part of argv, so
|
|
147
163
|
* `FOO=1 jq .` yields `"jq"`. An assignment-only statement (`FOO=1`) has no
|
|
@@ -149,15 +165,15 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
149
165
|
*
|
|
150
166
|
* @param callExpr - A parsed `CallExpr` node from this file's lint tree.
|
|
151
167
|
* @returns The command word's static text, or `null`.
|
|
152
|
-
* @throws TypeError when `callExpr` is not a parsed shell `CallExpr`.
|
|
153
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-
|
|
168
|
+
* @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
|
|
169
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
|
|
154
170
|
* nesting exceeds analysis's recursion guard; see
|
|
155
171
|
* {@link ShellSourceCode.resolveInvokedCommand}.
|
|
156
172
|
*/
|
|
157
173
|
getCommandName(callExpr: ShellNodeOf<'CallExpr'>): string | null;
|
|
158
174
|
/**
|
|
159
175
|
* Follows `callExpr`'s argv0 through transparent wrappers (`env`, `sudo`,
|
|
160
|
-
* `nohup`, `exec`, …) and returns `sh-
|
|
176
|
+
* `nohup`, `exec`, …) and returns `sh-analysis`'s full `resolveArgv0`
|
|
161
177
|
* result, or `null` for a `CallExpr` that has no `CommandSite` (an
|
|
162
178
|
* assignment-only statement such as `FOO=1`).
|
|
163
179
|
*
|
|
@@ -171,7 +187,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
171
187
|
* `embedded-command`; `chain`
|
|
172
188
|
* lists every word resolved along the way, outermost wrapper first, and
|
|
173
189
|
* `chainIndices` gives each entry's position in the command's `argv` (as
|
|
174
|
-
* {@link ShellSourceCode.
|
|
190
|
+
* {@link ShellSourceCode.getCommandInventory} reports it). When `effective` is
|
|
175
191
|
* static, the effective command's arguments are
|
|
176
192
|
* `argv.slice(chainIndices.at(-1)! + 1)`: every entry after the effective
|
|
177
193
|
* command's own index. For an interpreter command string the final chain
|
|
@@ -189,49 +205,32 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
189
205
|
*
|
|
190
206
|
* @param callExpr - A parsed `CallExpr` node from this file's lint tree.
|
|
191
207
|
* @param options - Forwarded to `resolveArgv0` unchanged.
|
|
192
|
-
* `transparentWrappers` replaces `sh-
|
|
208
|
+
* `transparentWrappers` replaces `sh-analysis`'s
|
|
193
209
|
* `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
|
|
194
210
|
* extend them instead.
|
|
195
211
|
* @returns The resolution, or `null` when `callExpr` invokes no command.
|
|
196
|
-
* @throws TypeError when `callExpr` is not a parsed shell `CallExpr`.
|
|
197
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-
|
|
212
|
+
* @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
|
|
213
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_ANALYSIS_MAX_DEPTH`, from `sh-analysis`) when this file's
|
|
198
214
|
* nesting exceeds analysis's recursion guard.
|
|
199
|
-
* @throws `ShAnalyzeInvalidWrapperSpecError` (from `sh-
|
|
215
|
+
* @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_ANALYSIS_INVALID_WRAPPER_SPEC`, from `sh-analysis`) when
|
|
200
216
|
* `options.transparentWrappers` contains a malformed entry.
|
|
201
217
|
*/
|
|
202
218
|
resolveInvokedCommand(callExpr: ShellNodeOf<'CallExpr'>, options?: ResolveArgv0Options): Argv0Resolution | null;
|
|
203
219
|
/**
|
|
204
|
-
* Returns
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* command inside a function or inside `$(…)`, instead of visiting
|
|
208
|
-
* `CallExpr` nodes one by one.
|
|
209
|
-
*
|
|
210
|
-
* The data comes from `sh-ast/analyze`'s `enumerateCommands`: facts about
|
|
211
|
-
* how each command is reached and what its words resolve to, never a
|
|
212
|
-
* verdict. Each entry's `context`, `argv0`, and `argv` are analysis's own
|
|
213
|
-
* values, unchanged; `context` lists frames outermost first, as in sh-ast.
|
|
214
|
-
* Each entry's `node` is the `CallExpr` view node (`===` the node ESLint
|
|
215
|
-
* passes to a `CallExpr` visitor), so it can be passed to
|
|
216
|
-
* `context.report()`.
|
|
220
|
+
* Returns represented command sites and explicit opaque execution boundaries.
|
|
221
|
+
* Both retain original node identity in this file's UTF-16 ESLint view. This
|
|
222
|
+
* adapter maps sh-analysis observations without parsing text or choosing policy.
|
|
217
223
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
224
|
+
* The inventory and observation data are frozen and shared across rules; view
|
|
225
|
+
* nodes retain ESLint's ordinary mutable-node contract. Enumeration runs once,
|
|
226
|
+
* lazily, shared with getCommandName and resolveInvokedCommand. Analysis errors
|
|
227
|
+
* propagate unchanged rather than returning a partial inventory.
|
|
220
228
|
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* same array. Because every rule shares it, the array and everything in each
|
|
225
|
-
* entry except `node` are deeply frozen (see `ShellCommandSite`): no rule can
|
|
226
|
-
* change what another rule reads. If the file's nesting exceeds `enumerateCommands`'s
|
|
227
|
-
* recursion guard, its `ShAnalyzeMaxDepthError` propagates unchanged, as it
|
|
228
|
-
* does for those helpers: a partial list would silently omit real commands.
|
|
229
|
-
*
|
|
230
|
-
* @returns This file's command sites, in source order.
|
|
231
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
|
|
232
|
-
* nesting exceeds analysis's recursion guard.
|
|
229
|
+
* A known-command policy may inspect `commands`; any assertion of execution
|
|
230
|
+
* completeness must also account for `uncertainties` and its own dynamic-code
|
|
231
|
+
* assumptions. Empty commands with nonempty uncertainties never proves no execution.
|
|
233
232
|
*/
|
|
234
|
-
|
|
233
|
+
getCommandInventory(): ShellCommandInventory;
|
|
235
234
|
/**
|
|
236
235
|
* Returns the sh-ast record `node` was projected from: this file's original
|
|
237
236
|
* parse of `node`, with every field the lint view leaves out, including
|
|
@@ -239,7 +238,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
239
238
|
* `Redirect.OpPos`. Pass those positions to
|
|
240
239
|
* {@link ShellSourceCode.getIndexFromSyntaxPos} or
|
|
241
240
|
* {@link ShellSourceCode.getLocFromSyntaxPos} to report on them, or pass the
|
|
242
|
-
* record to an `sh-
|
|
241
|
+
* record to an `sh-analysis` function.
|
|
243
242
|
*
|
|
244
243
|
* The returned record is read-only by contract. It is the language's
|
|
245
244
|
* original parse, shared by every rule and helper linting this file, and
|
|
@@ -287,7 +286,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
287
286
|
* printing"), so no second parse is involved. The copy owns its records,
|
|
288
287
|
* arrays, positions and byte buffers. Editing it leaves this file's original
|
|
289
288
|
* syntax, its lint view, its cached traversal and the answers of view-aware
|
|
290
|
-
* helpers such as
|
|
289
|
+
* helpers such as {@link ShellSourceCode.resolveWord} and
|
|
291
290
|
* {@link ShellSourceCode.resolveWordText} unchanged. Each call returns a new
|
|
292
291
|
* copy.
|
|
293
292
|
*
|
|
@@ -299,7 +298,7 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
299
298
|
*
|
|
300
299
|
* @param node - A view node from this file's lint tree.
|
|
301
300
|
* @returns A deep copy of `node`'s original sh-ast record.
|
|
302
|
-
* @throws TypeError when `node` has no original record in this file: an
|
|
301
|
+
* @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file: an
|
|
303
302
|
* auxiliary view (such as the `Slice` of `${x:1:2}`), a view node of another
|
|
304
303
|
* file, or an object that did not come from the parser.
|
|
305
304
|
*/
|
|
@@ -337,13 +336,14 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
337
336
|
* `Command` or `WordPart`.
|
|
338
337
|
* @param options - Forwarded to `printSync` unchanged.
|
|
339
338
|
* @returns The range to replace and the printed text to put there.
|
|
340
|
-
* @throws TypeError when `node` has no original record in this file (see
|
|
339
|
+
* @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file (see
|
|
341
340
|
* {@link ShellSourceCode.getEditableSyntax}), when `edited` is not a
|
|
342
|
-
* printable root (the message names its type), or when the printer's output
|
|
343
|
-
* is not valid UTF-8, or the edited syntax contains literal vertical tabs or
|
|
344
|
-
* form feeds that the printer cannot preserve. Non-UTF-8 output comes back
|
|
341
|
+
* printable root (`ESLINT_SH_PRINT_ROOT`; the message names its type), or when the printer's output
|
|
342
|
+
* is not valid UTF-8 (`ESLINT_SH_PRINT_ENCODING`), or the edited syntax contains literal vertical tabs or
|
|
343
|
+
* form feeds that the printer cannot preserve (`ESLINT_SH_PRINT_UNSAFE_TEXT`). Non-UTF-8 output comes back
|
|
345
344
|
* from `printSync` as a `Uint8Array` and is never decoded lossily into a fix.
|
|
346
|
-
* @throws `PrintError`
|
|
345
|
+
* @throws `PrintError` (`SH_AST_SYNTAX_PRINT`), `PrintPanicError` (`SH_AST_SYNTAX_PRINT_PANIC`),
|
|
346
|
+
* or `InputError` (`SH_AST_SYNTAX_INPUT`), passed through unchanged from sh-ast, when upstream's
|
|
347
347
|
* printer fails for `edited` or `options`.
|
|
348
348
|
*/
|
|
349
349
|
getPrintedReplacement(node: ShNode, edited: SyntaxNode, options?: PrintOptions): {
|
|
@@ -364,12 +364,12 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
364
364
|
*
|
|
365
365
|
* @param pos - A `SyntaxPos` from one of this file's original records.
|
|
366
366
|
* @returns The UTF-16 index of `pos` in this file's text.
|
|
367
|
-
* @throws RangeError when `pos` is invalid (`IsValid === false`), recovered
|
|
367
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid (`IsValid === false`), recovered
|
|
368
368
|
* (`IsRecovered === true`), or overflowed (`OffsetOverflow === true`), or
|
|
369
369
|
* when its offset is not a UTF-8 character boundary of this source. Such a
|
|
370
370
|
* position is never rounded to a nearby boundary.
|
|
371
|
-
* @throws TypeError when `pos` is not a `SyntaxPos`, or when this source
|
|
372
|
-
* code's tree was not built by this language's parser.
|
|
371
|
+
* @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
|
|
372
|
+
* code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
|
|
373
373
|
*/
|
|
374
374
|
getIndexFromSyntaxPos(pos: SyntaxPos): number;
|
|
375
375
|
/**
|
|
@@ -380,10 +380,10 @@ export declare class ShellSourceCode extends TextSourceCodeBase<{
|
|
|
380
380
|
*
|
|
381
381
|
* @param pos - A `SyntaxPos` from one of this file's original records.
|
|
382
382
|
* @returns The one-based line and UTF-16 column of `pos`.
|
|
383
|
-
* @throws RangeError when `pos` is invalid, recovered, or overflowed, or
|
|
383
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid, recovered, or overflowed, or
|
|
384
384
|
* when its offset is not a UTF-8 character boundary of this source.
|
|
385
|
-
* @throws TypeError when `pos` is not a `SyntaxPos`, or when this source
|
|
386
|
-
* code's tree was not built by this language's parser.
|
|
385
|
+
* @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
|
|
386
|
+
* code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
|
|
387
387
|
*/
|
|
388
388
|
getLocFromSyntaxPos(pos: SyntaxPos): {
|
|
389
389
|
line: number;
|