@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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* POSIX `sh` rather than for Bash.
|
|
4
4
|
*
|
|
5
5
|
* It sets `languageOptions.dialect: 'posix'`, which makes every Bash-only
|
|
6
|
-
* feature unavailable at any `
|
|
6
|
+
* feature unavailable at any `minBashVersion`, and enables the `compat/*` rules
|
|
7
7
|
* that report those features. The dialect is also what every dialect-aware
|
|
8
8
|
* rule reads, so the preset is one switch rather than a list of settings that
|
|
9
9
|
* could drift apart.
|
|
@@ -14,18 +14,14 @@
|
|
|
14
14
|
* shellcheck, which is why it does not promise "any POSIX `sh`". The scope and
|
|
15
15
|
* the shell behaviour behind it are stated for users in `docs/compat.md`.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* `recommended
|
|
21
|
-
*
|
|
22
|
-
* ash reject. A pack that asked for `pipefail` would make its own autofix
|
|
23
|
-
* break a working `#!/bin/sh` script.
|
|
17
|
+
* Target presets carry only target facts and findings that depend on them.
|
|
18
|
+
* The shebang check belongs here because it verifies the declared interpreter
|
|
19
|
+
* against the configured target. Error-handling policy belongs to recommended:
|
|
20
|
+
* `extends: [sh.configs.recommended, sh.configs['posix-portable']]` requires
|
|
21
|
+
* the dialect-aware POSIX default, `set -eu`.
|
|
24
22
|
*
|
|
25
23
|
* It follows the shape contract in `./recommended.ts`, extended with
|
|
26
|
-
* `languageOptions`
|
|
27
|
-
* through `extends: [sh.configs.recommended, sh.configs['posix-portable']]`;
|
|
28
|
-
* the later entry's `require-strict-mode` options win.
|
|
24
|
+
* `languageOptions` because the target is the preset's meaning.
|
|
29
25
|
*
|
|
30
26
|
* Rule membership follows the **Configs** column of the rule catalog (rows
|
|
31
27
|
* marked `P`), which a test checks against this module.
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The rules `sh/posix-portable` enables, all at `error`, keyed as a user
|
|
3
|
-
* writes them (`sh/<rule-name>`):
|
|
4
|
-
* `dialect: 'posix'
|
|
5
|
-
* `bash-3.2` has no use for, the shebang/dialect check
|
|
6
|
-
* POSIX
|
|
3
|
+
* writes them (`sh/<rule-name>`): the effective `compat/*` rules under
|
|
4
|
+
* `dialect: 'posix'`, including the POSIX-only gates
|
|
5
|
+
* `bash-3.2` has no use for, and the shebang/dialect check. The empty-array
|
|
6
|
+
* nounset rule is omitted because it checks Bash targets and cannot report under POSIX.
|
|
7
7
|
*
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
const posixPortableRules = {
|
|
11
|
-
'sh/require-strict-mode': ['error', { mode: 'set -eu' }],
|
|
12
11
|
'sh/shebang-matches-dialect': 'error',
|
|
13
12
|
'sh/compat/no-append-all-redirect': 'error',
|
|
14
13
|
'sh/compat/no-associative-arrays': 'error',
|
|
@@ -27,7 +26,6 @@ const posixPortableRules = {
|
|
|
27
26
|
'sh/compat/no-mapfile': 'error',
|
|
28
27
|
'sh/compat/no-nameref': 'error',
|
|
29
28
|
'sh/compat/no-negative-array-index': 'error',
|
|
30
|
-
'sh/compat/no-nounset-empty-array': 'error',
|
|
31
29
|
'sh/compat/no-parameter-transformation': 'error',
|
|
32
30
|
'sh/compat/no-pipe-all': 'error',
|
|
33
31
|
'sh/compat/no-printf-time-format': 'error',
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human diagnostics for project-owned configuration boundaries. Codes belong to
|
|
3
|
+
* the rejecting boundary; this module only keeps paths and received values
|
|
4
|
+
* consistent, without constructing errors or coupling runtime packages.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Render a rejected value using the project's short JSON-first convention.
|
|
8
|
+
* Non-JSON values must not replace the intended configuration failure with a
|
|
9
|
+
* serialization exception. The rendering is diagnostic text, never stored state.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function describeConfigurationValue(value: unknown): string;
|
|
13
|
+
/** The user's path identifies the binding; prose may evolve independently of the error code. @internal */
|
|
14
|
+
export declare function configurationMessage(where: string, detail: string, value: unknown): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Generated from shared/configuration-message.ts; edit the canonical source.
|
|
2
|
+
/**
|
|
3
|
+
* Human diagnostics for project-owned configuration boundaries. Codes belong to
|
|
4
|
+
* the rejecting boundary; this module only keeps paths and received values
|
|
5
|
+
* consistent, without constructing errors or coupling runtime packages.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Render a rejected value using the project's short JSON-first convention.
|
|
9
|
+
* Non-JSON values must not replace the intended configuration failure with a
|
|
10
|
+
* serialization exception. The rendering is diagnostic text, never stored state.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function describeConfigurationValue(value) {
|
|
14
|
+
// JSON turns nonfinite numbers into null, which would identify a different rejected value.
|
|
15
|
+
if (typeof value === 'number' && !Number.isFinite(value)) {
|
|
16
|
+
return String(value);
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === 'bigint') {
|
|
19
|
+
return `${String(value)}n`;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
// JSON.stringify also returns undefined for functions, symbols and undefined.
|
|
23
|
+
const rendered = JSON.stringify(value);
|
|
24
|
+
return rendered ?? String(value);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return String(value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The user's path identifies the binding; prose may evolve independently of the error code. @internal */
|
|
31
|
+
export function configurationMessage(where, detail, value) {
|
|
32
|
+
return `${where}: ${detail}; received ${describeConfigurationValue(value)}.`;
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { SettingsConfig } from '@eslint/core';
|
|
2
|
+
import type { ShellSourceCode } from '../language/shell-source-code.js';
|
|
3
|
+
import type { DeclaredCommand, LintedFile } from './declaration-convention.js';
|
|
4
|
+
/**
|
|
5
|
+
* The only view of the linted file a convention's hooks receive: `filename`,
|
|
6
|
+
* `physicalFilename` and `cwd`, frozen. A rule's `context` must never reach a
|
|
7
|
+
* hook, because it would let a convention report, read options or reach other
|
|
8
|
+
* rule state.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function toLintedFile(context: LintedFile): LintedFile;
|
|
13
|
+
/**
|
|
14
|
+
* Returns validated declarations for the linted file, or `null` when the project
|
|
15
|
+
* has no bound convention. An empty array means a convention is bound and the
|
|
16
|
+
* file declares no commands; consumers must preserve that distinction.
|
|
17
|
+
*
|
|
18
|
+
* The convention receives only a frozen {@link LintedFile}, never rule state.
|
|
19
|
+
* Invalid bindings, output arrays, declaration kinds, provenance or UTF-16 ranges
|
|
20
|
+
* throw an error naming the shared setting before a rule can trust the result.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* File() {
|
|
25
|
+
* const declarations = getDeclaredCommands(context);
|
|
26
|
+
* if (declarations === null) return;
|
|
27
|
+
* for (const declared of declarations) {
|
|
28
|
+
* // Each declaration has been checked against its kind's contract.
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @throws Error with `ESLINT_SH_DECLARATION_CONVENTION` for invalid shared bindings, or
|
|
34
|
+
* `ESLINT_SH_DECLARATION_OUTPUT` for invalid hook results.
|
|
35
|
+
* Exceptions thrown by the convention itself pass through unchanged, including their causes.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export declare function getDeclaredCommands(context: LintedFile & {
|
|
39
|
+
readonly sourceCode: ShellSourceCode;
|
|
40
|
+
readonly settings: SettingsConfig;
|
|
41
|
+
}): DeclaredCommand[] | null;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The one path by which a rule reads a bound convention's declarations for
|
|
3
|
+
* the file it is linting. The built-in consumers (`sh/no-undeclared-commands`,
|
|
4
|
+
* `sh/no-unused-declarations`) and a pack's own rules all call
|
|
5
|
+
* {@link getDeclaredCommands}, so they hand the convention the same
|
|
6
|
+
* {@link LintedFile} and trust only declarations that passed the same checks.
|
|
7
|
+
*
|
|
8
|
+
* The checks exist because a declaration's kind decides where a report goes
|
|
9
|
+
* and whether a fix is offered. A declaration of an unknown kind, one missing
|
|
10
|
+
* its kind's fields, or a script range outside the text would otherwise be
|
|
11
|
+
* reported at a made-up location, crash deep inside a rule, or be silently
|
|
12
|
+
* accepted by a rule that only reads names. Failing with the declaration and
|
|
13
|
+
* the setting in the message makes the convention's bug the thing the user
|
|
14
|
+
* sees.
|
|
15
|
+
*
|
|
16
|
+
* ESLINT_SH_DECLARATION_OUTPUT identifies invalid extension results. Exceptions thrown by convention hooks belong to the extension and propagate unchanged.
|
|
5
17
|
*/
|
|
18
|
+
import { configurationMessage, describeConfigurationValue } from '../configuration-message.js';
|
|
19
|
+
import { resolveDeclarationConvention } from '../rules/resolve-declaration-convention.js';
|
|
20
|
+
/** Validation errors identify the same shared policy that supplied the declarations. */
|
|
6
21
|
const BINDING = 'settings.sh.declarationConvention';
|
|
7
22
|
/**
|
|
8
23
|
* The only view of the linted file a convention's hooks receive: `filename`,
|
|
@@ -64,64 +79,49 @@ function invalidReason(value, textLength) {
|
|
|
64
79
|
case undefined:
|
|
65
80
|
return "`kind` is missing: it must be 'script', 'file' or 'described'";
|
|
66
81
|
default:
|
|
67
|
-
return `\`kind\` must be 'script', 'file' or 'described', not ${
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/** A short rendering of a value for an error message. */
|
|
71
|
-
function describe(value) {
|
|
72
|
-
try {
|
|
73
|
-
// `JSON.stringify` returns `undefined` for a function or `undefined`.
|
|
74
|
-
const text = JSON.stringify(value);
|
|
75
|
-
return text ?? String(value);
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
return String(value);
|
|
82
|
+
return `\`kind\` must be 'script', 'file' or 'described', not ${describeConfigurationValue(declared.kind)}`;
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
/**
|
|
82
|
-
* Returns
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* the rule's own `context`.
|
|
86
|
-
*
|
|
87
|
-
* The convention receives a frozen {@link LintedFile} holding only
|
|
88
|
-
* `filename`, `physicalFilename` and `cwd`, never the whole context, so it
|
|
89
|
-
* sees which file it is reading and nothing it could report through.
|
|
86
|
+
* Returns validated declarations for the linted file, or `null` when the project
|
|
87
|
+
* has no bound convention. An empty array means a convention is bound and the
|
|
88
|
+
* file declares no commands; consumers must preserve that distinction.
|
|
90
89
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* a missing or unknown `kind`, without its kind's fields, or with a `range`
|
|
95
|
-
* outside the linted text.
|
|
90
|
+
* The convention receives only a frozen {@link LintedFile}, never rule state.
|
|
91
|
+
* Invalid bindings, output arrays, declaration kinds, provenance or UTF-16 ranges
|
|
92
|
+
* throw an error naming the shared setting before a rule can trust the result.
|
|
96
93
|
*
|
|
97
94
|
* @example
|
|
98
95
|
* ```ts
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* return
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* }
|
|
107
|
-
* }
|
|
108
|
-
* },
|
|
109
|
-
* };
|
|
96
|
+
* File() {
|
|
97
|
+
* const declarations = getDeclaredCommands(context);
|
|
98
|
+
* if (declarations === null) return;
|
|
99
|
+
* for (const declared of declarations) {
|
|
100
|
+
* // Each declaration has been checked against its kind's contract.
|
|
101
|
+
* }
|
|
102
|
+
* }
|
|
110
103
|
* ```
|
|
111
104
|
*
|
|
105
|
+
* @throws Error with `ESLINT_SH_DECLARATION_CONVENTION` for invalid shared bindings, or
|
|
106
|
+
* `ESLINT_SH_DECLARATION_OUTPUT` for invalid hook results.
|
|
107
|
+
* Exceptions thrown by the convention itself pass through unchanged, including their causes.
|
|
112
108
|
* @public
|
|
113
109
|
*/
|
|
114
|
-
export function
|
|
110
|
+
export function getDeclaredCommands(context) {
|
|
111
|
+
const convention = resolveDeclarationConvention(context);
|
|
112
|
+
if (convention === null) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
115
|
const { sourceCode } = context;
|
|
116
116
|
const file = toLintedFile(context);
|
|
117
117
|
const declarations = convention.declaredCommands(sourceCode, file);
|
|
118
118
|
if (!Array.isArray(declarations)) {
|
|
119
|
-
throw new Error(
|
|
119
|
+
throw Object.assign(new Error(configurationMessage(`${BINDING}.declaredCommands`, 'must return an array', declarations)), { code: 'ESLINT_SH_DECLARATION_OUTPUT' });
|
|
120
120
|
}
|
|
121
|
-
for (const declared of declarations) {
|
|
121
|
+
for (const [index, declared] of declarations.entries()) {
|
|
122
122
|
const reason = invalidReason(declared, sourceCode.text.length);
|
|
123
123
|
if (reason !== null) {
|
|
124
|
-
throw new Error(
|
|
124
|
+
throw Object.assign(new Error(configurationMessage(`${BINDING}.declaredCommands[${String(index)}]`, `returned an invalid declaration: ${reason}`, declared)), { code: 'ESLINT_SH_DECLARATION_OUTPUT' });
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
return declarations;
|