@eslint-sh/eslint-plugin 0.9.0 → 0.10.1
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 +71 -60
- 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 +31 -47
- package/dist/language/shell-source-code.js +47 -62
- package/dist/language/syntax-clone.d.ts +29 -0
- package/dist/language/syntax-clone.js +76 -0
- package/dist/language/syntax-view.d.ts +23 -2
- package/dist/language/syntax-view.js +166 -33
- 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 +5 -3
- package/dist/rules/compat/no-wait-n.js +2 -2
- package/dist/rules/compat/nounset-array-proof.js +16 -9
- 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.d.ts +12 -0
- package/dist/rules/no-masked-exit-status.js +27 -17
- package/dist/rules/no-secret-env-reads.js +1 -1
- package/dist/rules/no-unchecked-cd.js +28 -21
- package/dist/rules/no-undeclared-commands.js +2 -1
- package/dist/rules/no-unused-declarations.js +7 -2
- package/dist/rules/prefer-local.js +10 -8
- 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 +12 -23
- 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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep copy of sh-ast syntax records that does not recurse once per tree level.
|
|
3
|
+
*
|
|
4
|
+
* `structuredClone` recurses natively, so V8 overflows its stack on a record
|
|
5
|
+
* graph nested a thousand or so levels deep, such as the left-nested records of
|
|
6
|
+
* a long `a && b && …` list. {@link cloneSyntax} gives the same result for the
|
|
7
|
+
* values a syntax tree is made of, walking the graph with an explicit work list
|
|
8
|
+
* so depth costs heap, not call stack.
|
|
9
|
+
*/
|
|
10
|
+
/** Whether `value` is an ordinary object or array, the containers a syntax tree is built from. */
|
|
11
|
+
function isContainer(value) {
|
|
12
|
+
return Array.isArray(value) || Object.prototype.toString.call(value) === '[object Object]';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns an independent deep copy of `value` with `structuredClone`'s
|
|
16
|
+
* semantics for syntax records: plain objects and arrays are copied entry by
|
|
17
|
+
* entry (own enumerable string keys, array holes and length preserved),
|
|
18
|
+
* `Uint8Array` byte strings are copied into fresh memory (a `Buffer` or an
|
|
19
|
+
* offset view does not share storage with the copy), a record reachable twice
|
|
20
|
+
* is copied once so shared and cyclic references keep their shape, and
|
|
21
|
+
* prototypes are not carried over. A function or symbol value fails with
|
|
22
|
+
* `structuredClone`'s `DataCloneError`.
|
|
23
|
+
*
|
|
24
|
+
* Supported input is what sh-ast records contain: plain objects, arrays,
|
|
25
|
+
* primitives and `Uint8Array`s. Any other object is handed to `structuredClone`
|
|
26
|
+
* as a whole, so a `Map` or `Set` is copied by it (records shared with the
|
|
27
|
+
* surrounding graph are duplicated) and a `Proxy` is copied as a plain object.
|
|
28
|
+
*
|
|
29
|
+
* No depth limit applies other than available memory.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export function cloneSyntax(value) {
|
|
34
|
+
const copies = new Map();
|
|
35
|
+
// eslint-disable-next-line @api-extractor-tools/forgotten-export -- The work-list entry type is private to this function.
|
|
36
|
+
const pending = [];
|
|
37
|
+
const copyOf = (item) => {
|
|
38
|
+
if (typeof item === 'symbol') {
|
|
39
|
+
// Same refusal, and error type, as structuredClone.
|
|
40
|
+
return structuredClone(item);
|
|
41
|
+
}
|
|
42
|
+
if (item === null || (typeof item !== 'object' && typeof item !== 'function')) {
|
|
43
|
+
return item;
|
|
44
|
+
}
|
|
45
|
+
const known = copies.get(item);
|
|
46
|
+
if (known !== undefined) {
|
|
47
|
+
return known;
|
|
48
|
+
}
|
|
49
|
+
let copy;
|
|
50
|
+
if (typeof item === 'function' || !isContainer(item)) {
|
|
51
|
+
copy = item instanceof Uint8Array ? new Uint8Array(item) : structuredClone(item);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const container = Array.isArray(item)
|
|
55
|
+
? new Array(item.length)
|
|
56
|
+
: {};
|
|
57
|
+
pending.push({ source: item, copy: container });
|
|
58
|
+
copy = container;
|
|
59
|
+
}
|
|
60
|
+
copies.set(item, copy);
|
|
61
|
+
return copy;
|
|
62
|
+
};
|
|
63
|
+
const root = copyOf(value);
|
|
64
|
+
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
|
|
65
|
+
for (const key of Object.keys(next.source)) {
|
|
66
|
+
// defineProperty keeps a key named `__proto__` an ordinary own property.
|
|
67
|
+
Object.defineProperty(next.copy, key, {
|
|
68
|
+
value: copyOf(next.source[key]),
|
|
69
|
+
writable: true,
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return root;
|
|
76
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { File, Node as SyntaxNode, PositionSnapshot } from 'sh-ast';
|
|
2
|
-
import type { WordResolution } from 'sh-
|
|
2
|
+
import type { WordResolution } from 'sh-analysis';
|
|
3
3
|
import type { ShellNodeMap, ShellNodeOf, ShellNodeType } from './lint-view-types.js';
|
|
4
4
|
import { SourceCoordinates } from './source-coordinates.js';
|
|
5
5
|
/**
|
|
@@ -77,5 +77,26 @@ export declare function adaptSyntaxFile(file: File, source: string, positions: P
|
|
|
77
77
|
* @internal
|
|
78
78
|
*/
|
|
79
79
|
export declare function childNodes(node: ShellNode): ShellNode[];
|
|
80
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Visits `root` and every projected descendant depth-first in visitor-key order
|
|
82
|
+
* with an explicit stack, so a left-nested chain of any length costs heap, not
|
|
83
|
+
* call stack. `enter` runs before a node's children and `exit` after the last of
|
|
84
|
+
* them, each with the node and its parent (`undefined` for `root`). Every
|
|
85
|
+
* consumer traversal of the lint view goes through here; it makes no claim to
|
|
86
|
+
* upstream Walk control semantics.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export declare function traverseShell(root: ShellNode, handlers: {
|
|
90
|
+
readonly enter?: (node: ShellNode, parent: ShellNode | undefined) => void;
|
|
91
|
+
readonly exit?: (node: ShellNode, parent: ShellNode | undefined) => void;
|
|
92
|
+
}): void;
|
|
93
|
+
/** Visits `root` and every projected descendant in pre-order, including auxiliary views. @internal */
|
|
81
94
|
export declare function walkShell(root: ShellNode, visit: (node: ShellNode) => void): void;
|
|
95
|
+
/**
|
|
96
|
+
* Whether `test` holds for `root` or any projected descendant, searching
|
|
97
|
+
* depth-first in pre-order with an explicit stack and stopping at the first
|
|
98
|
+
* `true`. Returning `'skip'` leaves that node's descendants unsearched without
|
|
99
|
+
* ending the search. `test` must not depend on visiting order beyond that.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
export declare function someShellNode(root: ShellNode, test: (node: ShellNode) => boolean | 'skip'): boolean;
|
|
@@ -62,6 +62,8 @@ export const shellVisitorKeys = Object.freeze(Object.fromEntries(Object.entries(
|
|
|
62
62
|
.filter(([, field]) => field.kind === 'struct' || field.kind === 'interface')
|
|
63
63
|
.map(([fieldName]) => fieldName.toLowerCase())),
|
|
64
64
|
])));
|
|
65
|
+
/** Marks that a projection frame has no further child records to project. */
|
|
66
|
+
const FIELDS_DONE = Symbol('fieldsDone');
|
|
65
67
|
/** Checks record identity without pretending unknown transport values already have syntax types. */
|
|
66
68
|
function isRecord(value) {
|
|
67
69
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -192,8 +194,9 @@ export function adaptSyntaxFile(file, source, positions) {
|
|
|
192
194
|
const position = (raw, fallback) => raw.IsValid && !raw.IsRecovered ? coordinates.fromByteOffset(raw.Offset) : fallback;
|
|
193
195
|
/** Comment views in projection order; registered against the root once projection succeeds. */
|
|
194
196
|
const comments = [];
|
|
195
|
-
/**
|
|
196
|
-
|
|
197
|
+
/** Validates `raw`, observes its span and opens a frame for projecting its fields. */
|
|
198
|
+
// eslint-disable-next-line @api-extractor-tools/forgotten-export -- The frame type belongs only to the private projection closure, not the exported signature.
|
|
199
|
+
const openFrame = (raw, fallback) => {
|
|
197
200
|
if (!isRecord(raw) || typeof raw.Type !== 'string') {
|
|
198
201
|
throw Object.assign(new TypeError('shell view expected a known upstream syntax record'), {
|
|
199
202
|
code: 'ESLINT_SH_SYNTAX_VIEW',
|
|
@@ -206,7 +209,6 @@ export function adaptSyntaxFile(file, source, positions) {
|
|
|
206
209
|
});
|
|
207
210
|
}
|
|
208
211
|
const realNode = isSyntaxNode(raw);
|
|
209
|
-
// eslint-disable-next-line @api-extractor-tools/forgotten-export -- This span belongs only to the private projection closure, not the exported signature.
|
|
210
212
|
let span = fallback;
|
|
211
213
|
// Whether this node's span lost a CRLF carriage return (see `endsBeforeCrlfNewline`).
|
|
212
214
|
let trimmedCarriageReturn = false;
|
|
@@ -225,50 +227,90 @@ export function adaptSyntaxFile(file, source, positions) {
|
|
|
225
227
|
crlfTrimmedViews.add(raw);
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
230
|
+
return {
|
|
231
|
+
raw,
|
|
232
|
+
plan,
|
|
233
|
+
realNode,
|
|
234
|
+
span,
|
|
235
|
+
trimmedCarriageReturn,
|
|
236
|
+
// Schema fields first, in schema order, then `type`, `range` and `loc`.
|
|
237
|
+
view: {},
|
|
238
|
+
childStart: Number.POSITIVE_INFINITY,
|
|
239
|
+
childEnd: Number.NEGATIVE_INFINITY,
|
|
240
|
+
fieldIndex: 0,
|
|
241
|
+
sliceItems: undefined,
|
|
242
|
+
sliceIndex: 0,
|
|
243
|
+
sliceOut: [],
|
|
244
|
+
awaitingKey: undefined,
|
|
241
245
|
};
|
|
242
|
-
|
|
246
|
+
};
|
|
247
|
+
/** Records a projected child's extent; auxiliary records take their span from it. */
|
|
248
|
+
const include = (frame, child) => {
|
|
249
|
+
if (child.range[0] < frame.childStart) {
|
|
250
|
+
frame.childStart = child.range[0];
|
|
251
|
+
}
|
|
252
|
+
if (child.range[1] > frame.childEnd) {
|
|
253
|
+
frame.childEnd = child.range[1];
|
|
254
|
+
}
|
|
255
|
+
return child;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Advances `frame` through its plan until it needs a child record projected,
|
|
259
|
+
* and returns that record; `FIELDS_DONE` means every field is done (a missing
|
|
260
|
+
* child record is `undefined` and must still reach `openFrame` to be refused). Scalar fields
|
|
261
|
+
* are filled in as they are passed.
|
|
262
|
+
*/
|
|
263
|
+
const nextChild = (frame) => {
|
|
264
|
+
const { raw, plan, view } = frame;
|
|
265
|
+
while (frame.fieldIndex < plan.length) {
|
|
266
|
+
const field = plan[frame.fieldIndex];
|
|
243
267
|
const value = raw[field.name];
|
|
244
268
|
if (field.kind === 'child') {
|
|
245
269
|
if (field.slice) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
270
|
+
if (frame.sliceItems === undefined) {
|
|
271
|
+
const items = value === null ? [] : value;
|
|
272
|
+
if (!Array.isArray(items)) {
|
|
273
|
+
throw Object.assign(new TypeError(`shell view expected ${raw.Type}.${field.name} to be a slice`), { code: 'ESLINT_SH_SYNTAX_VIEW' });
|
|
274
|
+
}
|
|
275
|
+
frame.sliceItems = items;
|
|
276
|
+
frame.sliceIndex = 0;
|
|
277
|
+
frame.sliceOut = [];
|
|
249
278
|
}
|
|
250
|
-
|
|
251
|
-
|
|
279
|
+
while (frame.sliceIndex < frame.sliceItems.length) {
|
|
280
|
+
const item = frame.sliceItems[frame.sliceIndex++];
|
|
252
281
|
if (item !== null) {
|
|
253
|
-
|
|
282
|
+
return item;
|
|
254
283
|
}
|
|
255
284
|
}
|
|
256
|
-
view[field.key] =
|
|
285
|
+
view[field.key] = frame.sliceOut;
|
|
286
|
+
frame.sliceItems = undefined;
|
|
257
287
|
}
|
|
258
288
|
else if (value !== null) {
|
|
259
|
-
|
|
289
|
+
frame.awaitingKey = field.key;
|
|
290
|
+
frame.fieldIndex++;
|
|
291
|
+
return value;
|
|
260
292
|
}
|
|
261
293
|
}
|
|
262
294
|
else {
|
|
263
295
|
const text = field.kind === 'text' ? sourceText(value) : value;
|
|
264
296
|
view[field.key] =
|
|
265
|
-
trimmedCarriageReturn && typeof text === 'string' && text.endsWith('\r')
|
|
297
|
+
frame.trimmedCarriageReturn && typeof text === 'string' && text.endsWith('\r')
|
|
266
298
|
? text.slice(0, -1)
|
|
267
299
|
: text;
|
|
268
300
|
}
|
|
301
|
+
frame.fieldIndex++;
|
|
269
302
|
}
|
|
270
|
-
|
|
271
|
-
|
|
303
|
+
return FIELDS_DONE;
|
|
304
|
+
};
|
|
305
|
+
/** Completes `frame`'s view once every field is projected. */
|
|
306
|
+
const closeFrame = (frame) => {
|
|
307
|
+
const { raw, view } = frame;
|
|
308
|
+
let { span } = frame;
|
|
309
|
+
if (!frame.realNode && frame.childStart !== Number.POSITIVE_INFINITY) {
|
|
310
|
+
span = {
|
|
311
|
+
start: coordinates.atIndex(frame.childStart),
|
|
312
|
+
end: coordinates.atIndex(frame.childEnd),
|
|
313
|
+
};
|
|
272
314
|
}
|
|
273
315
|
view.type = raw.Type;
|
|
274
316
|
view.range = [span.start.index, span.end.index];
|
|
@@ -280,12 +322,54 @@ export function adaptSyntaxFile(file, source, positions) {
|
|
|
280
322
|
if (isShellComment(node)) {
|
|
281
323
|
comments.push(node);
|
|
282
324
|
}
|
|
283
|
-
if (realNode) {
|
|
325
|
+
if (frame.realNode) {
|
|
284
326
|
originalSyntax.set(node, raw);
|
|
285
327
|
views.set(raw, node);
|
|
286
328
|
}
|
|
287
329
|
return node;
|
|
288
330
|
};
|
|
331
|
+
/**
|
|
332
|
+
* Projects `rootRecord` and everything under it with an explicit frame stack,
|
|
333
|
+
* visiting records in the same depth-first, schema-field order a recursive
|
|
334
|
+
* projection would, so errors, comment order and view key order are unchanged.
|
|
335
|
+
* A record that contains itself, directly or through descendants, would never
|
|
336
|
+
* finish projecting, so it is refused; a record reachable twice by different
|
|
337
|
+
* paths is projected once per path, as before.
|
|
338
|
+
*/
|
|
339
|
+
const project = (rootRecord, rootFallback) => {
|
|
340
|
+
const stack = [openFrame(rootRecord, rootFallback)];
|
|
341
|
+
// Records on the path from the root to the frame being projected.
|
|
342
|
+
const active = new Set([stack[0].raw]);
|
|
343
|
+
for (;;) {
|
|
344
|
+
const frame = stack[stack.length - 1];
|
|
345
|
+
const child = nextChild(frame);
|
|
346
|
+
if (child !== FIELDS_DONE) {
|
|
347
|
+
if (typeof child === 'object' && child !== null && active.has(child)) {
|
|
348
|
+
throw Object.assign(new TypeError(`shell view found a ${child.Type} record that contains itself`), { code: 'ESLINT_SH_SYNTAX_VIEW' });
|
|
349
|
+
}
|
|
350
|
+
const opened = openFrame(child, frame.span);
|
|
351
|
+
active.add(opened.raw);
|
|
352
|
+
stack.push(opened);
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const done = closeFrame(frame);
|
|
356
|
+
stack.pop();
|
|
357
|
+
active.delete(frame.raw);
|
|
358
|
+
const parent = stack.length === 0 ? undefined : stack[stack.length - 1];
|
|
359
|
+
if (parent === undefined) {
|
|
360
|
+
return done;
|
|
361
|
+
}
|
|
362
|
+
include(parent, done);
|
|
363
|
+
if (parent.sliceItems !== undefined) {
|
|
364
|
+
parent.sliceOut.push(done);
|
|
365
|
+
}
|
|
366
|
+
else if (parent.awaitingKey !== undefined) {
|
|
367
|
+
// A single child: the parent is waiting on exactly one record for this key.
|
|
368
|
+
parent.view[parent.awaitingKey] = done;
|
|
369
|
+
parent.awaitingKey = undefined;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
};
|
|
289
373
|
const root = project(file, wholeSource);
|
|
290
374
|
if (!isShellFile(root)) {
|
|
291
375
|
throw Object.assign(new TypeError('shell view expected a File with statements'), {
|
|
@@ -322,10 +406,59 @@ export function childNodes(node) {
|
|
|
322
406
|
}
|
|
323
407
|
return children;
|
|
324
408
|
}
|
|
325
|
-
/**
|
|
409
|
+
/**
|
|
410
|
+
* Visits `root` and every projected descendant depth-first in visitor-key order
|
|
411
|
+
* with an explicit stack, so a left-nested chain of any length costs heap, not
|
|
412
|
+
* call stack. `enter` runs before a node's children and `exit` after the last of
|
|
413
|
+
* them, each with the node and its parent (`undefined` for `root`). Every
|
|
414
|
+
* consumer traversal of the lint view goes through here; it makes no claim to
|
|
415
|
+
* upstream Walk control semantics.
|
|
416
|
+
* @internal
|
|
417
|
+
*/
|
|
418
|
+
export function traverseShell(root, handlers) {
|
|
419
|
+
// eslint-disable-next-line @api-extractor-tools/forgotten-export -- The open-node type is private to this function.
|
|
420
|
+
const open = [];
|
|
421
|
+
const enter = (node, parent) => {
|
|
422
|
+
handlers.enter?.(node, parent);
|
|
423
|
+
open.push({ node, parent, children: childNodes(node), next: 0 });
|
|
424
|
+
};
|
|
425
|
+
enter(root, undefined);
|
|
426
|
+
while (open.length > 0) {
|
|
427
|
+
const current = open[open.length - 1];
|
|
428
|
+
if (current.next < current.children.length) {
|
|
429
|
+
enter(current.children[current.next++], current.node);
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
open.pop();
|
|
433
|
+
handlers.exit?.(current.node, current.parent);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/** Visits `root` and every projected descendant in pre-order, including auxiliary views. @internal */
|
|
326
438
|
export function walkShell(root, visit) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
439
|
+
traverseShell(root, { enter: visit });
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Whether `test` holds for `root` or any projected descendant, searching
|
|
443
|
+
* depth-first in pre-order with an explicit stack and stopping at the first
|
|
444
|
+
* `true`. Returning `'skip'` leaves that node's descendants unsearched without
|
|
445
|
+
* ending the search. `test` must not depend on visiting order beyond that.
|
|
446
|
+
* @internal
|
|
447
|
+
*/
|
|
448
|
+
export function someShellNode(root, test) {
|
|
449
|
+
const pending = [root];
|
|
450
|
+
for (let node = pending.pop(); node !== undefined; node = pending.pop()) {
|
|
451
|
+
const verdict = test(node);
|
|
452
|
+
if (verdict === true) {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
if (verdict === 'skip') {
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const children = childNodes(node);
|
|
459
|
+
for (let index = children.length - 1; index >= 0; index--) {
|
|
460
|
+
pending.push(children[index]);
|
|
461
|
+
}
|
|
330
462
|
}
|
|
463
|
+
return false;
|
|
331
464
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ResolveWordOptions, WordResolution } from 'sh-
|
|
1
|
+
import type { ResolveWordOptions, WordResolution } from 'sh-analysis';
|
|
2
2
|
import type { ShellNodeOf } from './syntax-view.js';
|
|
3
3
|
/**
|
|
4
4
|
* Resolves a parsed lint Word using the upstream-shaped syntax associated with it.
|
|
5
|
-
* The view supplies locations and selector fields; sh-
|
|
5
|
+
* The view supplies locations and selector fields; sh-analysis owns the word
|
|
6
6
|
* interpretation. Fabricated or synthetic view nodes have no source syntax and
|
|
7
7
|
* are rejected instead of being treated as known or unknown shell values.
|
|
8
8
|
* A static word that ends a line of a CRLF file resolves without the line
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* ESLINT_SH_WORD_NODE rejects a missing source association; dynamic words
|
|
4
4
|
* remain ordinary analysis results rather than errors.
|
|
5
5
|
*/
|
|
6
|
-
import { resolveWord as resolveSyntaxWord } from 'sh-
|
|
6
|
+
import { resolveWord as resolveSyntaxWord } from 'sh-analysis';
|
|
7
7
|
import { syntaxForNode, withoutCrlfCarriageReturn } from './syntax-view.js';
|
|
8
8
|
/**
|
|
9
9
|
* Resolves a parsed lint Word using the upstream-shaped syntax associated with it.
|
|
10
|
-
* The view supplies locations and selector fields; sh-
|
|
10
|
+
* The view supplies locations and selector fields; sh-analysis owns the word
|
|
11
11
|
* interpretation. Fabricated or synthetic view nodes have no source syntax and
|
|
12
12
|
* are rejected instead of being treated as known or unknown shell values.
|
|
13
13
|
* A static word that ends a line of a CRLF file resolves without the line
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* gating an option `local` shares (`-n`, `-l`, `-u`) adds `local` with
|
|
14
14
|
* {@link DECLARATION_AND_LOCAL_COMMANDS}.
|
|
15
15
|
*/
|
|
16
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
16
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
17
17
|
import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
|
|
18
18
|
import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
|
|
19
19
|
/** The declaration commands that take option clusters. */
|
|
@@ -32,7 +32,7 @@ export const DECLARATION_AND_LOCAL_COMMANDS = new Set([
|
|
|
32
32
|
]);
|
|
33
33
|
/**
|
|
34
34
|
* The wrappers followed to find a declaration command written as an ordinary
|
|
35
|
-
* command: `sh-
|
|
35
|
+
* command: `sh-analysis`'s defaults (which include `command`) plus Bash's
|
|
36
36
|
* `builtin`.
|
|
37
37
|
*/
|
|
38
38
|
const TRANSPARENT_WRAPPERS = [
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
* the whole word, once per word.
|
|
73
73
|
*/
|
|
74
74
|
import { createCompatRule } from './create-compat-rule.js';
|
|
75
|
-
import { DashHdoc, DplIn, DplOut, Hdoc, WordHdoc } from 'sh-ast
|
|
75
|
+
import { DashHdoc, DplIn, DplOut, Hdoc, WordHdoc } from 'sh-ast';
|
|
76
76
|
/** The sequence between braces: two endpoints and an optional step. */
|
|
77
77
|
const SEQUENCE = /^([+-]?\d+|[A-Za-z])\.\.([+-]?\d+|[A-Za-z])(?:\.\.([+-]?\d+))?$/u;
|
|
78
78
|
/**
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* `-t`, which keeps each newline) and POSIX files, which have no arrays at
|
|
28
28
|
* all, get the report without a suggestion.
|
|
29
29
|
*/
|
|
30
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
30
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
31
31
|
import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
|
|
32
32
|
import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
|
|
33
33
|
import { createCompatRule } from './create-compat-rule.js';
|
|
@@ -39,7 +39,7 @@ const DEFAULT_ARRAY = 'MAPFILE';
|
|
|
39
39
|
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
40
40
|
/**
|
|
41
41
|
* The wrappers followed to find the command an invocation runs:
|
|
42
|
-
* `sh-
|
|
42
|
+
* `sh-analysis`'s defaults (which include `command`) plus Bash's
|
|
43
43
|
* `builtin`.
|
|
44
44
|
*/
|
|
45
45
|
const TRANSPARENT_WRAPPERS = [
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
* ordinary word; option words (`-v`) never match an element name.
|
|
29
29
|
*/
|
|
30
30
|
import { Minus } from 'sh-ast';
|
|
31
|
-
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-
|
|
31
|
+
import { DEFAULT_TRANSPARENT_WRAPPERS } from 'sh-analysis';
|
|
32
32
|
import { resolveTransparentWrappers } from '../resolve-transparent-wrappers.js';
|
|
33
33
|
import { BUILTIN_WRAPPER } from '../transparent-wrappers.js';
|
|
34
34
|
import { createCompatRule } from './create-compat-rule.js';
|
|
35
35
|
/** A bare negative-subscript read, the only shape the suggestion rewrites. */
|
|
36
36
|
const BARE_READ = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\[\s*-\s*(\d+)\s*\]\}$/u;
|
|
37
37
|
/**
|
|
38
|
-
* The wrappers followed to find an `unset` command: `sh-
|
|
38
|
+
* The wrappers followed to find an `unset` command: `sh-analysis`'s
|
|
39
39
|
* defaults (which include `command`) plus Bash's `builtin`.
|
|
40
40
|
*/
|
|
41
41
|
const TRANSPARENT_WRAPPERS = [
|
|
@@ -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 = [
|
|
@@ -127,7 +127,9 @@ function variableTestIndices(args) {
|
|
|
127
127
|
return;
|
|
128
128
|
const word = argv[pos];
|
|
129
129
|
if (word === '!') {
|
|
130
|
-
|
|
130
|
+
// A run of negations applies to the one term after it; consume them in a loop.
|
|
131
|
+
while (argv[pos] === '!')
|
|
132
|
+
pos++;
|
|
131
133
|
term();
|
|
132
134
|
return;
|
|
133
135
|
}
|
|
@@ -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 = [
|
|
@@ -504,16 +504,23 @@ export function createArraySafetyProof(source) {
|
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
506
|
/** Entry facts never cross functions or loops; an if condition can prove its then arm. */
|
|
507
|
-
function entry(
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
507
|
+
function entry(first) {
|
|
508
|
+
// The left side of &&/|| runs first and no evidence flows to their right
|
|
509
|
+
// side, so a statement on the left spine of a list has the list's entry facts.
|
|
510
|
+
let stmt = first;
|
|
511
|
+
let parent;
|
|
512
|
+
for (;;) {
|
|
513
|
+
const cached = before.get(stmt);
|
|
514
|
+
if (cached !== undefined) {
|
|
515
|
+
return cached;
|
|
516
|
+
}
|
|
517
|
+
parent = source.getParent(stmt);
|
|
518
|
+
if (parent?.type !== 'BinaryCmd' || parent.x !== stmt)
|
|
519
|
+
break;
|
|
515
520
|
const outer = source.getParent(parent);
|
|
516
|
-
|
|
521
|
+
if (outer?.type !== 'Stmt')
|
|
522
|
+
return UNKNOWN;
|
|
523
|
+
stmt = outer;
|
|
517
524
|
}
|
|
518
525
|
let facts = UNKNOWN;
|
|
519
526
|
if (!variableAttributes &&
|
|
@@ -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
|