|
2 | 2 | * @file Sort all-identifier boolean chains alphanumerically. Per CLAUDE.md |
3 | 3 | * "Sorting" rule, a chain like `agentshieldOk && zizmorOk && sfwOk` reads |
4 | 4 | * with the identifier names in alpha order: `agentshieldOk && sfwOk && |
5 | | - * zizmorOk`. The runtime is short-circuit-insensitive to operand order |
6 | | - * *when every operand is a plain identifier* (no calls, no member access |
7 | | - * with getters) — so reordering doesn't change semantics. Sorting reduces |
8 | | - * diff churn when adding a new flag and makes "is everything ready?" |
9 | | - * checks visually consistent. |
| 5 | + * zizmorOk`. The runtime is short-circuit-insensitive to operand order _when |
| 6 | + * every operand is a plain identifier_ (no calls, no member access with |
| 7 | + * getters) — so reordering doesn't change semantics. Sorting reduces diff |
| 8 | + * churn when adding a new flag and makes "is everything ready?" checks |
| 9 | + * visually consistent. Detects: chains of `&&` or `||` whose operands are ALL |
| 10 | + * bare Identifiers (length ≥ 2, no duplicates, uniform operator across the |
| 11 | + * flattened chain). Skipped (not reported, autofix-safe stays narrow): |
10 | 12 | * |
11 | | - * Detects: chains of `&&` or `||` whose operands are ALL bare Identifiers |
12 | | - * (length ≥ 2, no duplicates, uniform operator across the flattened chain). |
13 | | - * |
14 | | - * Skipped (not reported, autofix-safe stays narrow): |
15 | | - * |
16 | | - * - Any operand isn't a bare `Identifier` (Calls / member-access / literals |
17 | | - * / negations / nested non-uniform logical exprs short-circuit, and a |
| 13 | + * - Any operand isn't a bare `Identifier` (Calls / member-access / literals / |
| 14 | + * negations / nested non-uniform logical exprs short-circuit, and a |
18 | 15 | * `getter` on a member-access can have side effects — reordering would be |
19 | 16 | * observable). |
20 | 17 | * - Duplicate identifiers in the chain (rare, but rewriting through the |
21 | 18 | * duplicate would silently drop one). |
22 | 19 | * - Comments live between operands (autofix would relocate them). |
23 | | - * - Chain length < 2 (nothing to sort). |
24 | | - * |
25 | | - * Why a separate rule from sort-equality-disjunctions: that rule sorts the |
26 | | - * right-hand string-literal of an equality chain (`x === 'a' || x === 'b'`); |
27 | | - * this rule sorts the bare-identifier operands of a pure-identifier chain. |
28 | | - * Structurally different ASTs, semantically different safety arguments. |
| 20 | + * - Chain length < 2 (nothing to sort). Why a separate rule from |
| 21 | + * sort-equality-disjunctions: that rule sorts the right-hand string-literal |
| 22 | + * of an equality chain (`x === 'a' || x === 'b'`); this rule sorts the |
| 23 | + * bare-identifier operands of a pure-identifier chain. Structurally |
| 24 | + * different ASTs, semantically different safety arguments. |
29 | 25 | */ |
30 | 26 |
|
31 | 27 | /** |
@@ -57,9 +53,9 @@ const rule = { |
57 | 53 | : context.sourceCode |
58 | 54 |
|
59 | 55 | /** |
60 | | - * Flatten a left-associative LogicalExpression chain into leaf nodes. |
61 | | - * `(a && b) && c` and `a && (b && c)` both flatten to [a, b, c]. Caller |
62 | | - * checks operator uniformity. |
| 56 | + * Flatten a left-associative LogicalExpression chain into leaf nodes. `(a |
| 57 | + * && b) && c` and `a && (b && c)` both flatten to [a, b, c]. Caller checks |
| 58 | + * operator uniformity. |
63 | 59 | */ |
64 | 60 | function flatten(node: AstNode, op: string, out: AstNode[]): void { |
65 | 61 | if (node.type === 'LogicalExpression' && node.operator === op) { |
|
0 commit comments