@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
|
@@ -1,3 +1,11 @@
|
|
|
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 { ConfigCommentParser, Directive, TextSourceCodeBase, VisitNodeStep, } from '@eslint/plugin-kit';
|
|
2
10
|
import { childNodes, isShellComment, projectedComments, projectedCoordinates, syntaxForNode, viewForSyntax, walkShell, } from './syntax-view.js';
|
|
3
11
|
import { SourceCoordinates } from './source-coordinates.js';
|
|
@@ -5,6 +13,38 @@ import { SYNTAX_INTERFACES, printSync } from 'sh-ast';
|
|
|
5
13
|
import { resolveArgv0 } from 'sh-ast/analyze';
|
|
6
14
|
import { buildCommandSiteIndex, rawCallExprFor, viewCommandSites } from './command-resolution.js';
|
|
7
15
|
import { resolveWord } from './word-resolution.js';
|
|
16
|
+
/**
|
|
17
|
+
* Refuses edited syntax whose string or byte values the upstream printer treats as layout.
|
|
18
|
+
* Checking the edited tree also catches controls introduced by a rule, without refusing ordinary
|
|
19
|
+
* text edits elsewhere in a file. The input filename is metadata, never printer output.
|
|
20
|
+
* Iteration tolerates shared/cyclic records; sh-ast still validates
|
|
21
|
+
* the printable syntax itself.
|
|
22
|
+
*/
|
|
23
|
+
// format.ts's refusePrinterControlCharacters independently guards the formatter's source text.
|
|
24
|
+
function refusePrinterControlCharacters(root) {
|
|
25
|
+
const pending = [root.Type === 'File' ? { ...root, Name: '' } : root];
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
while (pending.length > 0) {
|
|
28
|
+
const current = pending.pop();
|
|
29
|
+
const unsafe = (typeof current === 'string' && /[\v\f]/u.test(current)) ||
|
|
30
|
+
(current instanceof Uint8Array && current.some((byte) => byte === 0x0b || byte === 0x0c));
|
|
31
|
+
if (unsafe) {
|
|
32
|
+
throw Object.assign(new TypeError('cannot print a text fix containing literal vertical tabs and form feeds: ' +
|
|
33
|
+
'the printer changes their value'), { code: 'ESLINT_SH_PRINT_UNSAFE_TEXT' });
|
|
34
|
+
}
|
|
35
|
+
// A checked byte-valued string is a leaf; its individual numbers are not syntax children.
|
|
36
|
+
if (current instanceof Uint8Array) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (current !== null && typeof current === 'object' && !seen.has(current)) {
|
|
40
|
+
seen.add(current);
|
|
41
|
+
const children = Object.values(current);
|
|
42
|
+
for (const child of children) {
|
|
43
|
+
pending.push(child);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
8
48
|
/**
|
|
9
49
|
* Shared instance — `ConfigCommentParser` is stateless (see
|
|
10
50
|
* `@eslint/plugin-kit`'s implementation), so every `ShellSourceCode`
|
|
@@ -188,8 +228,8 @@ function computeUnusedDirectiveFixRange(comment, text) {
|
|
|
188
228
|
* converting them would place a report or fix somewhere the parser never
|
|
189
229
|
* pointed. They are rejected rather than rounded to a nearby boundary.
|
|
190
230
|
*
|
|
191
|
-
* @throws TypeError when `pos` is not shaped like an sh-ast `SyntaxPos`.
|
|
192
|
-
* @throws RangeError when `pos` is invalid, recovered, or overflowed.
|
|
231
|
+
* @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not shaped like an sh-ast `SyntaxPos`.
|
|
232
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid, recovered, or overflowed.
|
|
193
233
|
*/
|
|
194
234
|
function exactByteOffset(pos) {
|
|
195
235
|
const candidate = pos;
|
|
@@ -199,11 +239,13 @@ function exactByteOffset(pos) {
|
|
|
199
239
|
typeof pos.IsValid !== 'boolean' ||
|
|
200
240
|
typeof pos.IsRecovered !== 'boolean' ||
|
|
201
241
|
typeof pos.OffsetOverflow !== 'boolean') {
|
|
202
|
-
throw new TypeError('expected an sh-ast SyntaxPos')
|
|
242
|
+
throw Object.assign(new TypeError('expected an sh-ast SyntaxPos'), {
|
|
243
|
+
code: 'ESLINT_SH_SYNTAX_POSITION',
|
|
244
|
+
});
|
|
203
245
|
}
|
|
204
246
|
if (!pos.IsValid || pos.IsRecovered || pos.OffsetOverflow) {
|
|
205
|
-
throw new RangeError(`syntax position has no exact source offset (IsValid: ${String(pos.IsValid)}, ` +
|
|
206
|
-
`IsRecovered: ${String(pos.IsRecovered)}, OffsetOverflow: ${String(pos.OffsetOverflow)})`);
|
|
247
|
+
throw Object.assign(new RangeError(`syntax position has no exact source offset (IsValid: ${String(pos.IsValid)}, ` +
|
|
248
|
+
`IsRecovered: ${String(pos.IsRecovered)}, OffsetOverflow: ${String(pos.OffsetOverflow)})`), { code: 'ESLINT_SH_SOURCE_RANGE' });
|
|
207
249
|
}
|
|
208
250
|
return pos.Offset;
|
|
209
251
|
}
|
|
@@ -233,11 +275,13 @@ function printableRootType(edited) {
|
|
|
233
275
|
candidate === null ||
|
|
234
276
|
!('Type' in candidate) ||
|
|
235
277
|
typeof candidate.Type !== 'string') {
|
|
236
|
-
throw new TypeError('expected an sh-ast syntax record to print')
|
|
278
|
+
throw Object.assign(new TypeError('expected an sh-ast syntax record to print'), {
|
|
279
|
+
code: 'ESLINT_SH_PRINT_ROOT',
|
|
280
|
+
});
|
|
237
281
|
}
|
|
238
282
|
if (!printableRootTypes.has(candidate.Type)) {
|
|
239
|
-
throw new TypeError(`cannot print a ${candidate.Type} as a fix: printSync accepts File, Stmt, Word, Assign, ` +
|
|
240
|
-
'Command and WordPart roots');
|
|
283
|
+
throw Object.assign(new TypeError(`cannot print a ${candidate.Type} as a fix: printSync accepts File, Stmt, Word, Assign, ` +
|
|
284
|
+
'Command and WordPart roots'), { code: 'ESLINT_SH_PRINT_ROOT' });
|
|
241
285
|
}
|
|
242
286
|
return candidate.Type;
|
|
243
287
|
}
|
|
@@ -291,12 +335,15 @@ function withUnusedDirectiveFixRange(comment, text) {
|
|
|
291
335
|
* classes) is implemented on `ShellLanguage` — see `shell-language.ts` and
|
|
292
336
|
* `selector-classes.ts`.
|
|
293
337
|
*
|
|
294
|
-
*
|
|
338
|
+
* Exported from the package root as a type only. Rules receive the instance
|
|
339
|
+
* from `context.sourceCode`; its constructor is internal language plumbing.
|
|
340
|
+
*
|
|
341
|
+
* Rule-author helpers (`resolveWord`, `resolveWordText`, `getCommandName`,
|
|
295
342
|
* `resolveInvokedCommand`, `getCommandSites`) answer "is this word statically
|
|
296
343
|
* the string `jq`?", "which command does this invocation run?", and "which
|
|
297
344
|
* commands does this file run, and where?" by delegating to
|
|
298
345
|
* `sh-ast/analyze`. They never reinterpret words themselves, so every rule
|
|
299
|
-
* gets the same answer for the same syntax. `dialect` and `
|
|
346
|
+
* gets the same answer for the same syntax. `dialect` and `minBashVersion`
|
|
300
347
|
* expose the file's normalized language options.
|
|
301
348
|
*
|
|
302
349
|
* Syntax access (`getSyntax`, `getViewNode`, `getIndexFromSyntaxPos`,
|
|
@@ -356,8 +403,8 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
356
403
|
#inlineConfigNodes;
|
|
357
404
|
/** The normalized `languageOptions.dialect` this file was parsed with. */
|
|
358
405
|
#dialect;
|
|
359
|
-
/** The configured `languageOptions.
|
|
360
|
-
#
|
|
406
|
+
/** The configured `languageOptions.minBashVersion`, if the config supplied one. */
|
|
407
|
+
#minBashVersion;
|
|
361
408
|
/** This file's coordinate index; see `#textCoordinates`. */
|
|
362
409
|
#ownCoordinates;
|
|
363
410
|
/**
|
|
@@ -380,7 +427,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
380
427
|
// supplies the already-normalized, defaulted values.
|
|
381
428
|
this.#directivePrefix = options.directivePrefix ?? 'eslint';
|
|
382
429
|
this.#dialect = options.dialect ?? 'bash';
|
|
383
|
-
this.#
|
|
430
|
+
this.#minBashVersion = options.minBashVersion;
|
|
384
431
|
this.#directiveLabels = buildDirectiveLabels(this.#directivePrefix);
|
|
385
432
|
this.#inlineConfigPattern = buildInlineConfigPattern(this.#directivePrefix);
|
|
386
433
|
}
|
|
@@ -393,12 +440,13 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
393
440
|
return this.#dialect;
|
|
394
441
|
}
|
|
395
442
|
/**
|
|
396
|
-
* The configured `languageOptions.
|
|
443
|
+
* The configured `languageOptions.minBashVersion` (a `MAJOR[.MINOR]` string
|
|
397
444
|
* such as `"3.2"`), or `undefined` when the config does not set one. The
|
|
398
|
-
*
|
|
445
|
+
* script must support this Bash and every newer release. The parser never
|
|
446
|
+
* reads it; compatibility rules use it as a floor with no upper limit.
|
|
399
447
|
*/
|
|
400
|
-
get
|
|
401
|
-
return this.#
|
|
448
|
+
get minBashVersion() {
|
|
449
|
+
return this.#minBashVersion;
|
|
402
450
|
}
|
|
403
451
|
/**
|
|
404
452
|
* The one-based location of a UTF-16 `index` in this file's text, where
|
|
@@ -410,12 +458,15 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
410
458
|
* file's root starts at its first statement or comment, so the base answer
|
|
411
459
|
* was shifted by any leading blank lines or indentation.
|
|
412
460
|
*
|
|
413
|
-
* @throws TypeError when `index` is not a number.
|
|
414
|
-
* @throws RangeError when `index` is not an integer from 0 to `text.length`.
|
|
461
|
+
* @throws TypeError with `ESLINT_SH_SOURCE_INDEX` when `index` is not a number.
|
|
462
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `index` is not an integer from 0 to `text.length`.
|
|
415
463
|
*/
|
|
416
464
|
getLocFromIndex(index) {
|
|
417
|
-
if (typeof index !== 'number')
|
|
418
|
-
throw new TypeError('Expected `index` to be a number.')
|
|
465
|
+
if (typeof index !== 'number') {
|
|
466
|
+
throw Object.assign(new TypeError('Expected `index` to be a number.'), {
|
|
467
|
+
code: 'ESLINT_SH_SOURCE_INDEX',
|
|
468
|
+
});
|
|
469
|
+
}
|
|
419
470
|
const { line, column } = this.#textCoordinates().atIndex(index);
|
|
420
471
|
return { line, column };
|
|
421
472
|
}
|
|
@@ -426,8 +477,8 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
426
477
|
*
|
|
427
478
|
* Overrides the base class for the same reason as `getLocFromIndex`.
|
|
428
479
|
*
|
|
429
|
-
* @throws TypeError when `loc` is not an object with numeric `line` and `column`.
|
|
430
|
-
* @throws RangeError when `loc` is not inside the text.
|
|
480
|
+
* @throws TypeError with `ESLINT_SH_SOURCE_LOCATION` when `loc` is not an object with numeric `line` and `column`.
|
|
481
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `loc` is not inside the text.
|
|
431
482
|
*/
|
|
432
483
|
getIndexFromLoc(loc) {
|
|
433
484
|
if (typeof loc !== 'object' ||
|
|
@@ -435,7 +486,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
435
486
|
loc === null ||
|
|
436
487
|
typeof loc.line !== 'number' ||
|
|
437
488
|
typeof loc.column !== 'number') {
|
|
438
|
-
throw new TypeError('Expected `loc` to be an object with numeric `line` and `column` properties.');
|
|
489
|
+
throw Object.assign(new TypeError('Expected `loc` to be an object with numeric `line` and `column` properties.'), { code: 'ESLINT_SH_SOURCE_LOCATION' });
|
|
439
490
|
}
|
|
440
491
|
return this.#textCoordinates().indexAt(loc.line, loc.column);
|
|
441
492
|
}
|
|
@@ -449,30 +500,37 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
449
500
|
return this.#ownCoordinates;
|
|
450
501
|
}
|
|
451
502
|
/**
|
|
452
|
-
*
|
|
453
|
-
*
|
|
503
|
+
* Resolves a lint-view word using its original syntax and grammar position.
|
|
504
|
+
* `sh-ast/analyze` owns static-word interpretation and dynamic reasons; this
|
|
505
|
+
* method supplies the lint tree's position-based policy, without executing shell.
|
|
454
506
|
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
* Call the root `resolveWord` export instead when the reason matters.
|
|
507
|
+
* Without explicit options, `CallExpr.args` use command-argument context, so
|
|
508
|
+
* `PATH=a:~/bin` is literal there. Other positions retain the analyzer's
|
|
509
|
+
* conservative default, including tilde expansion after an unquoted colon.
|
|
510
|
+
* Explicit options are forwarded unchanged, even when empty.
|
|
460
511
|
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
* `
|
|
465
|
-
*
|
|
466
|
-
|
|
467
|
-
|
|
512
|
+
* @param word - A parsed Word from the lint view.
|
|
513
|
+
* @param options - Explicit analysis policy overriding grammar defaults.
|
|
514
|
+
* @returns Static text or the analyzer's reason the word is dynamic.
|
|
515
|
+
* @throws TypeError with `ESLINT_SH_WORD_NODE` when the word has no associated parsed shell syntax.
|
|
516
|
+
* @public
|
|
517
|
+
*/
|
|
518
|
+
resolveWord(word, options) {
|
|
519
|
+
return resolveWord(word, options ?? this.#defaultWordOptions(word));
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* The text-only form of {@link ShellSourceCode.resolveWord}: returns its text
|
|
523
|
+
* exactly when static, otherwise `null`. Both methods share one policy path
|
|
524
|
+
* through `sh-ast/analyze`.
|
|
468
525
|
*
|
|
469
|
-
* @param word - A parsed
|
|
470
|
-
* @param options -
|
|
526
|
+
* @param word - A parsed Word from the lint view.
|
|
527
|
+
* @param options - Explicit analysis policy overriding grammar defaults.
|
|
471
528
|
* @returns The resolved text, or `null` when the word is not static.
|
|
472
|
-
* @throws TypeError when `word` is not a parsed shell `Word`.
|
|
529
|
+
* @throws TypeError with `ESLINT_SH_WORD_NODE` when `word` is not a parsed shell `Word`.
|
|
530
|
+
* @public
|
|
473
531
|
*/
|
|
474
532
|
resolveWordText(word, options) {
|
|
475
|
-
const resolution = resolveWord(word, options
|
|
533
|
+
const resolution = this.resolveWord(word, options);
|
|
476
534
|
return resolution.static ? resolution.text : null;
|
|
477
535
|
}
|
|
478
536
|
/**
|
|
@@ -500,8 +558,8 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
500
558
|
*
|
|
501
559
|
* @param callExpr - A parsed `CallExpr` node from this file's lint tree.
|
|
502
560
|
* @returns The command word's static text, or `null`.
|
|
503
|
-
* @throws TypeError when `callExpr` is not a parsed shell `CallExpr`.
|
|
504
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
|
|
561
|
+
* @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
|
|
562
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
|
|
505
563
|
* nesting exceeds analysis's recursion guard; see
|
|
506
564
|
* {@link ShellSourceCode.resolveInvokedCommand}.
|
|
507
565
|
*/
|
|
@@ -521,13 +579,19 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
521
579
|
* effective command's name as
|
|
522
580
|
* `res.effective.static ? res.effective.text : null`.
|
|
523
581
|
* `sudo -u x "$prog"` and `exec "$@"` have a non-static `effective` with
|
|
524
|
-
* reason `expansion`; `env -S '…'`
|
|
582
|
+
* reason `expansion`; `env -S '…'` and `bash -c '…'` have reason
|
|
583
|
+
* `embedded-command`; `chain`
|
|
525
584
|
* lists every word resolved along the way, outermost wrapper first, and
|
|
526
585
|
* `chainIndices` gives each entry's position in the command's `argv` (as
|
|
527
586
|
* {@link ShellSourceCode.getCommandSites} reports it). When `effective` is
|
|
528
587
|
* static, the effective command's arguments are
|
|
529
588
|
* `argv.slice(chainIndices.at(-1)! + 1)`: every entry after the effective
|
|
530
|
-
* command's own index.
|
|
589
|
+
* command's own index. For an interpreter command string the final chain
|
|
590
|
+
* index instead locates the selector flag; the interpreter is in `chain.at(-2)`.
|
|
591
|
+
* `embeddedCommandInterpreters: []` retains the interpreter as the static
|
|
592
|
+
* effective command when a policy needs program identity. Utility wrappers
|
|
593
|
+
* can match absolute-path basenames; `shellBuiltin: true` entries require
|
|
594
|
+
* exact names, so external paths do not acquire in-process semantics.
|
|
531
595
|
*
|
|
532
596
|
* Enumeration runs once per file, the first time any command helper is
|
|
533
597
|
* called. If the file's nesting exceeds `enumerateCommands`'s recursion
|
|
@@ -541,10 +605,10 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
541
605
|
* `DEFAULT_TRANSPARENT_WRAPPERS`; spread the defaults into the array to
|
|
542
606
|
* extend them instead.
|
|
543
607
|
* @returns The resolution, or `null` when `callExpr` invokes no command.
|
|
544
|
-
* @throws TypeError when `callExpr` is not a parsed shell `CallExpr`.
|
|
545
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
|
|
608
|
+
* @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed shell `CallExpr`.
|
|
609
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
|
|
546
610
|
* nesting exceeds analysis's recursion guard.
|
|
547
|
-
* @throws `ShAnalyzeInvalidWrapperSpecError` (from `sh-ast/analyze`) when
|
|
611
|
+
* @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
|
|
548
612
|
* `options.transparentWrappers` contains a malformed entry.
|
|
549
613
|
*/
|
|
550
614
|
resolveInvokedCommand(callExpr, options) {
|
|
@@ -579,7 +643,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
579
643
|
* does for those helpers: a partial list would silently omit real commands.
|
|
580
644
|
*
|
|
581
645
|
* @returns This file's command sites, in source order.
|
|
582
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when this file's
|
|
646
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when this file's
|
|
583
647
|
* nesting exceeds analysis's recursion guard.
|
|
584
648
|
*/
|
|
585
649
|
getCommandSites() {
|
|
@@ -647,7 +711,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
647
711
|
* printing"), so no second parse is involved. The copy owns its records,
|
|
648
712
|
* arrays, positions and byte buffers. Editing it leaves this file's original
|
|
649
713
|
* syntax, its lint view, its cached traversal and the answers of view-aware
|
|
650
|
-
* helpers such as
|
|
714
|
+
* helpers such as {@link ShellSourceCode.resolveWord} and
|
|
651
715
|
* {@link ShellSourceCode.resolveWordText} unchanged. Each call returns a new
|
|
652
716
|
* copy.
|
|
653
717
|
*
|
|
@@ -659,7 +723,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
659
723
|
*
|
|
660
724
|
* @param node - A view node from this file's lint tree.
|
|
661
725
|
* @returns A deep copy of `node`'s original sh-ast record.
|
|
662
|
-
* @throws TypeError when `node` has no original record in this file: an
|
|
726
|
+
* @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file: an
|
|
663
727
|
* auxiliary view (such as the `Slice` of `${x:1:2}`), a view node of another
|
|
664
728
|
* file, or an object that did not come from the parser.
|
|
665
729
|
*/
|
|
@@ -699,22 +763,25 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
699
763
|
* `Command` or `WordPart`.
|
|
700
764
|
* @param options - Forwarded to `printSync` unchanged.
|
|
701
765
|
* @returns The range to replace and the printed text to put there.
|
|
702
|
-
* @throws TypeError when `node` has no original record in this file (see
|
|
766
|
+
* @throws TypeError with `ESLINT_SH_FOREIGN_VIEW_NODE` when `node` has no original record in this file (see
|
|
703
767
|
* {@link ShellSourceCode.getEditableSyntax}), when `edited` is not a
|
|
704
|
-
* printable root (the message names its type), or when the printer's output
|
|
705
|
-
* is not valid UTF-8
|
|
706
|
-
*
|
|
707
|
-
*
|
|
768
|
+
* printable root (`ESLINT_SH_PRINT_ROOT`; the message names its type), or when the printer's output
|
|
769
|
+
* is not valid UTF-8 (`ESLINT_SH_PRINT_ENCODING`), or the edited syntax contains literal vertical tabs or
|
|
770
|
+
* form feeds that the printer cannot preserve (`ESLINT_SH_PRINT_UNSAFE_TEXT`). Non-UTF-8 output comes back
|
|
771
|
+
* from `printSync` as a `Uint8Array` and is never decoded lossily into a fix.
|
|
772
|
+
* @throws `PrintError` (`SH_AST_SYNTAX_PRINT`), `PrintPanicError` (`SH_AST_SYNTAX_PRINT_PANIC`),
|
|
773
|
+
* or `InputError` (`SH_AST_SYNTAX_INPUT`), passed through unchanged from sh-ast, when upstream's
|
|
708
774
|
* printer fails for `edited` or `options`.
|
|
709
775
|
*/
|
|
710
776
|
getPrintedReplacement(node, edited, options) {
|
|
711
777
|
const original = this.#originalSyntaxFor(node);
|
|
712
778
|
const rootType = printableRootType(edited);
|
|
713
779
|
const root = edited.Type === 'Stmt' ? { ...edited, Comments: null } : edited;
|
|
780
|
+
refusePrinterControlCharacters(root);
|
|
714
781
|
const printed = printSync(root, options);
|
|
715
782
|
if (typeof printed !== 'string') {
|
|
716
|
-
throw new TypeError('printSync produced output that is not valid UTF-8; a text fix cannot hold it without ' +
|
|
717
|
-
'lossy decoding');
|
|
783
|
+
throw Object.assign(new TypeError('printSync produced output that is not valid UTF-8; a text fix cannot hold it without ' +
|
|
784
|
+
'lossy decoding'), { code: 'ESLINT_SH_PRINT_ENCODING' });
|
|
718
785
|
}
|
|
719
786
|
if (rootType === 'File') {
|
|
720
787
|
return { range: [0, this.text.length], text: printed };
|
|
@@ -736,8 +803,8 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
736
803
|
#originalSyntaxFor(node) {
|
|
737
804
|
const syntax = this.getSyntax(node);
|
|
738
805
|
if (syntax === undefined) {
|
|
739
|
-
throw new TypeError('expected a view node parsed from this file; auxiliary views, view nodes of other ' +
|
|
740
|
-
'files and objects that did not come from the parser have no original syntax');
|
|
806
|
+
throw Object.assign(new TypeError('expected a view node parsed from this file; auxiliary views, view nodes of other ' +
|
|
807
|
+
'files and objects that did not come from the parser have no original syntax'), { code: 'ESLINT_SH_FOREIGN_VIEW_NODE' });
|
|
741
808
|
}
|
|
742
809
|
return syntax;
|
|
743
810
|
}
|
|
@@ -755,12 +822,12 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
755
822
|
*
|
|
756
823
|
* @param pos - A `SyntaxPos` from one of this file's original records.
|
|
757
824
|
* @returns The UTF-16 index of `pos` in this file's text.
|
|
758
|
-
* @throws RangeError when `pos` is invalid (`IsValid === false`), recovered
|
|
825
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid (`IsValid === false`), recovered
|
|
759
826
|
* (`IsRecovered === true`), or overflowed (`OffsetOverflow === true`), or
|
|
760
827
|
* when its offset is not a UTF-8 character boundary of this source. Such a
|
|
761
828
|
* position is never rounded to a nearby boundary.
|
|
762
|
-
* @throws TypeError when `pos` is not a `SyntaxPos`, or when this source
|
|
763
|
-
* code's tree was not built by this language's parser.
|
|
829
|
+
* @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
|
|
830
|
+
* code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
|
|
764
831
|
*/
|
|
765
832
|
getIndexFromSyntaxPos(pos) {
|
|
766
833
|
return this.#coordinateAt(pos).index;
|
|
@@ -773,10 +840,10 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
773
840
|
*
|
|
774
841
|
* @param pos - A `SyntaxPos` from one of this file's original records.
|
|
775
842
|
* @returns The one-based line and UTF-16 column of `pos`.
|
|
776
|
-
* @throws RangeError when `pos` is invalid, recovered, or overflowed, or
|
|
843
|
+
* @throws RangeError with `ESLINT_SH_SOURCE_RANGE` when `pos` is invalid, recovered, or overflowed, or
|
|
777
844
|
* when its offset is not a UTF-8 character boundary of this source.
|
|
778
|
-
* @throws TypeError when `pos` is not a `SyntaxPos`, or when this source
|
|
779
|
-
* code's tree was not built by this language's parser.
|
|
845
|
+
* @throws TypeError with `ESLINT_SH_SYNTAX_POSITION` when `pos` is not a `SyntaxPos`, or when this source
|
|
846
|
+
* code's tree was not built by this language's parser (`ESLINT_SH_FILE_NODE`).
|
|
780
847
|
*/
|
|
781
848
|
getLocFromSyntaxPos(pos) {
|
|
782
849
|
const { line, column } = this.#coordinateAt(pos);
|
|
@@ -790,7 +857,7 @@ export class ShellSourceCode extends TextSourceCodeBase {
|
|
|
790
857
|
#coordinateAt(pos) {
|
|
791
858
|
const coordinates = projectedCoordinates(this.ast);
|
|
792
859
|
if (coordinates === undefined) {
|
|
793
|
-
throw new TypeError('expected a parsed shell File from this language adapter');
|
|
860
|
+
throw Object.assign(new TypeError('expected a parsed shell File from this language adapter'), { code: 'ESLINT_SH_FILE_NODE' });
|
|
794
861
|
}
|
|
795
862
|
return coordinates.fromByteOffset(exactByteOffset(pos));
|
|
796
863
|
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* count bytes; this adapter derives UTF-16 indices and columns without replacing or
|
|
4
4
|
* mutating the raw syntax position. Display widths, graphemes, and tab expansion
|
|
5
5
|
* are deliberately outside this contract.
|
|
6
|
+
*
|
|
7
|
+
* ESLINT_SH_SOURCE_RANGE rejects an inexact or out-of-source boundary instead of inventing a location or edit range.
|
|
6
8
|
*/
|
|
7
9
|
/** A source boundary expressed in JavaScript indexing and ESLint's one-based location convention. @internal */
|
|
8
10
|
export interface ISourceCoordinate {
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* count bytes; this adapter derives UTF-16 indices and columns without replacing or
|
|
4
4
|
* mutating the raw syntax position. Display widths, graphemes, and tab expansion
|
|
5
5
|
* are deliberately outside this contract.
|
|
6
|
+
*
|
|
7
|
+
* ESLINT_SH_SOURCE_RANGE rejects an inexact or out-of-source boundary instead of inventing a location or edit range.
|
|
6
8
|
*/
|
|
7
9
|
/**
|
|
8
10
|
* Sentinel in the byte table for an offset that falls inside a multi-byte
|
|
@@ -69,14 +71,16 @@ export class SourceCoordinates {
|
|
|
69
71
|
? this.#byteIndices[offset]
|
|
70
72
|
: INTERIOR_BYTE;
|
|
71
73
|
if (index === INTERIOR_BYTE) {
|
|
72
|
-
throw new RangeError(`byte offset ${String(offset)} is not a boundary in this source`);
|
|
74
|
+
throw Object.assign(new RangeError(`byte offset ${String(offset)} is not a boundary in this source`), { code: 'ESLINT_SH_SOURCE_RANGE' });
|
|
73
75
|
}
|
|
74
76
|
return this.atIndex(index);
|
|
75
77
|
}
|
|
76
78
|
/** Derive a one-based location from a known JavaScript source index. @internal */
|
|
77
79
|
atIndex(index) {
|
|
78
80
|
if (!Number.isInteger(index) || index < 0 || index > this.#length) {
|
|
79
|
-
throw new RangeError(`UTF-16 index ${String(index)} is outside this source`)
|
|
81
|
+
throw Object.assign(new RangeError(`UTF-16 index ${String(index)} is outside this source`), {
|
|
82
|
+
code: 'ESLINT_SH_SOURCE_RANGE',
|
|
83
|
+
});
|
|
80
84
|
}
|
|
81
85
|
let low = 0;
|
|
82
86
|
let high = this.#lineStarts.length;
|
|
@@ -100,12 +104,12 @@ export class SourceCoordinates {
|
|
|
100
104
|
*/
|
|
101
105
|
indexAt(line, column) {
|
|
102
106
|
if (!Number.isInteger(line) || line < 1 || line > this.#lineStarts.length) {
|
|
103
|
-
throw new RangeError(`line ${String(line)} is outside this source (lines 1-${String(this.#lineStarts.length)})`);
|
|
107
|
+
throw Object.assign(new RangeError(`line ${String(line)} is outside this source (lines 1-${String(this.#lineStarts.length)})`), { code: 'ESLINT_SH_SOURCE_RANGE' });
|
|
104
108
|
}
|
|
105
109
|
const start = this.#lineStarts[line - 1];
|
|
106
110
|
const last = line === this.#lineStarts.length ? this.#length : this.#lineStarts[line] - 1;
|
|
107
111
|
if (!Number.isInteger(column) || column < 1 || start + column - 1 > last) {
|
|
108
|
-
throw new RangeError(`column ${String(column)} is outside line ${String(line)} (columns 1-${String(last - start + 1)})`);
|
|
112
|
+
throw Object.assign(new RangeError(`column ${String(column)} is outside line ${String(line)} (columns 1-${String(last - start + 1)})`), { code: 'ESLINT_SH_SOURCE_RANGE' });
|
|
109
113
|
}
|
|
110
114
|
return start + column - 1;
|
|
111
115
|
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* are consumer conventions; the original syntax remains untouched and associated
|
|
5
5
|
* by identity. Bounds are observations of the original parse, tied to this exact
|
|
6
6
|
* source. This is neither upstream Walk nor a replacement syntax model.
|
|
7
|
+
*
|
|
8
|
+
* ESLINT_SH_SYNTAX_VIEW identifies a record/snapshot invariant that prevents a faithful lint view; it never denotes invalid shell grammar.
|
|
7
9
|
*/
|
|
8
10
|
import { SYNTAX_INTERFACES, SYNTAX_SCHEMA } from 'sh-ast';
|
|
9
11
|
import { SourceCoordinates } from './source-coordinates.js';
|
|
@@ -122,7 +124,9 @@ function sourceText(value) {
|
|
|
122
124
|
if (value instanceof Uint8Array) {
|
|
123
125
|
return textDecoder.decode(value);
|
|
124
126
|
}
|
|
125
|
-
throw new TypeError('shell text view expected a Go string')
|
|
127
|
+
throw Object.assign(new TypeError('shell text view expected a Go string'), {
|
|
128
|
+
code: 'ESLINT_SH_SYNTAX_VIEW',
|
|
129
|
+
});
|
|
126
130
|
}
|
|
127
131
|
/**
|
|
128
132
|
* Parser nodes whose view span was shortened by {@link endsBeforeCrlfNewline}.
|
|
@@ -177,7 +181,9 @@ export function withoutCrlfCarriageReturn(word, resolution) {
|
|
|
177
181
|
*/
|
|
178
182
|
export function adaptSyntaxFile(file, source, positions) {
|
|
179
183
|
if (!isRecord(positions) || typeof positions.get !== 'function') {
|
|
180
|
-
throw new TypeError('shell view requires a source position snapshot')
|
|
184
|
+
throw Object.assign(new TypeError('shell view requires a source position snapshot'), {
|
|
185
|
+
code: 'ESLINT_SH_SYNTAX_VIEW',
|
|
186
|
+
});
|
|
181
187
|
}
|
|
182
188
|
const coordinates = new SourceCoordinates(source);
|
|
183
189
|
const views = new WeakMap();
|
|
@@ -189,11 +195,15 @@ export function adaptSyntaxFile(file, source, positions) {
|
|
|
189
195
|
/** Each projected record owns its derived fields, while real syntax nodes retain their original identity. */
|
|
190
196
|
const project = (raw, fallback) => {
|
|
191
197
|
if (!isRecord(raw) || typeof raw.Type !== 'string') {
|
|
192
|
-
throw new TypeError('shell view expected a known upstream syntax record')
|
|
198
|
+
throw Object.assign(new TypeError('shell view expected a known upstream syntax record'), {
|
|
199
|
+
code: 'ESLINT_SH_SYNTAX_VIEW',
|
|
200
|
+
});
|
|
193
201
|
}
|
|
194
202
|
const plan = projectionPlans.get(raw.Type);
|
|
195
203
|
if (plan === undefined) {
|
|
196
|
-
throw new TypeError('shell view expected a known upstream syntax record')
|
|
204
|
+
throw Object.assign(new TypeError('shell view expected a known upstream syntax record'), {
|
|
205
|
+
code: 'ESLINT_SH_SYNTAX_VIEW',
|
|
206
|
+
});
|
|
197
207
|
}
|
|
198
208
|
const realNode = isSyntaxNode(raw);
|
|
199
209
|
// eslint-disable-next-line @api-extractor-tools/forgotten-export -- This span belongs only to the private projection closure, not the exported signature.
|
|
@@ -203,7 +213,7 @@ export function adaptSyntaxFile(file, source, positions) {
|
|
|
203
213
|
if (realNode) {
|
|
204
214
|
const observed = positions.get(raw);
|
|
205
215
|
if (observed === undefined) {
|
|
206
|
-
throw new TypeError(`shell position snapshot has no observation for ${raw.Type}`);
|
|
216
|
+
throw Object.assign(new TypeError(`shell position snapshot has no observation for ${raw.Type}`), { code: 'ESLINT_SH_SYNTAX_VIEW' });
|
|
207
217
|
}
|
|
208
218
|
span = {
|
|
209
219
|
start: position(observed.Pos, fallback.start),
|
|
@@ -235,7 +245,7 @@ export function adaptSyntaxFile(file, source, positions) {
|
|
|
235
245
|
if (field.slice) {
|
|
236
246
|
const items = value === null ? [] : value;
|
|
237
247
|
if (!Array.isArray(items)) {
|
|
238
|
-
throw new TypeError(`shell view expected ${raw.Type}.${field.name} to be a slice`);
|
|
248
|
+
throw Object.assign(new TypeError(`shell view expected ${raw.Type}.${field.name} to be a slice`), { code: 'ESLINT_SH_SYNTAX_VIEW' });
|
|
239
249
|
}
|
|
240
250
|
const projected = [];
|
|
241
251
|
for (const item of items) {
|
|
@@ -278,7 +288,9 @@ export function adaptSyntaxFile(file, source, positions) {
|
|
|
278
288
|
};
|
|
279
289
|
const root = project(file, wholeSource);
|
|
280
290
|
if (!isShellFile(root)) {
|
|
281
|
-
throw new TypeError('shell view expected a File with statements')
|
|
291
|
+
throw Object.assign(new TypeError('shell view expected a File with statements'), {
|
|
292
|
+
code: 'ESLINT_SH_SYNTAX_VIEW',
|
|
293
|
+
});
|
|
282
294
|
}
|
|
283
295
|
projectedViews.set(root, views);
|
|
284
296
|
projectedCommentsByRoot.set(root, comments);
|
|
@@ -7,6 +7,7 @@ import type { ShellNodeOf } from './syntax-view.js';
|
|
|
7
7
|
* are rejected instead of being treated as known or unknown shell values.
|
|
8
8
|
* A static word that ends a line of a CRLF file resolves without the line
|
|
9
9
|
* terminator's carriage return, as it would on LF input.
|
|
10
|
-
* @
|
|
10
|
+
* @throws TypeError with `ESLINT_SH_WORD_NODE` for a word without original syntax.
|
|
11
|
+
* @internal
|
|
11
12
|
*/
|
|
12
13
|
export declare function resolveWord(word: ShellNodeOf<'Word'>, options?: ResolveWordOptions): WordResolution;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Bridges lint-word identity to faithful syntax for source-code methods.
|
|
3
|
+
* ESLINT_SH_WORD_NODE rejects a missing source association; dynamic words
|
|
4
|
+
* remain ordinary analysis results rather than errors.
|
|
5
|
+
*/
|
|
2
6
|
import { resolveWord as resolveSyntaxWord } from 'sh-ast/analyze';
|
|
3
7
|
import { syntaxForNode, withoutCrlfCarriageReturn } from './syntax-view.js';
|
|
4
8
|
/**
|
|
@@ -8,12 +12,13 @@ import { syntaxForNode, withoutCrlfCarriageReturn } from './syntax-view.js';
|
|
|
8
12
|
* are rejected instead of being treated as known or unknown shell values.
|
|
9
13
|
* A static word that ends a line of a CRLF file resolves without the line
|
|
10
14
|
* terminator's carriage return, as it would on LF input.
|
|
11
|
-
* @
|
|
15
|
+
* @throws TypeError with `ESLINT_SH_WORD_NODE` for a word without original syntax.
|
|
16
|
+
* @internal
|
|
12
17
|
*/
|
|
13
18
|
export function resolveWord(word, options) {
|
|
14
19
|
const syntax = syntaxForNode(word);
|
|
15
20
|
if (syntax?.Type !== 'Word') {
|
|
16
|
-
throw new TypeError('resolveWord expects a parsed shell Word from this language adapter');
|
|
21
|
+
throw Object.assign(new TypeError('resolveWord expects a parsed shell Word from this language adapter'), { code: 'ESLINT_SH_WORD_NODE' });
|
|
17
22
|
}
|
|
18
23
|
return withoutCrlfCarriageReturn(syntax, resolveSyntaxWord(syntax, options));
|
|
19
24
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The common Bash 3.2+ intrinsic numeric profile used by shell rules. Value
|
|
3
|
+
* shape and assignment behavior are separate properties: a variable that
|
|
4
|
+
* always yields an integer need not evaluate assigned text arithmetically.
|
|
5
|
+
* Writable intrinsic setters still differ from ordinary string bindings;
|
|
6
|
+
* their handling can vary between Bash versions.
|
|
7
|
+
*
|
|
8
|
+
* This is a name profile, not dataflow over unset, local, or declaration
|
|
9
|
+
* attributes. Callers decide when intrinsic meaning applies. POSIX and other
|
|
10
|
+
* shell dialects do not inherit this Bash profile, and newer Bash-only names
|
|
11
|
+
* are excluded from the common minimum-version guarantee.
|
|
12
|
+
*/
|
|
13
|
+
/** A name whose intrinsic value is numeric throughout the common Bash profile. @internal */
|
|
14
|
+
export declare function isBashIntegerVariable(name: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* A name with a non-ordinary writable integer setter. OPTIND can evaluate
|
|
17
|
+
* assigned text as arithmetic; numeric output alone makes no such promise
|
|
18
|
+
* about the other setters. Proofs that do not model these setters must fence
|
|
19
|
+
* their writes rather than treat them as ordinary string assignments.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare function hasSpecialBashIntegerSetter(name: string): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The common Bash 3.2+ intrinsic numeric profile used by shell rules. Value
|
|
3
|
+
* shape and assignment behavior are separate properties: a variable that
|
|
4
|
+
* always yields an integer need not evaluate assigned text arithmetically.
|
|
5
|
+
* Writable intrinsic setters still differ from ordinary string bindings;
|
|
6
|
+
* their handling can vary between Bash versions.
|
|
7
|
+
*
|
|
8
|
+
* This is a name profile, not dataflow over unset, local, or declaration
|
|
9
|
+
* attributes. Callers decide when intrinsic meaning applies. POSIX and other
|
|
10
|
+
* shell dialects do not inherit this Bash profile, and newer Bash-only names
|
|
11
|
+
* are excluded from the common minimum-version guarantee.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Every listed intrinsic yields a decimal integer. Writable setters control
|
|
15
|
+
* the random generator, elapsed clock, or option parser; the other bindings
|
|
16
|
+
* ignore assignments or reject them. Environment-controlled names such as
|
|
17
|
+
* UID/EUID/COLUMNS, and later additions such as BASHPID/SRANDOM, are outside
|
|
18
|
+
* this common profile.
|
|
19
|
+
*/
|
|
20
|
+
const INTEGER_BINDINGS = new Map([
|
|
21
|
+
['RANDOM', 'writable'],
|
|
22
|
+
['SECONDS', 'writable'],
|
|
23
|
+
['OPTIND', 'writable'],
|
|
24
|
+
['LINENO', 'ignored'],
|
|
25
|
+
['BASH_SUBSHELL', 'ignored'],
|
|
26
|
+
['PPID', 'readonly'],
|
|
27
|
+
]);
|
|
28
|
+
/** A name whose intrinsic value is numeric throughout the common Bash profile. @internal */
|
|
29
|
+
export function isBashIntegerVariable(name) {
|
|
30
|
+
return INTEGER_BINDINGS.has(name);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A name with a non-ordinary writable integer setter. OPTIND can evaluate
|
|
34
|
+
* assigned text as arithmetic; numeric output alone makes no such promise
|
|
35
|
+
* about the other setters. Proofs that do not model these setters must fence
|
|
36
|
+
* their writes rather than treat them as ordinary string assignments.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export function hasSpecialBashIntegerSetter(name) {
|
|
40
|
+
return INTEGER_BINDINGS.get(name) === 'writable';
|
|
41
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* A compat rule reports one gated feature (a row of the gate table in
|
|
5
5
|
* `./version-gates.ts`) wherever a file uses it while its `languageOptions`
|
|
6
6
|
* say the feature is unavailable. The factory owns the gate decision, so no
|
|
7
|
-
* compat rule reads `
|
|
7
|
+
* compat rule reads `minBashVersion` or `dialect` itself:
|
|
8
8
|
*
|
|
9
9
|
* - when {@link isFeatureAvailable} says the feature is available, the rule
|
|
10
10
|
* returns no listeners at all, so it costs nothing and cannot report;
|