@eslint-sh/eslint-plugin 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -40
- package/dist/api.d.ts +92 -0
- package/dist/api.js +83 -0
- package/dist/command-harvest/builtins/bash.d.ts +1 -1
- package/dist/command-harvest/builtins/bash.js +1 -1
- package/dist/command-harvest/builtins/bats.d.ts +2 -0
- package/dist/command-harvest/builtins/bats.js +3 -0
- package/dist/command-harvest/harvest-commands.d.ts +2 -2
- package/dist/command-harvest/harvest-commands.js +2 -2
- package/dist/command-harvest/wrapper-table.d.ts +3 -19
- package/dist/command-harvest/wrapper-table.js +8 -38
- package/dist/configs/bash-3-2.d.ts +7 -6
- package/dist/configs/bash-3-2.js +4 -3
- package/dist/configs/posix-portable.d.ts +7 -11
- package/dist/configs/posix-portable.js +4 -6
- package/dist/configuration-message.d.ts +14 -0
- package/dist/configuration-message.js +33 -0
- package/dist/declaration-conventions/get-declared-commands.d.ts +41 -0
- package/dist/declaration-conventions/{read-declared-commands.js → get-declared-commands.js} +43 -43
- package/dist/eslint-plugin-api.d.ts +1506 -0
- package/dist/eslint-plugin-syntax-analyze.d.ts +3 -3
- package/dist/eslint-plugin-syntax.d.ts +7 -4
- package/dist/eslint-plugin.d.ts +16 -1514
- package/dist/index.d.ts +14 -78
- package/dist/index.js +22 -74
- package/dist/language/command-resolution.d.ts +5 -5
- package/dist/language/command-resolution.js +11 -7
- package/dist/language/selector-classes.d.ts +7 -3
- package/dist/language/selector-classes.js +13 -4
- package/dist/language/shell-language-options.d.ts +21 -18
- package/dist/language/shell-language-options.js +41 -39
- package/dist/language/shell-language.d.ts +13 -10
- package/dist/language/shell-language.js +23 -45
- package/dist/language/shell-source-code.d.ts +74 -49
- package/dist/language/shell-source-code.js +135 -68
- package/dist/language/source-coordinates.d.ts +2 -0
- package/dist/language/source-coordinates.js +8 -4
- package/dist/language/syntax-view.js +19 -7
- package/dist/language/word-resolution.d.ts +2 -1
- package/dist/language/word-resolution.js +8 -3
- package/dist/rules/bash-variable-semantics.d.ts +22 -0
- package/dist/rules/bash-variable-semantics.js +41 -0
- package/dist/rules/compat/create-compat-rule.js +1 -1
- package/dist/rules/compat/declaration-options.d.ts +2 -2
- package/dist/rules/compat/declaration-options.js +5 -2
- package/dist/rules/compat/no-append-all-redirect.js +1 -1
- package/dist/rules/compat/no-associative-arrays.js +2 -2
- package/dist/rules/compat/no-brace-sequence-padding-step.js +4 -4
- package/dist/rules/compat/no-case-attributes.js +3 -3
- package/dist/rules/compat/no-case-fallthrough.js +2 -2
- package/dist/rules/compat/no-case-modification.js +2 -2
- package/dist/rules/compat/no-coproc.js +1 -1
- package/dist/rules/compat/no-declare-g.js +3 -3
- package/dist/rules/compat/no-double-bracket.js +2 -2
- package/dist/rules/compat/no-epoch-variables.js +2 -2
- package/dist/rules/compat/no-fd-variable.js +1 -1
- package/dist/rules/compat/no-globstar.js +1 -1
- package/dist/rules/compat/no-lastpipe-semantics.js +2 -2
- package/dist/rules/compat/no-let.js +2 -1
- package/dist/rules/compat/no-mapfile.js +4 -2
- package/dist/rules/compat/no-nameref.js +3 -3
- package/dist/rules/compat/no-negative-array-index.js +39 -9
- package/dist/rules/compat/no-nounset-empty-array.js +15 -4
- package/dist/rules/compat/no-parameter-transformation.js +2 -2
- package/dist/rules/compat/no-pipe-all.js +1 -1
- package/dist/rules/compat/no-printf-time-format.js +4 -2
- package/dist/rules/compat/no-source.js +2 -1
- package/dist/rules/compat/no-test-v.js +4 -2
- package/dist/rules/compat/no-unicode-escape.js +2 -2
- package/dist/rules/compat/no-wait-n.js +4 -2
- package/dist/rules/compat/nounset-array-proof.d.ts +8 -0
- package/dist/rules/compat/nounset-array-proof.js +563 -0
- package/dist/rules/compat/posix-absent-command.d.ts +7 -8
- package/dist/rules/compat/posix-absent-command.js +17 -15
- package/dist/rules/compat/shopt-options.js +3 -1
- package/dist/rules/compat/version-gates.d.ts +9 -9
- package/dist/rules/compat/version-gates.js +13 -13
- package/dist/rules/create-wrapper-rule.d.ts +1 -1
- package/dist/rules/create-wrapper-rule.js +23 -16
- package/dist/rules/define-shell-rule.js +1 -1
- package/dist/rules/no-dynamic-invocation.d.ts +0 -8
- package/dist/rules/no-dynamic-invocation.js +7 -15
- package/dist/rules/no-eval.js +3 -1
- package/dist/rules/no-masked-exit-status.d.ts +4 -3
- package/dist/rules/no-masked-exit-status.js +18 -10
- package/dist/rules/no-secret-env-reads.d.ts +6 -3
- package/dist/rules/no-secret-env-reads.js +49 -15
- package/dist/rules/no-secret-flags.d.ts +4 -1
- package/dist/rules/no-secret-flags.js +21 -11
- package/dist/rules/no-unchecked-cd.js +6 -3
- package/dist/rules/no-undeclared-commands.d.ts +1 -15
- package/dist/rules/no-undeclared-commands.js +11 -18
- package/dist/rules/no-unused-declarations.d.ts +1 -18
- package/dist/rules/no-unused-declarations.js +15 -36
- package/dist/rules/prefer-local.d.ts +3 -2
- package/dist/rules/prefer-local.js +7 -4
- package/dist/rules/quote-expansions.js +3 -28
- package/dist/rules/require-network-wrapper.d.ts +3 -18
- package/dist/rules/require-network-wrapper.js +43 -10
- package/dist/rules/require-strict-mode.d.ts +5 -46
- package/dist/rules/require-strict-mode.js +17 -107
- package/dist/rules/require-tty-guard.d.ts +2 -0
- package/dist/rules/require-tty-guard.js +8 -1
- package/dist/rules/resolve-declaration-convention.d.ts +9 -89
- package/dist/rules/resolve-declaration-convention.js +19 -72
- package/dist/rules/resolve-network-wrapper.d.ts +20 -2
- package/dist/rules/resolve-network-wrapper.js +71 -36
- package/dist/rules/resolve-transparent-wrappers.d.ts +38 -0
- package/dist/rules/resolve-transparent-wrappers.js +108 -0
- package/dist/rules/set-options.d.ts +3 -2
- package/dist/rules/set-options.js +18 -6
- package/dist/rules/shebang-interpreter.js +4 -2
- package/dist/rules/strict-mode-prologue.d.ts +43 -0
- package/dist/rules/strict-mode-prologue.js +91 -0
- package/dist/rules/transparent-wrappers.d.ts +4 -3
- package/dist/rules/transparent-wrappers.js +5 -4
- package/dist/rules/user-pattern.d.ts +9 -6
- package/dist/rules/user-pattern.js +16 -12
- package/dist/shell-dialect.d.ts +8 -0
- package/dist/shell-dialect.js +22 -0
- package/dist/syntax/analyze.d.ts +3 -3
- package/dist/syntax/analyze.js +3 -3
- package/dist/syntax/index.d.ts +7 -4
- package/dist/syntax/index.js +7 -4
- package/dist/version.js +2 -1
- package/docs/compat.md +81 -33
- package/docs/custom-rule-tutorial.md +31 -21
- package/docs/declaration-conventions.md +20 -23
- package/docs/error-codes.md +93 -0
- package/docs/examples/no-listed-commands-rule.ts +2 -2
- package/docs/examples/no-rm-rf-rule.mjs +8 -10
- package/docs/examples/sorted-declarations-rule.mjs +6 -9
- package/docs/examples/tsconfig.json +10 -0
- package/docs/rules/README.md +46 -6
- package/docs/rules/_template.md +2 -2
- package/docs/rules/compat/no-append-all-redirect.md +12 -12
- package/docs/rules/compat/no-associative-arrays.md +14 -14
- package/docs/rules/compat/no-brace-sequence-padding-step.md +12 -12
- package/docs/rules/compat/no-case-attributes.md +13 -13
- package/docs/rules/compat/no-case-fallthrough.md +12 -12
- package/docs/rules/compat/no-case-modification.md +11 -11
- package/docs/rules/compat/no-coproc.md +13 -13
- package/docs/rules/compat/no-declare-g.md +13 -13
- package/docs/rules/compat/no-double-bracket.md +2 -2
- package/docs/rules/compat/no-epoch-variables.md +13 -13
- package/docs/rules/compat/no-fd-variable.md +12 -12
- package/docs/rules/compat/no-globstar.md +13 -13
- package/docs/rules/compat/no-lastpipe-semantics.md +13 -13
- package/docs/rules/compat/no-let.md +2 -2
- package/docs/rules/compat/no-mapfile.md +16 -16
- package/docs/rules/compat/no-nameref.md +13 -13
- package/docs/rules/compat/no-negative-array-index.md +14 -14
- package/docs/rules/compat/no-nounset-empty-array.md +72 -17
- package/docs/rules/compat/no-parameter-transformation.md +19 -19
- package/docs/rules/compat/no-pipe-all.md +13 -13
- package/docs/rules/compat/no-printf-time-format.md +13 -13
- package/docs/rules/compat/no-source.md +2 -2
- package/docs/rules/compat/no-test-v.md +12 -12
- package/docs/rules/compat/no-unicode-escape.md +13 -13
- package/docs/rules/compat/no-wait-n.md +13 -13
- package/docs/rules/no-dynamic-invocation.md +17 -12
- package/docs/rules/no-eval.md +6 -1
- package/docs/rules/no-masked-exit-status.md +6 -2
- package/docs/rules/no-secret-env-reads.md +46 -5
- package/docs/rules/no-secret-flags.md +32 -6
- package/docs/rules/no-unchecked-cd.md +22 -2
- package/docs/rules/no-undeclared-commands.md +16 -15
- package/docs/rules/no-unused-declarations.md +17 -20
- package/docs/rules/prefer-local.md +20 -2
- package/docs/rules/quote-expansions.md +8 -5
- package/docs/rules/require-network-wrapper.md +26 -21
- package/docs/rules/require-shebang.md +10 -4
- package/docs/rules/require-strict-mode.md +31 -23
- package/docs/rules/require-tty-guard.md +12 -3
- package/docs/selectors.md +7 -2
- package/docs/shellcheck.md +9 -5
- package/docs/transparent-wrappers.md +97 -0
- package/docs/wrapper-rules.md +11 -0
- package/package.json +3 -3
- package/dist/declaration-conventions/read-declared-commands.d.ts +0 -70
- package/dist/language/end-of-input-marker.d.ts +0 -29
- package/dist/language/end-of-input-marker.js +0 -88
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,18 @@
|
|
|
1
|
-
/** Exposes the ESLint language, source view, and rule-author helpers as one plugin boundary. */
|
|
2
|
-
import type { ConfigObject } from '@eslint/core';
|
|
3
|
-
import { ShellLanguage } from './language/shell-language.js';
|
|
4
|
-
export { ShellLanguage } from './language/shell-language.js';
|
|
5
|
-
export { ShellSourceCode } from './language/shell-source-code.js';
|
|
6
|
-
export type { NormalizedShellLanguageOptions, ShellLanguageOptions, ShellLanguageOptionsJSON, } from './language/shell-language-options.js';
|
|
7
|
-
export { resolveWord } from './language/word-resolution.js';
|
|
8
|
-
export type { Argv0Resolution } from 'sh-ast/analyze';
|
|
9
|
-
export type { CommandContext, ResolveArgv0Options, WordResolution } from 'sh-ast/analyze';
|
|
10
|
-
export type { ShellCommandSite } from './language/command-resolution.js';
|
|
11
|
-
export type { ShellComment, ShellFile, ShellNode, ShellNodeField, ShellNodeMap, ShellNodeOf, ShellNodeType, ShellPosition, } from './language/syntax-view.js';
|
|
12
|
-
export type { ShellDialect } from './language/shell-language-options.js';
|
|
13
|
-
export type { DeclarationConvention, DeclaredCommand, FileDeclaredCommand, LintedFile, DescribedDeclaredCommand, ScriptDeclaredCommand, } from './declaration-conventions/declaration-convention.js';
|
|
14
|
-
export { readDeclaredCommands } from './declaration-conventions/read-declared-commands.js';
|
|
15
|
-
export type { DeclarationReadContext } from './declaration-conventions/read-declared-commands.js';
|
|
16
|
-
export { commentPragma } from './declaration-conventions/comment-pragma.js';
|
|
17
|
-
export { resolveDeclarationConvention } from './rules/resolve-declaration-convention.js';
|
|
18
|
-
export type { DeclarationConventionBindingContext } from './rules/resolve-declaration-convention.js';
|
|
19
|
-
export { defineShellRule } from './rules/define-shell-rule.js';
|
|
20
|
-
export type { ShellListener, ShellRule, ShellRuleContext, ShellRuleMeta, ShellRuleSpec, ShellRuleVisitor, ShellTypedListeners, } from './rules/define-shell-rule.js';
|
|
21
|
-
export { createWrapperRule } from './rules/create-wrapper-rule.js';
|
|
22
|
-
export type { WrapperRuleConfig, WrapperRuleLocalInvocation, WrapperRuleLocalOperand, WrapperRuleSubcommands, } from './rules/create-wrapper-rule.js';
|
|
23
|
-
export type { WrapperSpec } from 'sh-ast/analyze';
|
|
24
1
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* `configs.recommended` is the `sh/recommended` preset: a single config
|
|
39
|
-
* object carrying `plugins: { sh }` and `language: "sh/sh"` but no `files`,
|
|
40
|
-
* so it inherits the globs of the entry that extends it:
|
|
41
|
-
* `{ files: [...], extends: [sh.configs.recommended] }`. It enables the
|
|
42
|
-
* convention-free policy rules. The rules index at
|
|
43
|
-
* https://github.com/mike-north/eslint-sh/blob/main/packages/eslint-plugin/docs/rules/README.md
|
|
44
|
-
* describes preset membership and available autofixes.
|
|
45
|
-
* `configs['agent-authored']` is the strict `sh/agent-authored` preset for
|
|
46
|
-
* machine-written, human-reviewed scripts:
|
|
47
|
-
* every `recommended` rule plus the contract rules, all at `error`.
|
|
48
|
-
* `configs['bash-3.2']` and `configs['posix-portable']` are deployment-target
|
|
49
|
-
* packs: the first sets `languageOptions.shellVersion: "3.2"` and enables
|
|
50
|
-
* every version-gated `compat/*` rule; the second sets
|
|
51
|
-
* `languageOptions.dialect: "posix"`, enables the `compat/*` rules and the
|
|
52
|
-
* shebang/dialect check, and requires `set -eu`; it reports named constructs
|
|
53
|
-
* that fail on dash, not every non-POSIX construct, and leaves `local`,
|
|
54
|
-
* `echo -e` and the rest of shellcheck's SC3xxx catalog to shellcheck. Every
|
|
55
|
-
* shipped config is a
|
|
56
|
-
* single object with no `files`; the two packs also carry `languageOptions`,
|
|
57
|
-
* because the target they name is their meaning.
|
|
58
|
-
*
|
|
59
|
-
* Re-exported, unchanged, as the default export of the `eslint-sh` umbrella
|
|
60
|
-
* package: importing this package or the umbrella package both yield the
|
|
61
|
-
* same plugin object.
|
|
2
|
+
* Node's CommonJS entry uses the same plugin as ESM and every preset. Helpers
|
|
3
|
+
* remain non-enumerable so ESLint's plugin/config traversal sees only plugin
|
|
4
|
+
* data, while existing namespace-style require properties retain their identity.
|
|
5
|
+
* API Extractor reads api.ts instead: it cannot represent quoted export names.
|
|
6
|
+
*/
|
|
7
|
+
import plugin, * as api from './api.js';
|
|
8
|
+
export { default } from './api.js';
|
|
9
|
+
export * from './api.js';
|
|
10
|
+
/**
|
|
11
|
+
* The require(ESM) result is the plugin itself, augmented with the ESM namespace's
|
|
12
|
+
* default and named values. This assertion describes the properties installed
|
|
13
|
+
* above; it neither wraps nor copies the plugin, preserving preset identity.
|
|
62
14
|
*
|
|
63
15
|
* @public
|
|
64
16
|
*/
|
|
65
|
-
declare const
|
|
66
|
-
|
|
67
|
-
name: string;
|
|
68
|
-
version: string;
|
|
69
|
-
namespace: string;
|
|
70
|
-
};
|
|
71
|
-
languages: {
|
|
72
|
-
sh: ShellLanguage;
|
|
73
|
-
};
|
|
74
|
-
rules: Record<string, import("@eslint/core").RuleDefinition<import("@eslint/core").RuleDefinitionTypeOptions>>;
|
|
75
|
-
configs: {
|
|
76
|
-
recommended: ConfigObject;
|
|
77
|
-
"agent-authored": ConfigObject;
|
|
78
|
-
"bash-3.2": ConfigObject;
|
|
79
|
-
"posix-portable": ConfigObject;
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
export default plugin;
|
|
17
|
+
declare const commonJsModule: typeof plugin & Readonly<typeof api>;
|
|
18
|
+
export { commonJsModule as 'module.exports' };
|
package/dist/index.js
CHANGED
|
@@ -1,78 +1,26 @@
|
|
|
1
|
-
import { createAgentAuthoredConfig } from './configs/agent-authored.js';
|
|
2
|
-
import { createBash32Config } from './configs/bash-3-2.js';
|
|
3
|
-
import { createPosixPortableConfig } from './configs/posix-portable.js';
|
|
4
|
-
import { createRecommendedConfig } from './configs/recommended.js';
|
|
5
|
-
import { ShellLanguage } from './language/shell-language.js';
|
|
6
|
-
import { rules } from './rules/index.js';
|
|
7
|
-
import { readPackageVersion } from './version.js';
|
|
8
|
-
export { ShellLanguage } from './language/shell-language.js';
|
|
9
|
-
export { ShellSourceCode } from './language/shell-source-code.js';
|
|
10
|
-
export { resolveWord } from './language/word-resolution.js';
|
|
11
|
-
export { readDeclaredCommands } from './declaration-conventions/read-declared-commands.js';
|
|
12
|
-
export { commentPragma } from './declaration-conventions/comment-pragma.js';
|
|
13
|
-
export { resolveDeclarationConvention } from './rules/resolve-declaration-convention.js';
|
|
14
|
-
export { defineShellRule } from './rules/define-shell-rule.js';
|
|
15
|
-
export { createWrapperRule } from './rules/create-wrapper-rule.js';
|
|
16
|
-
/* eslint-disable @api-extractor-tools/public-on-non-exported -- `plugin` is exported below as
|
|
17
|
-
`export default plugin`; the rule only recognizes inline exports. */
|
|
18
1
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* `configs['agent-authored']` is the strict `sh/agent-authored` preset for
|
|
40
|
-
* machine-written, human-reviewed scripts:
|
|
41
|
-
* every `recommended` rule plus the contract rules, all at `error`.
|
|
42
|
-
* `configs['bash-3.2']` and `configs['posix-portable']` are deployment-target
|
|
43
|
-
* packs: the first sets `languageOptions.shellVersion: "3.2"` and enables
|
|
44
|
-
* every version-gated `compat/*` rule; the second sets
|
|
45
|
-
* `languageOptions.dialect: "posix"`, enables the `compat/*` rules and the
|
|
46
|
-
* shebang/dialect check, and requires `set -eu`; it reports named constructs
|
|
47
|
-
* that fail on dash, not every non-POSIX construct, and leaves `local`,
|
|
48
|
-
* `echo -e` and the rest of shellcheck's SC3xxx catalog to shellcheck. Every
|
|
49
|
-
* shipped config is a
|
|
50
|
-
* single object with no `files`; the two packs also carry `languageOptions`,
|
|
51
|
-
* because the target they name is their meaning.
|
|
52
|
-
*
|
|
53
|
-
* Re-exported, unchanged, as the default export of the `eslint-sh` umbrella
|
|
54
|
-
* package: importing this package or the umbrella package both yield the
|
|
55
|
-
* same plugin object.
|
|
2
|
+
* Node's CommonJS entry uses the same plugin as ESM and every preset. Helpers
|
|
3
|
+
* remain non-enumerable so ESLint's plugin/config traversal sees only plugin
|
|
4
|
+
* data, while existing namespace-style require properties retain their identity.
|
|
5
|
+
* API Extractor reads api.ts instead: it cannot represent quoted export names.
|
|
6
|
+
*/
|
|
7
|
+
import plugin, * as api from './api.js';
|
|
8
|
+
export { default } from './api.js';
|
|
9
|
+
export * from './api.js';
|
|
10
|
+
for (const [name, value] of Object.entries(api)) {
|
|
11
|
+
Object.defineProperty(plugin, name, {
|
|
12
|
+
value,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
writable: false,
|
|
15
|
+
configurable: false,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The require(ESM) result is the plugin itself, augmented with the ESM namespace's
|
|
20
|
+
* default and named values. This assertion describes the properties installed
|
|
21
|
+
* above; it neither wraps nor copies the plugin, preserving preset identity.
|
|
56
22
|
*
|
|
57
23
|
* @public
|
|
58
24
|
*/
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
name: '@eslint-sh/eslint-plugin',
|
|
62
|
-
version: readPackageVersion(),
|
|
63
|
-
namespace: 'sh',
|
|
64
|
-
},
|
|
65
|
-
languages: {
|
|
66
|
-
sh: new ShellLanguage(),
|
|
67
|
-
},
|
|
68
|
-
rules,
|
|
69
|
-
// Filled in below: each shipped config registers this very object under
|
|
70
|
-
// `plugins.sh`, so the plugin must exist before its configs can.
|
|
71
|
-
configs: {},
|
|
72
|
-
};
|
|
73
|
-
/* eslint-enable @api-extractor-tools/public-on-non-exported */
|
|
74
|
-
plugin.configs.recommended = createRecommendedConfig(plugin);
|
|
75
|
-
plugin.configs['agent-authored'] = createAgentAuthoredConfig(plugin);
|
|
76
|
-
plugin.configs['bash-3.2'] = createBash32Config(plugin);
|
|
77
|
-
plugin.configs['posix-portable'] = createPosixPortableConfig(plugin);
|
|
78
|
-
export default plugin;
|
|
25
|
+
const commonJsModule = plugin;
|
|
26
|
+
export { commonJsModule as 'module.exports' };
|
|
@@ -70,7 +70,7 @@ export interface ShellCommandSite {
|
|
|
70
70
|
* @returns A new result on every call. Its `chain` and `chainIndices`
|
|
71
71
|
* arrays belong to the caller. `chainIndices` gives each chain entry's
|
|
72
72
|
* position in this site's `argv`.
|
|
73
|
-
* @throws `ShAnalyzeInvalidWrapperSpecError` (from `sh-ast/analyze`) when
|
|
73
|
+
* @throws `ShAnalyzeInvalidWrapperSpecError` (`SH_AST_ANALYZE_INVALID_WRAPPER_SPEC`, from `sh-ast/analyze`) when
|
|
74
74
|
* `options.transparentWrappers` contains a malformed entry.
|
|
75
75
|
*/
|
|
76
76
|
resolveInvokedCommand(options?: ResolveArgv0Options): Argv0Resolution;
|
|
@@ -91,8 +91,8 @@ export interface ShellCommandSite {
|
|
|
91
91
|
* sibling commands. So every site is frozen in place here, before any rule
|
|
92
92
|
* can see it (see {@link freezeCommandSite}).
|
|
93
93
|
*
|
|
94
|
-
* @throws TypeError when `file` has no associated parsed syntax.
|
|
95
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when the file's
|
|
94
|
+
* @throws TypeError with `ESLINT_SH_FILE_NODE` when `file` has no associated parsed syntax.
|
|
95
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
|
|
96
96
|
* nesting exceeds analysis's recursion guard. It propagates unchanged: a
|
|
97
97
|
* partial index would silently omit real commands, so callers fail closed.
|
|
98
98
|
* @internal
|
|
@@ -107,7 +107,7 @@ export declare function buildCommandSiteIndex(file: ShellFile): CommandSiteIndex
|
|
|
107
107
|
* when the index was built: the same array is shared by every rule linting
|
|
108
108
|
* this file.
|
|
109
109
|
*
|
|
110
|
-
* @throws Error when a site's `CallExpr` has no view node in `file`. Analysis
|
|
110
|
+
* @throws Error with `ESLINT_SH_COMMAND_SITE_VIEW` when a site's `CallExpr` has no view node in `file`. Analysis
|
|
111
111
|
* of the same parse only reports parser nodes the projection saw, so this
|
|
112
112
|
* marks a broken invariant rather than a shell construct; failing loudly is
|
|
113
113
|
* safer than silently dropping a command.
|
|
@@ -117,7 +117,7 @@ export declare function viewCommandSites(file: ShellFile, index: CommandSiteInde
|
|
|
117
117
|
/**
|
|
118
118
|
* Returns the parser's own `CallExpr` behind a lint `CallExpr`.
|
|
119
119
|
*
|
|
120
|
-
* @throws TypeError when `callExpr` is not a parsed `CallExpr` from this
|
|
120
|
+
* @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed `CallExpr` from this
|
|
121
121
|
* language adapter (a fabricated or synthetic view node has no syntax).
|
|
122
122
|
* @internal
|
|
123
123
|
*/
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* analysis reports, maps a lint `CallExpr` to its raw syntax node, and maps
|
|
6
6
|
* each site's raw `CallExpr` forward to its lint view node, so every rule gets
|
|
7
7
|
* the analysis answer rather than a local reinterpretation.
|
|
8
|
+
*
|
|
9
|
+
* ESLINT_SH_FILE_NODE and ESLINT_SH_CALL_NODE reject missing syntax associations. ESLINT_SH_COMMAND_SITE_VIEW rejects a site from a different file; analysis resource and wrapper failures propagate unchanged.
|
|
8
10
|
*/
|
|
9
11
|
import { enumerateCommands, resolveArgv0 } from 'sh-ast/analyze';
|
|
10
12
|
import { syntaxForNode, viewForSyntax, withoutCrlfCarriageReturn } from './syntax-view.js';
|
|
@@ -24,8 +26,8 @@ import { syntaxForNode, viewForSyntax, withoutCrlfCarriageReturn } from './synta
|
|
|
24
26
|
* sibling commands. So every site is frozen in place here, before any rule
|
|
25
27
|
* can see it (see {@link freezeCommandSite}).
|
|
26
28
|
*
|
|
27
|
-
* @throws TypeError when `file` has no associated parsed syntax.
|
|
28
|
-
* @throws `ShAnalyzeMaxDepthError` (from `sh-ast/analyze`) when the file's
|
|
29
|
+
* @throws TypeError with `ESLINT_SH_FILE_NODE` when `file` has no associated parsed syntax.
|
|
30
|
+
* @throws `ShAnalyzeMaxDepthError` (`SH_AST_ANALYZE_MAX_DEPTH`, from `sh-ast/analyze`) when the file's
|
|
29
31
|
* nesting exceeds analysis's recursion guard. It propagates unchanged: a
|
|
30
32
|
* partial index would silently omit real commands, so callers fail closed.
|
|
31
33
|
* @internal
|
|
@@ -33,7 +35,9 @@ import { syntaxForNode, viewForSyntax, withoutCrlfCarriageReturn } from './synta
|
|
|
33
35
|
export function buildCommandSiteIndex(file) {
|
|
34
36
|
const syntax = syntaxForNode(file);
|
|
35
37
|
if (syntax?.Type !== 'File') {
|
|
36
|
-
throw new TypeError('expected a parsed shell File from this language adapter')
|
|
38
|
+
throw Object.assign(new TypeError('expected a parsed shell File from this language adapter'), {
|
|
39
|
+
code: 'ESLINT_SH_FILE_NODE',
|
|
40
|
+
});
|
|
37
41
|
}
|
|
38
42
|
const sites = Object.freeze(enumerateCommands(syntax).map((site) => freezeCommandSite(withLfArgv(site))));
|
|
39
43
|
return { sites, byNode: new Map(sites.map((site) => [site.node, site])) };
|
|
@@ -83,7 +87,7 @@ function freezeCommandSite(site) {
|
|
|
83
87
|
* when the index was built: the same array is shared by every rule linting
|
|
84
88
|
* this file.
|
|
85
89
|
*
|
|
86
|
-
* @throws Error when a site's `CallExpr` has no view node in `file`. Analysis
|
|
90
|
+
* @throws Error with `ESLINT_SH_COMMAND_SITE_VIEW` when a site's `CallExpr` has no view node in `file`. Analysis
|
|
87
91
|
* of the same parse only reports parser nodes the projection saw, so this
|
|
88
92
|
* marks a broken invariant rather than a shell construct; failing loudly is
|
|
89
93
|
* safer than silently dropping a command.
|
|
@@ -93,7 +97,7 @@ export function viewCommandSites(file, index) {
|
|
|
93
97
|
return Object.freeze(index.sites.map((site) => {
|
|
94
98
|
const node = viewForSyntax(file, site.node);
|
|
95
99
|
if (node?.type !== 'CallExpr') {
|
|
96
|
-
throw new Error('command site has no CallExpr in the lint view of this file');
|
|
100
|
+
throw Object.assign(new Error('command site has no CallExpr in the lint view of this file'), { code: 'ESLINT_SH_COMMAND_SITE_VIEW' });
|
|
97
101
|
}
|
|
98
102
|
return Object.freeze({
|
|
99
103
|
node,
|
|
@@ -107,14 +111,14 @@ export function viewCommandSites(file, index) {
|
|
|
107
111
|
/**
|
|
108
112
|
* Returns the parser's own `CallExpr` behind a lint `CallExpr`.
|
|
109
113
|
*
|
|
110
|
-
* @throws TypeError when `callExpr` is not a parsed `CallExpr` from this
|
|
114
|
+
* @throws TypeError with `ESLINT_SH_CALL_NODE` when `callExpr` is not a parsed `CallExpr` from this
|
|
111
115
|
* language adapter (a fabricated or synthetic view node has no syntax).
|
|
112
116
|
* @internal
|
|
113
117
|
*/
|
|
114
118
|
export function rawCallExprFor(callExpr) {
|
|
115
119
|
const syntax = syntaxForNode(callExpr);
|
|
116
120
|
if (syntax?.Type !== 'CallExpr') {
|
|
117
|
-
throw new TypeError('expected a parsed shell CallExpr from this language adapter');
|
|
121
|
+
throw Object.assign(new TypeError('expected a parsed shell CallExpr from this language adapter'), { code: 'ESLINT_SH_CALL_NODE' });
|
|
118
122
|
}
|
|
119
123
|
return syntax;
|
|
120
124
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { ShellNode as ShNode } from './syntax-view.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* implements.
|
|
3
|
+
* Candidate node types for the six launch esquery selector classes
|
|
4
|
+
* `ShellLanguage.matchesSelectorClass` implements. `:command` additionally
|
|
5
|
+
* requires a command word: a `CallExpr` with nonempty `args` has a command
|
|
6
|
+
* site, including when that word is dynamic. Assignment-only calls such as
|
|
7
|
+
* `FOO=1` have no site; consumers wanting every call select `CallExpr` directly.
|
|
8
|
+
* Keys are the *bare* class name —
|
|
5
9
|
* esquery strips the leading `:` before invoking a language's
|
|
6
10
|
* `matchesSelectorClass` (confirmed against `esquery`'s own `case 'class'`
|
|
7
11
|
* matcher, which calls `options.matchClass(selector.name, node, ancestry)`
|
|
@@ -41,7 +45,7 @@ export type SelectorClassName = keyof typeof SELECTOR_CLASS_NODE_TYPES;
|
|
|
41
45
|
/**
|
|
42
46
|
* Implements the matching behavior behind `ShellLanguage.matchesSelectorClass`
|
|
43
47
|
* (`@eslint/core`'s `Language.matchesSelectorClass`): `true` when `node`'s
|
|
44
|
-
*
|
|
48
|
+
* construct belongs to the named launch class, `false` for every other node
|
|
45
49
|
* type (including the five other launch classes' node types) and for any
|
|
46
50
|
* unrecognized `className` (a class name this language does not define —
|
|
47
51
|
* per the `Language` contract, an unknown class simply never matches,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* implements.
|
|
2
|
+
* Candidate node types for the six launch esquery selector classes
|
|
3
|
+
* `ShellLanguage.matchesSelectorClass` implements. `:command` additionally
|
|
4
|
+
* requires a command word: a `CallExpr` with nonempty `args` has a command
|
|
5
|
+
* site, including when that word is dynamic. Assignment-only calls such as
|
|
6
|
+
* `FOO=1` have no site; consumers wanting every call select `CallExpr` directly.
|
|
7
|
+
* Keys are the *bare* class name —
|
|
4
8
|
* esquery strips the leading `:` before invoking a language's
|
|
5
9
|
* `matchesSelectorClass` (confirmed against `esquery`'s own `case 'class'`
|
|
6
10
|
* matcher, which calls `options.matchClass(selector.name, node, ancestry)`
|
|
@@ -30,7 +34,7 @@ export const SELECTOR_CLASS_NODE_TYPES = {
|
|
|
30
34
|
quoted: ['SglQuoted', 'DblQuoted'],
|
|
31
35
|
function: ['FuncDecl'],
|
|
32
36
|
};
|
|
33
|
-
/**
|
|
37
|
+
/** Candidate types are shared across matches; command-word presence is checked per node. */
|
|
34
38
|
const nodeTypesByClassName = new Map(Object.entries(SELECTOR_CLASS_NODE_TYPES).map(([className, nodeTypes]) => [
|
|
35
39
|
className,
|
|
36
40
|
new Set(nodeTypes),
|
|
@@ -38,7 +42,7 @@ const nodeTypesByClassName = new Map(Object.entries(SELECTOR_CLASS_NODE_TYPES).m
|
|
|
38
42
|
/**
|
|
39
43
|
* Implements the matching behavior behind `ShellLanguage.matchesSelectorClass`
|
|
40
44
|
* (`@eslint/core`'s `Language.matchesSelectorClass`): `true` when `node`'s
|
|
41
|
-
*
|
|
45
|
+
* construct belongs to the named launch class, `false` for every other node
|
|
42
46
|
* type (including the five other launch classes' node types) and for any
|
|
43
47
|
* unrecognized `className` (a class name this language does not define —
|
|
44
48
|
* per the `Language` contract, an unknown class simply never matches,
|
|
@@ -47,5 +51,10 @@ const nodeTypesByClassName = new Map(Object.entries(SELECTOR_CLASS_NODE_TYPES).m
|
|
|
47
51
|
* @public
|
|
48
52
|
*/
|
|
49
53
|
export function matchesSelectorClass(className, node) {
|
|
54
|
+
// A command site exists exactly when a call has a command word. Its name
|
|
55
|
+
// need not be statically known, and assignments before it do not remove it.
|
|
56
|
+
if (className === 'command') {
|
|
57
|
+
return node.type === 'CallExpr' && node.args.length > 0;
|
|
58
|
+
}
|
|
50
59
|
return nodeTypesByClassName.get(className)?.has(node.type) ?? false;
|
|
51
60
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type ShellDialect = 'bash' | 'posix' | 'mksh' | 'bats' | 'zsh';
|
|
1
|
+
import type { ShellDialect } from '../shell-dialect.js';
|
|
2
|
+
export type { ShellDialect } from '../shell-dialect.js';
|
|
4
3
|
/**
|
|
5
4
|
* `languageOptions` accepted by {@link ShellLanguage}: `dialect` selects
|
|
6
|
-
* mvdan/sh's `LangVariant` through a consumer-owned mapping (default `"bash"`); `
|
|
5
|
+
* mvdan/sh's `LangVariant` through a consumer-owned mapping (default `"bash"`); `minBashVersion`
|
|
7
6
|
* is consumed by the rule layer (e.g. the bash-3.2 compatibility pack),
|
|
8
7
|
* never by the parser itself.
|
|
9
8
|
*
|
|
@@ -19,13 +18,14 @@ export type ShellDialect = 'bash' | 'posix' | 'mksh' | 'bats' | 'zsh';
|
|
|
19
18
|
export interface ShellLanguageOptions extends Record<string, unknown> {
|
|
20
19
|
readonly dialect?: ShellDialect;
|
|
21
20
|
/**
|
|
22
|
-
* The Bash version (`MAJOR[.MINOR]`, such as `"3.2"`) the
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* version.
|
|
21
|
+
* The minimum Bash version (`MAJOR[.MINOR]`, such as `"3.2"`) the
|
|
22
|
+
* script must support, including every newer Bash. Only valid with the
|
|
23
|
+
* `bash` or `bats` dialect (the default is `bash`). The parser ignores
|
|
24
|
+
* it; `compat/*` rules report features unavailable at this floor. Unset
|
|
25
|
+
* means no Bash version constraint. Versions compare numerically by
|
|
26
|
+
* major then minor, with no upper version limit.
|
|
27
27
|
*/
|
|
28
|
-
readonly
|
|
28
|
+
readonly minBashVersion?: string;
|
|
29
29
|
/**
|
|
30
30
|
* The prefix directive/inline-config comments must start with — e.g. the
|
|
31
31
|
* default `"eslint"` recognizes `# eslint-disable-next-line ...` and
|
|
@@ -38,14 +38,14 @@ export interface ShellLanguageOptions extends Record<string, unknown> {
|
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* The plain-data shape {@link NormalizedShellLanguageOptions.toJSON} returns:
|
|
41
|
-
* `dialect` and `directivePrefix` always present (both defaulted), `
|
|
41
|
+
* `dialect` and `directivePrefix` always present (both defaulted), `minBashVersion`
|
|
42
42
|
* present only when the caller supplied one. Keys are always emitted in this
|
|
43
43
|
* fixed order so that two logically-identical inputs serialize identically
|
|
44
44
|
* regardless of the key order the caller happened to use — the property this
|
|
45
45
|
* type exists to guarantee for cache-key stability (see
|
|
46
46
|
* {@link NormalizedShellLanguageOptions}). `directivePrefix` is included
|
|
47
|
-
* unconditionally (like `dialect`, unlike `
|
|
48
|
-
* `dialect` and unlike `
|
|
47
|
+
* unconditionally (like `dialect`, unlike `minBashVersion`) because — like
|
|
48
|
+
* `dialect` and unlike `minBashVersion` — it always has a concrete effect on
|
|
49
49
|
* linting results (which comments the `SourceCode` recognizes as directives)
|
|
50
50
|
* whether or not the caller supplied one, so two configs that differ only in
|
|
51
51
|
* an *implicit* default vs. an *explicit* `directivePrefix: "eslint"` must
|
|
@@ -56,7 +56,7 @@ export interface ShellLanguageOptions extends Record<string, unknown> {
|
|
|
56
56
|
export interface ShellLanguageOptionsJSON {
|
|
57
57
|
readonly dialect: ShellDialect;
|
|
58
58
|
readonly directivePrefix: string;
|
|
59
|
-
readonly
|
|
59
|
+
readonly minBashVersion?: string;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* The result of {@link ShellLanguage.normalizeLanguageOptions}: `dialect` and
|
|
@@ -73,25 +73,28 @@ export interface ShellLanguageOptionsJSON {
|
|
|
73
73
|
export interface NormalizedShellLanguageOptions extends Record<string, unknown> {
|
|
74
74
|
readonly dialect: ShellDialect;
|
|
75
75
|
readonly directivePrefix: string;
|
|
76
|
-
readonly
|
|
76
|
+
readonly minBashVersion?: string;
|
|
77
77
|
toJSON(): ShellLanguageOptionsJSON;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Validates `languageOptions` for {@link ShellLanguage}. Throws a
|
|
81
81
|
* `TypeError` when `dialect` is present but not one of the five supported
|
|
82
|
-
* dialects, when `
|
|
83
|
-
* match the `MAJOR[.MINOR]` numeric shape (see {@link
|
|
82
|
+
* dialects, when `minBashVersion` is present but not a string or does not
|
|
83
|
+
* match the `MAJOR[.MINOR]` numeric shape (see {@link MIN_BASH_VERSION_PATTERN};
|
|
84
84
|
* e.g. `''` and `'not-a-version'` are rejected, but a shape-valid,
|
|
85
85
|
* nonexistent version like `'99.99'` is accepted — shape is validated, not
|
|
86
86
|
* membership in a known-versions list), or when `directivePrefix` is present
|
|
87
87
|
* but not a valid directive-comment label (see {@link DIRECTIVE_PREFIX_PATTERN}).
|
|
88
|
-
*
|
|
88
|
+
* The Bash floor is rejected for dialects other than `bash` and `bats`.
|
|
89
|
+
* The removed `shellVersion` key throws with migration guidance, even if
|
|
90
|
+
* its value is undefined. Other unknown keys are silently ignored.
|
|
89
91
|
*
|
|
90
92
|
* The parameter is treated as `Record<string, unknown>` internally (rather
|
|
91
93
|
* than trusting {@link ShellLanguageOptions}'s declared field types) because
|
|
92
94
|
* this function's entire job is validating an untrusted boundary: the
|
|
93
95
|
* caller-supplied object may not actually match the declared shape.
|
|
94
96
|
*
|
|
97
|
+
* @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
|
|
95
98
|
* @public
|
|
96
99
|
*/
|
|
97
100
|
export declare function validateShellLanguageOptions(languageOptions: Record<string, unknown>): void;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* the consumer's configuration labels; the syntax interface itself accepts
|
|
5
|
-
* upstream numeric constants rather than these configuration strings.
|
|
6
|
-
*/
|
|
7
|
-
const SUPPORTED_SHELL_DIALECTS = ['bash', 'posix', 'mksh', 'bats', 'zsh'];
|
|
8
|
-
/** Narrows configuration labels without treating arbitrary strings as parser variants. */
|
|
9
|
-
function isShellDialect(value) {
|
|
10
|
-
return (typeof value === 'string' && SUPPORTED_SHELL_DIALECTS.includes(value));
|
|
11
|
-
}
|
|
1
|
+
/** Validates ESLint-specific language options before parsing; shared vocabulary owns the grammar labels. */
|
|
2
|
+
import { configurationMessage } from '../configuration-message.js';
|
|
3
|
+
import { isShellDialect, SUPPORTED_SHELL_DIALECTS } from '../shell-dialect.js';
|
|
12
4
|
/**
|
|
13
5
|
* Default for {@link ShellLanguageOptions.directivePrefix} — the
|
|
14
6
|
* ESLint-conventional spelling. The directive prefix is configurable but
|
|
@@ -30,52 +22,62 @@ function isValidDirectivePrefix(value) {
|
|
|
30
22
|
return typeof value === 'string' && DIRECTIVE_PREFIX_PATTERN.test(value);
|
|
31
23
|
}
|
|
32
24
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* string — including `''` and `'not-a-version'` — with zero feedback). This
|
|
37
|
-
* validates *shape only*, not membership in a known-versions list: a
|
|
38
|
-
* shape-valid but nonexistent version like `'99.99'` is intentionally
|
|
39
|
-
* accepted, per this issue's acceptance criteria and non-goals (per-dialect
|
|
40
|
-
* known-version allowlists are out of scope). How rules consume
|
|
41
|
-
* `shellVersion` is defined by the `compat/*` rules' gate
|
|
42
|
-
* (`src/rules/compat/version-gates.ts`, documented in `docs/compat.md`).
|
|
25
|
+
* The Bash floor accepts numeric MAJOR[.MINOR] values, including future
|
|
26
|
+
* releases. Validation checks shape rather than a release allowlist;
|
|
27
|
+
* compatibility rules compare the floor with each feature's first release.
|
|
43
28
|
*/
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
const MIN_BASH_VERSION_PATTERN = /^\d+(?:\.\d+)?$/u;
|
|
30
|
+
/** Whether a Bash floor has the numeric shape required for comparison. */
|
|
31
|
+
function isValidMinBashVersionShape(value) {
|
|
32
|
+
return MIN_BASH_VERSION_PATTERN.test(value);
|
|
47
33
|
}
|
|
48
34
|
/**
|
|
49
35
|
* Validates `languageOptions` for {@link ShellLanguage}. Throws a
|
|
50
36
|
* `TypeError` when `dialect` is present but not one of the five supported
|
|
51
|
-
* dialects, when `
|
|
52
|
-
* match the `MAJOR[.MINOR]` numeric shape (see {@link
|
|
37
|
+
* dialects, when `minBashVersion` is present but not a string or does not
|
|
38
|
+
* match the `MAJOR[.MINOR]` numeric shape (see {@link MIN_BASH_VERSION_PATTERN};
|
|
53
39
|
* e.g. `''` and `'not-a-version'` are rejected, but a shape-valid,
|
|
54
40
|
* nonexistent version like `'99.99'` is accepted — shape is validated, not
|
|
55
41
|
* membership in a known-versions list), or when `directivePrefix` is present
|
|
56
42
|
* but not a valid directive-comment label (see {@link DIRECTIVE_PREFIX_PATTERN}).
|
|
57
|
-
*
|
|
43
|
+
* The Bash floor is rejected for dialects other than `bash` and `bats`.
|
|
44
|
+
* The removed `shellVersion` key throws with migration guidance, even if
|
|
45
|
+
* its value is undefined. Other unknown keys are silently ignored.
|
|
58
46
|
*
|
|
59
47
|
* The parameter is treated as `Record<string, unknown>` internally (rather
|
|
60
48
|
* than trusting {@link ShellLanguageOptions}'s declared field types) because
|
|
61
49
|
* this function's entire job is validating an untrusted boundary: the
|
|
62
50
|
* caller-supplied object may not actually match the declared shape.
|
|
63
51
|
*
|
|
52
|
+
* @throws TypeError with `ESLINT_SH_LANGUAGE_OPTION` for an invalid project binding.
|
|
64
53
|
* @public
|
|
65
54
|
*/
|
|
66
55
|
export function validateShellLanguageOptions(languageOptions) {
|
|
67
|
-
|
|
56
|
+
// ESLINT_SH_LANGUAGE_OPTION means a project language option cannot be honored,
|
|
57
|
+
// including combinations whose individual values would otherwise be valid.
|
|
58
|
+
// A removed key must not disappear during normalization: that would
|
|
59
|
+
// silently disable the consumer's compatibility requirement.
|
|
60
|
+
if ('shellVersion' in languageOptions) {
|
|
61
|
+
throw Object.assign(new TypeError(configurationMessage('languageOptions.shellVersion', 'has been removed; use languageOptions.minBashVersion with dialect "bash" or "bats" instead', languageOptions.shellVersion)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
|
|
62
|
+
}
|
|
63
|
+
const { dialect, minBashVersion, directivePrefix } = languageOptions;
|
|
68
64
|
if (dialect !== undefined && !isShellDialect(dialect)) {
|
|
69
|
-
throw new TypeError(
|
|
65
|
+
throw Object.assign(new TypeError(configurationMessage('languageOptions.dialect', `must be one of ${SUPPORTED_SHELL_DIALECTS.join(', ')}`, dialect)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
|
|
66
|
+
}
|
|
67
|
+
if (minBashVersion !== undefined &&
|
|
68
|
+
dialect !== undefined &&
|
|
69
|
+
dialect !== 'bash' &&
|
|
70
|
+
dialect !== 'bats') {
|
|
71
|
+
throw Object.assign(new TypeError(configurationMessage('languageOptions.minBashVersion', `applies only to bash and bats; dialect is "${dialect}". Remove minBashVersion or set dialect to "bash" or "bats"`, minBashVersion)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
|
|
70
72
|
}
|
|
71
|
-
if (
|
|
72
|
-
throw new TypeError(
|
|
73
|
+
if (minBashVersion !== undefined && typeof minBashVersion !== 'string') {
|
|
74
|
+
throw Object.assign(new TypeError(configurationMessage('languageOptions.minBashVersion', 'must be a string (e.g. "3.2")', minBashVersion)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
|
|
73
75
|
}
|
|
74
|
-
if (typeof
|
|
75
|
-
throw new TypeError(
|
|
76
|
+
if (typeof minBashVersion === 'string' && !isValidMinBashVersionShape(minBashVersion)) {
|
|
77
|
+
throw Object.assign(new TypeError(configurationMessage('languageOptions.minBashVersion', 'must match the shape MAJOR[.MINOR] (e.g. "3.2", "5")', minBashVersion)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
|
|
76
78
|
}
|
|
77
79
|
if (directivePrefix !== undefined && !isValidDirectivePrefix(directivePrefix)) {
|
|
78
|
-
throw new TypeError(
|
|
80
|
+
throw Object.assign(new TypeError(configurationMessage('languageOptions.directivePrefix', 'must be one or more lowercase, hyphen-separated words (e.g. "eslint", "shellcheck-sh")', directivePrefix)), { code: 'ESLINT_SH_LANGUAGE_OPTION' });
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
/**
|
|
@@ -91,18 +93,18 @@ export function validateShellLanguageOptions(languageOptions) {
|
|
|
91
93
|
export function normalizeShellLanguageOptions(languageOptions) {
|
|
92
94
|
const dialect = languageOptions.dialect ?? 'bash';
|
|
93
95
|
const directivePrefix = languageOptions.directivePrefix ?? DEFAULT_DIRECTIVE_PREFIX;
|
|
94
|
-
const
|
|
96
|
+
const minBashVersion = languageOptions.minBashVersion;
|
|
95
97
|
return {
|
|
96
98
|
dialect,
|
|
97
99
|
directivePrefix,
|
|
98
100
|
// `exactOptionalPropertyTypes` forbids assigning `undefined` to an
|
|
99
101
|
// optional property directly — omit the key entirely rather than set it
|
|
100
|
-
// to `undefined` when the caller didn't supply a
|
|
101
|
-
...(
|
|
102
|
+
// to `undefined` when the caller didn't supply a minBashVersion.
|
|
103
|
+
...(minBashVersion === undefined ? {} : { minBashVersion }),
|
|
102
104
|
toJSON() {
|
|
103
|
-
return
|
|
105
|
+
return minBashVersion === undefined
|
|
104
106
|
? { dialect, directivePrefix }
|
|
105
|
-
: { dialect, directivePrefix,
|
|
107
|
+
: { dialect, directivePrefix, minBashVersion };
|
|
106
108
|
},
|
|
107
109
|
};
|
|
108
110
|
}
|