@eslint-sh/eslint-plugin 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -29
- package/dist/api.d.ts +4 -4
- package/dist/command-harvest/builtins/bats.d.ts +1 -1
- package/dist/command-harvest/harvest-commands.d.ts +18 -7
- package/dist/command-harvest/harvest-commands.js +11 -10
- package/dist/command-harvest/wrapper-table.d.ts +1 -1
- package/dist/command-harvest/wrapper-table.js +1 -1
- package/dist/eslint-plugin-api.d.ts +65 -55
- package/dist/language/command-resolution.d.ts +44 -10
- package/dist/language/command-resolution.js +39 -13
- package/dist/language/shell-source-code.d.ts +25 -42
- package/dist/language/shell-source-code.js +27 -44
- package/dist/language/syntax-view.d.ts +1 -1
- package/dist/language/word-resolution.d.ts +2 -2
- package/dist/language/word-resolution.js +2 -2
- package/dist/rules/compat/declaration-options.js +2 -2
- package/dist/rules/compat/no-brace-sequence-padding-step.js +1 -1
- package/dist/rules/compat/no-mapfile.js +2 -2
- package/dist/rules/compat/no-negative-array-index.js +2 -2
- package/dist/rules/compat/no-printf-time-format.js +2 -2
- package/dist/rules/compat/no-test-v.js +2 -2
- package/dist/rules/compat/no-wait-n.js +2 -2
- package/dist/rules/compat/posix-absent-command.js +2 -2
- package/dist/rules/compat/shopt-options.js +2 -2
- package/dist/rules/create-wrapper-rule.d.ts +3 -3
- package/dist/rules/create-wrapper-rule.js +8 -4
- package/dist/rules/no-dynamic-invocation.d.ts +1 -1
- package/dist/rules/no-dynamic-invocation.js +12 -4
- package/dist/rules/no-eval.js +6 -2
- package/dist/rules/no-masked-exit-status.js +1 -1
- package/dist/rules/no-secret-env-reads.js +1 -1
- package/dist/rules/no-unchecked-cd.js +1 -1
- package/dist/rules/no-undeclared-commands.js +2 -1
- package/dist/rules/no-unused-declarations.js +7 -2
- package/dist/rules/quote-expansions.js +1 -1
- package/dist/rules/require-network-wrapper.d.ts +1 -1
- package/dist/rules/require-network-wrapper.js +10 -4
- package/dist/rules/require-tty-guard.js +1 -1
- package/dist/rules/resolve-network-wrapper.d.ts +2 -2
- package/dist/rules/resolve-network-wrapper.js +6 -6
- package/dist/rules/resolve-transparent-wrappers.d.ts +1 -1
- package/dist/rules/resolve-transparent-wrappers.js +2 -2
- package/dist/rules/transparent-wrappers.d.ts +3 -3
- package/dist/rules/transparent-wrappers.js +1 -1
- package/docs/custom-rule-tutorial.md +35 -35
- package/docs/error-codes.md +6 -5
- package/docs/examples/no-backticks-rule.mjs +1 -1
- package/docs/examples/no-curl-in-functions-rule.mjs +2 -2
- package/docs/examples/no-listed-commands-rule.ts +1 -1
- package/docs/examples/no-rm-rf-rule.mjs +1 -1
- package/docs/rules/no-dynamic-invocation.md +5 -0
- package/docs/rules/no-undeclared-commands.md +4 -0
- package/docs/rules/no-unused-declarations.md +4 -0
- package/docs/rules/require-network-wrapper.md +1 -1
- package/docs/selectors.md +1 -1
- package/docs/wrapper-rules.md +1 -1
- package/package.json +9 -20
- package/dist/eslint-plugin-syntax-analyze.d.ts +0 -23
- package/dist/eslint-plugin-syntax.d.ts +0 -30
- package/dist/syntax/analyze.d.ts +0 -19
- package/dist/syntax/analyze.js +0 -21
- package/dist/syntax/index.d.ts +0 -26
- package/dist/syntax/index.js +0 -28
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
* static cannot be read, and is not reported. The report is on the format
|
|
16
16
|
* word.
|
|
17
17
|
*/
|
|
18
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
18
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
19
19
|
import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
|
|
20
20
|
import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
|
|
21
21
|
import { createCompatRule } from './create-compat-rule.js';
|
|
22
22
|
/**
|
|
23
|
-
* The wrappers followed to find the `printf` command: `sh-
|
|
23
|
+
* The wrappers followed to find the `printf` command: `sh-analysis`'s
|
|
24
24
|
* defaults (which include `command`) plus Bash's `builtin`.
|
|
25
25
|
*/
|
|
26
26
|
const TRANSPARENT_WRAPPERS = [
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
* The report is on the `[[` test, or on the `-v` word.
|
|
27
27
|
*/
|
|
28
28
|
import { TsVarSet } from 'sh-ast';
|
|
29
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
29
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
30
30
|
import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
|
|
31
31
|
import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
|
|
32
32
|
import { createCompatRule } from './create-compat-rule.js';
|
|
33
33
|
/**
|
|
34
|
-
* The wrappers followed to find the `test` command: `sh-
|
|
34
|
+
* The wrappers followed to find the `test` command: `sh-analysis`'s
|
|
35
35
|
* defaults (which include `command`) plus Bash's `builtin`.
|
|
36
36
|
*/
|
|
37
37
|
const TRANSPARENT_WRAPPERS = [
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
* (Bash 5.1's `wait -p var`) is its operand, not an option. The report is on
|
|
16
16
|
* the option word.
|
|
17
17
|
*/
|
|
18
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
18
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
19
19
|
import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
|
|
20
20
|
import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
|
|
21
21
|
import { createCompatRule } from './create-compat-rule.js';
|
|
22
22
|
/**
|
|
23
|
-
* The wrappers followed to find the `wait` command: `sh-
|
|
23
|
+
* The wrappers followed to find the `wait` command: `sh-analysis`'s
|
|
24
24
|
* defaults (which include `command`) plus Bash's `builtin`.
|
|
25
25
|
*/
|
|
26
26
|
const TRANSPARENT_WRAPPERS = [
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
* directly. Anything else, including a version captured in another variable,
|
|
23
23
|
* reports.
|
|
24
24
|
*/
|
|
25
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
25
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
26
26
|
import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
|
|
27
27
|
import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
|
|
28
28
|
/**
|
|
29
29
|
* The wrappers followed to find the command an invocation runs:
|
|
30
|
-
* `sh-
|
|
30
|
+
* `sh-analysis`'s defaults (which include `command`) plus Bash's `builtin`.
|
|
31
31
|
*/
|
|
32
32
|
const TRANSPARENT_WRAPPERS = [
|
|
33
33
|
...DEFAULT_TRANSPARENT_WRAPPERS,
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
* `-s`), `shopt -o` names `set -o` options, and an operand that is not a
|
|
10
10
|
* static word cannot be read, so none of those count.
|
|
11
11
|
*/
|
|
12
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
12
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
13
13
|
import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
|
|
14
14
|
import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
|
|
15
15
|
/**
|
|
16
|
-
* The wrappers followed to find the `shopt` command: `sh-
|
|
16
|
+
* The wrappers followed to find the `shopt` command: `sh-analysis`'s
|
|
17
17
|
* defaults (which include `command`) plus Bash's `builtin`.
|
|
18
18
|
*/
|
|
19
19
|
const TRANSPARENT_WRAPPERS = [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WrapperSpec } from 'sh-
|
|
1
|
+
import type { WrapperSpec } from 'sh-analysis';
|
|
2
2
|
import type { ShellRule } from './define-shell-rule.js';
|
|
3
3
|
/**
|
|
4
4
|
* Restricts a listed command to some of its subcommands, for commands such as
|
|
@@ -73,7 +73,7 @@ export interface WrapperRuleConfig {
|
|
|
73
73
|
/**
|
|
74
74
|
* The wrapper the commands must be run through. A string names a wrapper
|
|
75
75
|
* that takes no options of its own (`retry curl x`), unless it names one of
|
|
76
|
-
* `sh-
|
|
76
|
+
* `sh-analysis`'s default transparent wrappers (`timeout`, `nice`, …),
|
|
77
77
|
* whose known option shape is used. A `WrapperSpec` declares the wrapper's
|
|
78
78
|
* option shape, so that `retry -n 3 curl x` is recognized as `curl` run
|
|
79
79
|
* through `retry`; any of its `names` counts as the wrapper. Like
|
|
@@ -147,7 +147,7 @@ export declare function buildWrapperRule<RuleOptions extends unknown[] = []>(con
|
|
|
147
147
|
* naming the command and the wrapper. Its `meta.docs.url` and
|
|
148
148
|
* `meta.docs.description` default to this package's wrapper-rules page and a
|
|
149
149
|
* sentence naming the policy; `config.docs` overrides either. A listed
|
|
150
|
-
* command is wrapped when the wrapper encloses it in `sh-
|
|
150
|
+
* command is wrapped when the wrapper encloses it in `sh-analysis`'s
|
|
151
151
|
* transparent-wrapper chain, so `audit-run sudo kubectl apply` is wrapped.
|
|
152
152
|
* Command and wrapper words written as paths match by basename
|
|
153
153
|
* (`/usr/bin/kubectl`). Commands inside `$(…)`, functions, and pipelines are
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `sh/require-network-wrapper` is the built-in instance whose wrapper comes
|
|
10
10
|
* from the user's rule options.
|
|
11
11
|
*
|
|
12
|
-
* "Run through" is decided from `sh-
|
|
12
|
+
* "Run through" is decided from `sh-analysis`'s transparent-wrapper
|
|
13
13
|
* resolution, never by reading words locally: each command site's argv0 is
|
|
14
14
|
* followed through the default wrapper table (`sudo`, `env`, `nohup`, …), the
|
|
15
15
|
* bound wrapper, and any command with modeled subcommands, and the resulting
|
|
@@ -35,9 +35,13 @@
|
|
|
35
35
|
* listed command does not report, and neither does a subcommand that is not
|
|
36
36
|
* static. Commands inside command strings (`bash -c '…'`) are not commands to
|
|
37
37
|
* this analysis and are out of scope.
|
|
38
|
+
*
|
|
39
|
+
* This policy checks represented, statically identified commands. Opaque executable
|
|
40
|
+
* syntax is outside that named-command scope; no-dynamic-invocation reports those
|
|
41
|
+
* inventory limits when a project requires execution completeness.
|
|
38
42
|
*/
|
|
39
43
|
import { configurationMessage } from '../configuration-message.js';
|
|
40
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
44
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
41
45
|
import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
|
|
42
46
|
import { definedFunctionNames } from '../command-harvest/harvest-commands.js';
|
|
43
47
|
import { createRule, packageDocsUrl } from './create-rule.js';
|
|
@@ -222,7 +226,7 @@ function wrapperRuleListeners(compiled, context) {
|
|
|
222
226
|
return {
|
|
223
227
|
File() {
|
|
224
228
|
let functions;
|
|
225
|
-
for (const site of sourceCode.
|
|
229
|
+
for (const site of sourceCode.getCommandInventory().commands) {
|
|
226
230
|
const resolution = resolveChain(compiled, site);
|
|
227
231
|
const finding = findListedCommand(compiled, resolution.chain);
|
|
228
232
|
if (finding === null || finding.wrapped)
|
|
@@ -393,7 +397,7 @@ export function buildWrapperRule(config) {
|
|
|
393
397
|
* naming the command and the wrapper. Its `meta.docs.url` and
|
|
394
398
|
* `meta.docs.description` default to this package's wrapper-rules page and a
|
|
395
399
|
* sentence naming the policy; `config.docs` overrides either. A listed
|
|
396
|
-
* command is wrapped when the wrapper encloses it in `sh-
|
|
400
|
+
* command is wrapped when the wrapper encloses it in `sh-analysis`'s
|
|
397
401
|
* transparent-wrapper chain, so `audit-run sudo kubectl apply` is wrapped.
|
|
398
402
|
* Command and wrapper words written as paths match by basename
|
|
399
403
|
* (`/usr/bin/kubectl`). Commands inside `$(…)`, functions, and pipelines are
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* The rule asks, never decides:
|
|
13
13
|
*
|
|
14
|
-
* -
|
|
14
|
+
* - Represented commands come from `ShellSourceCode.getCommandInventory().commands`,
|
|
15
15
|
* so commands nested in command substitutions, process substitutions,
|
|
16
16
|
* pipelines and function bodies are all checked, each once.
|
|
17
17
|
* - Which command each one runs comes from `resolveInvokedCommand`, which
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
* reports. `'embedded-command'` reports as `embeddedCommand`; every other
|
|
21
21
|
* reason (an expansion, a glob, a tilde, an unrecognized wrapper flag, …)
|
|
22
22
|
* reports as `dynamicInvocation`.
|
|
23
|
-
* -
|
|
23
|
+
* - Opaque executable syntax reports independently at the original construct.
|
|
24
|
+
* Dispatcher exemptions permit computed argv words, never embedded opaque code.
|
|
25
|
+
* - The wrappers followed are `sh-analysis`'s defaults, Bash's `builtin`,
|
|
24
26
|
* shells invoked as commands (so `bash -c` is an embedded command and
|
|
25
27
|
* `bash script.sh` runs `script.sh`), and the shared project wrapper facts.
|
|
26
28
|
*
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
* command word. The rule offers no fix and no suggestion; choosing the
|
|
31
33
|
* command is a human decision.
|
|
32
34
|
*/
|
|
33
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
35
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
34
36
|
import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
|
|
35
37
|
import { createRule } from './create-rule.js';
|
|
36
38
|
import { BUILTIN_WRAPPER, SHELL_WRAPPER } from './transparent-wrappers.js';
|
|
@@ -80,6 +82,7 @@ export const noDynamicInvocation = createRule({
|
|
|
80
82
|
],
|
|
81
83
|
defaultOptions: [{ allowInFunctions: [] }],
|
|
82
84
|
messages: {
|
|
85
|
+
opaqueExecutable: 'This syntax contains opaque executable text, so its commands cannot be statically reviewed. Write the commands directly instead.',
|
|
83
86
|
dynamicInvocation: 'The command this runs is not known until run time, so the script cannot be statically reviewed. Name the command with a literal word instead.',
|
|
84
87
|
embeddedCommand: 'This runs shell code embedded in a string, which cannot be statically reviewed. Write the commands directly instead.',
|
|
85
88
|
},
|
|
@@ -92,7 +95,12 @@ export const noDynamicInvocation = createRule({
|
|
|
92
95
|
const transparentWrappers = resolveTransparentWrappers(context, BUILT_IN_WRAPPERS);
|
|
93
96
|
return {
|
|
94
97
|
File() {
|
|
95
|
-
|
|
98
|
+
const inventory = sourceCode.getCommandInventory();
|
|
99
|
+
// Dispatcher exemptions cover computed argv words, never opaque embedded code.
|
|
100
|
+
for (const uncertainty of inventory.uncertainties) {
|
|
101
|
+
context.report({ node: uncertainty.node, messageId: 'opaqueExecutable' });
|
|
102
|
+
}
|
|
103
|
+
for (const site of inventory.commands) {
|
|
96
104
|
const { effective } = site.resolveInvokedCommand({ transparentWrappers });
|
|
97
105
|
if (effective.static)
|
|
98
106
|
continue;
|
package/dist/rules/no-eval.js
CHANGED
|
@@ -23,8 +23,12 @@
|
|
|
23
23
|
* (`$cmd args`) and embedded command strings (`bash -c "$x"`) belong to
|
|
24
24
|
* `no-dynamic-invocation`. The rule has no options and offers no fix or
|
|
25
25
|
* suggestion, because no mechanical rewrite of `eval` preserves behavior.
|
|
26
|
+
*
|
|
27
|
+
* This policy checks represented, statically identified commands. Opaque executable
|
|
28
|
+
* syntax is outside that named-command scope; no-dynamic-invocation reports those
|
|
29
|
+
* inventory limits when a project requires execution completeness.
|
|
26
30
|
*/
|
|
27
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
31
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
28
32
|
import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
|
|
29
33
|
import { createRule } from './create-rule.js';
|
|
30
34
|
import { BUILTIN_WRAPPER } from './transparent-wrappers.js';
|
|
@@ -32,7 +36,7 @@ import { BUILTIN_WRAPPER } from './transparent-wrappers.js';
|
|
|
32
36
|
const RULE_NAME = 'no-eval';
|
|
33
37
|
/**
|
|
34
38
|
* The wrappers followed to find the command an invocation actually runs:
|
|
35
|
-
* `sh-
|
|
39
|
+
* `sh-analysis`'s defaults (`command`, `exec`, `env`, `sudo`, …) plus
|
|
36
40
|
* Bash's `builtin`, so `builtin eval …` is recognized as `eval`.
|
|
37
41
|
*/
|
|
38
42
|
const TRANSPARENT_WRAPPERS = [
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
* `-r` (and `readonly` itself) forbids a later assignment, so those forms are
|
|
85
85
|
* split into the declaration, the assignment, then `readonly <names>`.
|
|
86
86
|
*/
|
|
87
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
87
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
88
88
|
import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
|
|
89
89
|
import { childNodes } from '../language/syntax-view.js';
|
|
90
90
|
import { lineBreakOf } from '../language/line-breaks.js';
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* command index separates wrapper operands from the sink's arguments.
|
|
29
29
|
* - Matching is a name pattern, not secret detection.
|
|
30
30
|
*/
|
|
31
|
-
import { AlternateUnset, AlternateUnsetOrNull } from 'sh-ast
|
|
31
|
+
import { AlternateUnset, AlternateUnsetOrNull } from 'sh-ast';
|
|
32
32
|
import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
|
|
33
33
|
import { createRule } from './create-rule.js';
|
|
34
34
|
import { compileUserPattern } from './user-pattern.js';
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
* negated, in the background, or carrying a here-document (the text after the
|
|
48
48
|
* statement is the document body, not shell code).
|
|
49
49
|
*/
|
|
50
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
50
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
51
51
|
import { resolveTransparentWrappers } from './resolve-transparent-wrappers.js';
|
|
52
52
|
import { createRule } from './create-rule.js';
|
|
53
53
|
import { prologueEnabledOptions, resolveStrictModePrologue, setStatementChanges, } from './strict-mode-prologue.js';
|
|
@@ -88,9 +88,10 @@ export const noUndeclaredCommands = createRule({
|
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
const declared = new Set(declarations.map(({ name }) => name));
|
|
91
|
+
// Report known dependencies even when opaque syntax prevents an exhaustive harvest.
|
|
91
92
|
for (const { name, node } of harvestCommands(sourceCode, {
|
|
92
93
|
transparentWrappers,
|
|
93
|
-
}).values()) {
|
|
94
|
+
}).commands.values()) {
|
|
94
95
|
if (declared.has(name))
|
|
95
96
|
continue;
|
|
96
97
|
context.report({
|
|
@@ -189,11 +189,16 @@ export const noUnusedDeclarations = createRule({
|
|
|
189
189
|
const removeDeclaration = convention.removeDeclaration?.bind(convention);
|
|
190
190
|
return {
|
|
191
191
|
File() {
|
|
192
|
-
const
|
|
192
|
+
const inventory = sourceCode.getCommandInventory();
|
|
193
|
+
// Opaque syntax may use any declaration, so absence cannot justify deletion.
|
|
194
|
+
if (inventory.uncertainties.length > 0) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const sites = inventory.commands;
|
|
193
198
|
if (sites.some((site) => runsUnknownCode(site, completenessWrappers)))
|
|
194
199
|
return;
|
|
195
200
|
const used = new Set();
|
|
196
|
-
for (const name of harvestCommands(sourceCode, { transparentWrappers }).keys()) {
|
|
201
|
+
for (const name of harvestCommands(sourceCode, { transparentWrappers }).commands.keys()) {
|
|
197
202
|
for (const each of namesFor(name))
|
|
198
203
|
used.add(each);
|
|
199
204
|
}
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
* autofix, because a script may rely on the splitting (for example
|
|
39
39
|
* `$CFLAGS` holding several flags), and only its author can say so.
|
|
40
40
|
*/
|
|
41
|
-
import { DashHdoc, Hdoc } from 'sh-ast
|
|
41
|
+
import { DashHdoc, Hdoc } from 'sh-ast';
|
|
42
42
|
import { createRule } from './create-rule.js';
|
|
43
43
|
import { isBashIntegerVariable } from './bash-variable-semantics.js';
|
|
44
44
|
import { messageExcerpt } from '../language/line-breaks.js';
|
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
* `git` counts only for the subcommands that talk to a remote (`fetch`,
|
|
14
14
|
* `clone`, `pull`, `push`), found after git's own global options
|
|
15
15
|
* (`git -C dir fetch`).
|
|
16
|
+
*
|
|
17
|
+
* This policy checks represented, statically identified commands. Opaque executable
|
|
18
|
+
* syntax is outside that named-command scope; no-dynamic-invocation reports those
|
|
19
|
+
* inventory limits when a project requires execution completeness.
|
|
16
20
|
*/
|
|
17
21
|
import { configurationMessage } from '../configuration-message.js';
|
|
18
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
22
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
19
23
|
import { createRule } from './create-rule.js';
|
|
20
24
|
import { WRAPPER_RULE_MESSAGES, buildWrapperRule } from './create-wrapper-rule.js';
|
|
21
25
|
import { networkWrapperSpec, readNetworkWrapperSetting, sameWrapperSpec, } from './resolve-network-wrapper.js';
|
|
@@ -186,9 +190,11 @@ const STRING_LIST_SCHEMA = {
|
|
|
186
190
|
};
|
|
187
191
|
/**
|
|
188
192
|
* The JSON-expressible form of a `WrapperSpec`, for the `wrapper` option.
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* `
|
|
193
|
+
* Assignment-like operands are skipped only under an explicit
|
|
194
|
+
* `assignmentOperands` grammar (`shell-identifier`, `env`, or `sudo`);
|
|
195
|
+
* omission leaves them available as command candidates. `noArgFlagPattern`
|
|
196
|
+
* is a `RegExp`, so a rule pack needing a flag pattern binds its wrapper
|
|
197
|
+
* with `createWrapperRule` instead of JSON configuration.
|
|
192
198
|
*/
|
|
193
199
|
const WRAPPER_SPEC_SCHEMA = {
|
|
194
200
|
type: 'object',
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
* that here-document's terminator and would carry the other command into the
|
|
31
31
|
* guard.
|
|
32
32
|
*/
|
|
33
|
-
import { DashHdoc, Hdoc } from 'sh-ast
|
|
33
|
+
import { DashHdoc, Hdoc } from 'sh-ast';
|
|
34
34
|
import { createRule } from './create-rule.js';
|
|
35
35
|
import { lineBreakOf } from '../language/line-breaks.js';
|
|
36
36
|
/** Registry name of this rule. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WrapperSpec } from 'sh-
|
|
1
|
+
import type { WrapperSpec } from 'sh-analysis';
|
|
2
2
|
/**
|
|
3
3
|
* Checks a configured value and returns it typed: a non-empty command name,
|
|
4
4
|
* or a `WrapperSpec` object made of the JSON-expressible fields.
|
|
@@ -16,7 +16,7 @@ export declare function readNetworkWrapperSetting(settings: Readonly<Record<stri
|
|
|
16
16
|
/**
|
|
17
17
|
* The `WrapperSpec` for the network wrapper set in `settings.sh.networkWrapper`,
|
|
18
18
|
* for a rule that looks through wrappers, or `null` when none is set. A name
|
|
19
|
-
* that is one of `sh-
|
|
19
|
+
* that is one of `sh-analysis`'s default wrappers (`timeout`) keeps that
|
|
20
20
|
* entry's known options; any other name is a wrapper with no options.
|
|
21
21
|
*
|
|
22
22
|
* @internal
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* A network wrapper also supplies a transparent-wrapper fact to every consumer.
|
|
4
4
|
*/
|
|
5
5
|
import { configurationMessage } from '../configuration-message.js';
|
|
6
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
6
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
7
7
|
/** The setting's dotted path, as error messages name it. */
|
|
8
8
|
const SETTING = 'settings.sh.networkWrapper';
|
|
9
9
|
/**
|
|
@@ -90,7 +90,7 @@ export function readNetworkWrapperSetting(settings) {
|
|
|
90
90
|
/**
|
|
91
91
|
* The `WrapperSpec` for the network wrapper set in `settings.sh.networkWrapper`,
|
|
92
92
|
* for a rule that looks through wrappers, or `null` when none is set. A name
|
|
93
|
-
* that is one of `sh-
|
|
93
|
+
* that is one of `sh-analysis`'s default wrappers (`timeout`) keeps that
|
|
94
94
|
* entry's known options; any other name is a wrapper with no options.
|
|
95
95
|
*
|
|
96
96
|
* @internal
|
|
@@ -106,11 +106,11 @@ export function networkWrapperSpec(settings) {
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
* Canonical effective grammar from sh-
|
|
109
|
+
* Canonical effective grammar from sh-analysis's WrapperSpec matcher, excluding
|
|
110
110
|
* the names that select it. Flags are membership sets; omitted lists are empty,
|
|
111
111
|
* shellBuiltin defaults to false (utility matching), and positional count
|
|
112
|
-
* defaults to zero.
|
|
113
|
-
*
|
|
112
|
+
* defaults to zero. Assignment operands require an explicit grammar; absence
|
|
113
|
+
* means every operand remains available as a command candidate.
|
|
114
114
|
*
|
|
115
115
|
* Expanded built-ins may contain a flag pattern even though JSON settings may
|
|
116
116
|
* not. Compare its source and flags structurally, including absence, rather
|
|
@@ -127,7 +127,7 @@ function canonicalWrapperGrammar(spec) {
|
|
|
127
127
|
stopsChainFlags: flags(spec.stopsChainFlags),
|
|
128
128
|
shellBuiltin: spec.shellBuiltin ?? false,
|
|
129
129
|
positionalOperandsBeforeCommand: spec.positionalOperandsBeforeCommand ?? 0,
|
|
130
|
-
assignmentOperands: spec.assignmentOperands ??
|
|
130
|
+
assignmentOperands: spec.assignmentOperands ?? null,
|
|
131
131
|
noArgFlagPattern: pattern === undefined ? null : { source: pattern.source, flags: pattern.flags },
|
|
132
132
|
});
|
|
133
133
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SettingsConfig } from '@eslint/core';
|
|
2
|
-
import type { WrapperSpec } from 'sh-
|
|
2
|
+
import type { WrapperSpec } from 'sh-analysis';
|
|
3
3
|
import type { ShellSourceCode } from '../language/shell-source-code.js';
|
|
4
4
|
/** The rule-context fields needed to resolve shared wrappers and their path spellings. @public */
|
|
5
5
|
export interface TransparentWrappersBindingContext {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* ESLINT_SH_WRAPPER_SETTING rejects malformed bindings; ESLINT_SH_WRAPPER_CONFLICT rejects contradictory shared facts instead of choosing a policy by list order.
|
|
8
8
|
*/
|
|
9
9
|
import { configurationMessage } from '../configuration-message.js';
|
|
10
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
10
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
11
11
|
import { networkWrapperSpec, sameWrapperOptions, validateWrapperSetting, } from './resolve-network-wrapper.js';
|
|
12
12
|
/** The user-written setting path, extended with indices and fields in configuration errors. */
|
|
13
13
|
const SETTING = 'settings.sh.transparentWrappers';
|
|
@@ -89,7 +89,7 @@ export function resolveTransparentWrappers(context, builtIns = DEFAULT_TRANSPARE
|
|
|
89
89
|
// Relative utility paths need exact aliases in sh-ast. Derive them only from
|
|
90
90
|
// static argv words in this file; no path is resolved or executed here.
|
|
91
91
|
const paths = new Map();
|
|
92
|
-
for (const site of context.sourceCode.
|
|
92
|
+
for (const site of context.sourceCode.getCommandInventory().commands) {
|
|
93
93
|
for (const word of site.argv) {
|
|
94
94
|
if (!word.static || !word.text.includes('/') || paths.has(word.text)) {
|
|
95
95
|
continue;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Wrapper data that built-in rules add to `sh-
|
|
2
|
+
* Wrapper data that built-in rules add to `sh-analysis`'s
|
|
3
3
|
* `DEFAULT_TRANSPARENT_WRAPPERS` when they ask
|
|
4
4
|
* `ShellSourceCode.resolveInvokedCommand` which command an invocation runs.
|
|
5
5
|
*
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
* find the word a wrapper runs. No rule logic lives here, and no entry makes
|
|
8
8
|
* a safety judgment. Each rule decides which of these entries it follows.
|
|
9
9
|
*/
|
|
10
|
-
import type { WrapperSpec } from 'sh-
|
|
10
|
+
import type { WrapperSpec } from 'sh-analysis';
|
|
11
11
|
/**
|
|
12
12
|
* Bash's `builtin [shell-builtin [args …]]`: runs the named builtin, bypassing
|
|
13
13
|
* any function of the same name. It takes no options of its own, so the word
|
|
14
14
|
* after it is the command it runs. Only the exact builtin name has these
|
|
15
15
|
* semantics; an executable path with the same basename is an ordinary program.
|
|
16
16
|
*
|
|
17
|
-
* `sh-
|
|
17
|
+
* `sh-analysis`'s default wrapper table leaves `builtin` out, so
|
|
18
18
|
* `builtin "$x"` would otherwise resolve to the static command `builtin`.
|
|
19
19
|
*
|
|
20
20
|
* @see https://www.gnu.org/software/bash/manual/bash.html#Bash-Builtins — `builtin`
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* after it is the command it runs. Only the exact builtin name has these
|
|
5
5
|
* semantics; an executable path with the same basename is an ordinary program.
|
|
6
6
|
*
|
|
7
|
-
* `sh-
|
|
7
|
+
* `sh-analysis`'s default wrapper table leaves `builtin` out, so
|
|
8
8
|
* `builtin "$x"` would otherwise resolve to the static command `builtin`.
|
|
9
9
|
*
|
|
10
10
|
* @see https://www.gnu.org/software/bash/manual/bash.html#Bash-Builtins — `builtin`
|
|
@@ -24,7 +24,7 @@ project's `"type"` field.
|
|
|
24
24
|
## 1. Pick a selector from the cookbook
|
|
25
25
|
|
|
26
26
|
The cookbook's `:command` [launch class](./selectors.md#the-six-launch-classes) matches
|
|
27
|
-
`CallExpr` nodes with a command word, exactly the calls in `sourceCode.
|
|
27
|
+
`CallExpr` nodes with a command word, exactly the calls in `sourceCode.getCommandInventory().commands`.
|
|
28
28
|
An assignment-only statement such as `FOO=1` does not match; `FOO=1 jq .`, `true`, `:`, and
|
|
29
29
|
dynamic invocations such as `"$tool" file` do. Select `CallExpr` directly to include
|
|
30
30
|
assignment-only calls. This tutorial's rule listens on `:command`; `create()` then narrows further
|
|
@@ -57,7 +57,7 @@ selector-first ESLint rule.
|
|
|
57
57
|
* domain-specific check).
|
|
58
58
|
*
|
|
59
59
|
* Flag words are resolved with `context.sourceCode.resolveWord`
|
|
60
|
-
* (backed by `sh-
|
|
60
|
+
* (backed by `sh-analysis`) rather than a
|
|
61
61
|
* hand-rolled scan: a word is only treated as a short-option cluster
|
|
62
62
|
* when it is *statically* that string (bare or
|
|
63
63
|
* quoted literal concatenations). Recursive (`r`/`R`) and force (`f`)
|
|
@@ -222,8 +222,9 @@ this package's test suite against a real `eslint` `Linter.verify()` run (not a h
|
|
|
222
222
|
|
|
223
223
|
The `:command` listener above sees one `CallExpr` at a time. Some rules need every command in the
|
|
224
224
|
file together with how each one is reached: inside which function, inside `$(…)`, in which
|
|
225
|
-
pipeline stage. `context.sourceCode.
|
|
226
|
-
source order, from `enumerateCommands` (in
|
|
225
|
+
pipeline stage. `context.sourceCode.getCommandInventory().commands` returns that list, one entry per command in
|
|
226
|
+
source order, from `enumerateCommands` (in `sh-analysis`). This is the represented-command collection,
|
|
227
|
+
not a completeness claim; inspect `getCommandInventory().uncertainties` for opaque boundaries. Each
|
|
227
228
|
entry has:
|
|
228
229
|
|
|
229
230
|
- `node`: the `CallExpr` node, the same object a `CallExpr` listener receives, so you can report
|
|
@@ -251,7 +252,7 @@ An assignment-only statement such as `FOO=1` runs no command and has no entry.
|
|
|
251
252
|
* It reports `curl` run anywhere inside a shell function, including through a
|
|
252
253
|
* wrapper (`sudo curl …`) or inside a command substitution in that function.
|
|
253
254
|
* Instead of tracking "am I inside a function?" while visiting nodes, it reads
|
|
254
|
-
* every command once from `context.sourceCode.
|
|
255
|
+
* every command once from `context.sourceCode.getCommandInventory().commands`, whose
|
|
255
256
|
* `context` frames (outermost first) already say how each command is reached.
|
|
256
257
|
*
|
|
257
258
|
* @see ../custom-rule-tutorial.md — the tutorial this rule backs
|
|
@@ -272,7 +273,7 @@ const noCurlInFunctions = defineShellRule({
|
|
|
272
273
|
create(context) {
|
|
273
274
|
return {
|
|
274
275
|
File() {
|
|
275
|
-
for (const site of context.sourceCode.
|
|
276
|
+
for (const site of context.sourceCode.getCommandInventory().commands) {
|
|
276
277
|
const { effective } = site.resolveInvokedCommand();
|
|
277
278
|
if (!effective.static || effective.text !== 'curl') {
|
|
278
279
|
continue;
|
|
@@ -404,29 +405,28 @@ it reports once, on line 1 from column 13 to column 15: exactly the `&&`. A plai
|
|
|
404
405
|
|
|
405
406
|
## 7. Using sh-ast's own operations and types
|
|
406
407
|
|
|
407
|
-
The records `getSyntax` returns
|
|
408
|
-
types
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
`getPrintedReplacement`, which refuses these values with `TypeError`.
|
|
408
|
+
The records `getSyntax` returns belong to `sh-ast`. Install and import raw parser operations,
|
|
409
|
+
syntax types and constants from `sh-ast`; import reusable analysis from `sh-analysis`:
|
|
410
|
+
|
|
411
|
+
```ts
|
|
412
|
+
import { walk, printSync, type Node, type PrintOptions } from 'sh-ast';
|
|
413
|
+
import { enumerateCommands, resolveArgv0, type CommandInventory } from 'sh-analysis';
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
The supported dependency ranges are `sh-ast@^0.11.0` and `sh-analysis@^0.1.0`.
|
|
417
|
+
There are no plugin or umbrella syntax forwarding subpaths. Keep using source helpers when you
|
|
418
|
+
need ESLint nodes, UTF-16 locations or fixes: they map the original syntax by identity.
|
|
419
|
+
|
|
420
|
+
`getCommandInventory()` exposes both `commands` and `uncertainties`. The examples here
|
|
421
|
+
report only named, represented commands. They do not establish that a file runs no other code.
|
|
422
|
+
An uncertainty such as `opaque-zsh-subscript` retains the original `FlagsArithm` view and its
|
|
423
|
+
context; raw text is not reparsed as another shell grammar. A security policy requiring all
|
|
424
|
+
execution to be reviewable must handle those boundaries. The built-in
|
|
425
|
+
`no-dynamic-invocation` reports them even in an allowed dispatcher function, and
|
|
426
|
+
`no-unused-declarations` declines deletion whenever they exist.
|
|
427
|
+
|
|
428
|
+
Raw `printSync` preserves the selected Go printer's behavior. Prefer
|
|
429
|
+
`getPrintedReplacement` for checked source edits, including its text-content safeguards.
|
|
430
430
|
|
|
431
431
|
## 8. Printed fixes
|
|
432
432
|
|
|
@@ -463,7 +463,7 @@ into an ESLint fix:
|
|
|
463
463
|
* new text with `getPrintedReplacement`. The original syntax every other rule
|
|
464
464
|
* reads stays unchanged.
|
|
465
465
|
*
|
|
466
|
-
* @import { PrintOptions } from '
|
|
466
|
+
* @import { PrintOptions } from 'sh-ast'
|
|
467
467
|
* @see ../custom-rule-tutorial.md — the tutorial this rule backs
|
|
468
468
|
*/
|
|
469
469
|
import { defineShellRule } from '@eslint-sh/eslint-plugin';
|
|
@@ -550,12 +550,12 @@ out the statement's own leading and trailing comments, which lie outside its ran
|
|
|
550
550
|
hand-formatted construct, step 9's position-based text edit is the better tool.
|
|
551
551
|
|
|
552
552
|
`PrintOptions`, `Node` and the record types (`CmdSubst`, `Word`, …) are the types of
|
|
553
|
-
|
|
553
|
+
`sh-ast` (step 7), and so is `printSync`, if you want to print a record
|
|
554
554
|
yourself, for example to compare it with the source before reporting:
|
|
555
555
|
|
|
556
556
|
```ts
|
|
557
|
-
import { printSync } from '
|
|
558
|
-
import type { Node, PrintOptions } from '
|
|
557
|
+
import { printSync } from 'sh-ast';
|
|
558
|
+
import type { Node, PrintOptions } from 'sh-ast';
|
|
559
559
|
```
|
|
560
560
|
|
|
561
561
|
## 9. Position-based text edits
|
|
@@ -686,7 +686,7 @@ TypeScript rule needs no `@eslint/core` import and no rule types of its own:
|
|
|
686
686
|
- `defineShellRule<Options, MessageIds>(…)` takes the options tuple and message ids as type
|
|
687
687
|
arguments, or infers the message ids from `meta.messages` when you leave them out. Either way,
|
|
688
688
|
`context.options` has your options' type, and `context.report` accepts only declared message ids.
|
|
689
|
-
- `context.sourceCode` is `ShellSourceCode`, so `
|
|
689
|
+
- `context.sourceCode` is `ShellSourceCode`, so `getCommandInventory().commands`, `getSyntax()` and the other
|
|
690
690
|
helpers are typed without a cast, and a listener keyed by a node type (`CallExpr`, `Word:exit`)
|
|
691
691
|
receives that node type, so its fields (`args`, `parts`, `cmd`, …) are typed; other selectors
|
|
692
692
|
receive `ShellNode`, which you narrow on `type`. See [Reading nodes](./reading-nodes.md).
|
|
@@ -755,7 +755,7 @@ const noListedCommands = defineShellRule<Options, 'listed'>({
|
|
|
755
755
|
const listed = new Set(context.options[0]?.commands ?? []);
|
|
756
756
|
return {
|
|
757
757
|
File() {
|
|
758
|
-
for (const site of context.sourceCode.
|
|
758
|
+
for (const site of context.sourceCode.getCommandInventory().commands) {
|
|
759
759
|
reportIfListed(context, site, listed);
|
|
760
760
|
}
|
|
761
761
|
},
|