|
1 | 1 | // Catches: the simctl scope bypasses `tsc` cannot reject. `runXcrun` accepts only a |
2 | 2 | // `ScopedSimctlCommand` or a named non-simctl tool, but the plain executors (`runCmd`, |
3 | 3 | // `runCmdBackground`, an `executable: 'xcrun'` spec) take any string argv, so every simctl argv |
4 | | -// reaching them must be builder output. (1) An array whose first element names simctl (the |
5 | | -// literal, a quasi-only template, or a same-file binding of either) outside the brand mints, |
6 | | -// however it later travels: inline, held in a variable, aliased or spread. (2) At an xcrun |
| 4 | +// reaching them must be builder output. (1) An array whose tool names simctl (the literal, a |
| 5 | +// quasi-only template, or a same-file binding of either; the first element, or any element |
| 6 | +// after leading xcrun options such as `--sdk`) outside the brand mints, however it later |
| 7 | +// travels: inline, held in a variable, aliased or spread. (2) At an xcrun |
7 | 8 | // invocation, an inline argv whose tool is not a string literal other than `simctl`. (3) A cast |
8 | 9 | // to `ScopedSimctlArgs`, `ScopedSimctlCommand` or `SimulatorAddress` outside the brand mints. |
9 | 10 | // Every form runs against the default CoreSimulator set: `Invalid device` for a simulator in a |
|
12 | 13 | // fold HID helper (`foldable/simulator-hid.ts`) built `['simctl', 'spawn', udid, ...]` from a |
13 | 14 | // bare udid and lost the set; #2824 moved every call site onto `core/simctl.ts` and checked it |
14 | 15 | // with a manual `git grep "'--set'"`. |
15 | | -// Cost: 300 LOC (159 rule + 141 test). |
| 16 | +// Cost: 311 LOC (167 rule + 144 test). |
16 | 17 | // Kill criterion: none enforced today; retire only by maintainer decision that scoped simulator |
17 | 18 | // sets (`--ios-simulator-device-set`) are no longer supported, or when no production xcrun |
18 | 19 | // executor takes a plain string argv. |
@@ -61,12 +62,14 @@ export function appleSimulatorScopeViolations( |
61 | 62 | const program = parseSync(file, source).program; |
62 | 63 | const simctlBindings = simctlNameBindings(program); |
63 | 64 | const isMint = BRAND_MINTS.has(file); |
| 65 | + const isSimctl = (element: AstNode | null) => |
| 66 | + namesSimctl(element ?? undefined) || |
| 67 | + (element?.type === 'Identifier' && simctlBindings.has(element.name)); |
64 | 68 | const buildsSimctlArgv = (array: AstNode) => { |
65 | | - const tool = firstElement(array); |
66 | | - return ( |
67 | | - !isMint && |
68 | | - (namesSimctl(tool) || (tool?.type === 'Identifier' && simctlBindings.has(tool.name))) |
69 | | - ); |
| 69 | + if (isMint) return false; |
| 70 | + const elements = array.elements as (AstNode | null)[]; |
| 71 | + const [tool] = elements; |
| 72 | + return isSimctl(tool ?? null) || (isXcrunOption(tool) && elements.some(isSimctl)); |
70 | 73 | }; |
71 | 74 | const report = (node: AstNode, message: string) => |
72 | 75 | violations.push({ rule: RULE, file, line: lineAt(source, node.start), message }); |
@@ -109,6 +112,11 @@ function namesNonSimctlTool(argv: AstNode): boolean { |
109 | 112 | return tool?.type === 'Literal' && typeof tool.value === 'string' && tool.value !== 'simctl'; |
110 | 113 | } |
111 | 114 |
|
| 115 | +/** A leading `-` literal is an xcrun option (`--sdk`, `--find`), so the tool name comes later. */ |
| 116 | +function isXcrunOption(node: AstNode | null | undefined): boolean { |
| 117 | + return node?.type === 'Literal' && typeof node.value === 'string' && node.value.startsWith('-'); |
| 118 | +} |
| 119 | + |
112 | 120 | function firstElement(array: AstNode): AstNode | undefined { |
113 | 121 | return (array.elements as (AstNode | null)[])[0] ?? undefined; |
114 | 122 | } |
|
0 commit comments