Skip to content

Commit b8690fa

Browse files
committed
Harden tailwind class difference classification
Make comparison outcome handling explicit so each classify result is mapped to a known kind, and token-multiset cases now include formatter token-loss symmetry checks to avoid false exact matches.
1 parent 2a1bc52 commit b8690fa

3 files changed

Lines changed: 12 additions & 24 deletions

File tree

tests/tailwind-compare/compare.mjs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -357,31 +357,19 @@ function compareAttribute(
357357
const kind = classifyDifference(comparison);
358358
if (kind === "token-multiset") {
359359
summary.extractionMismatch += 1;
360-
pending.push({
361-
attribute,
362-
...comparison,
363-
kind,
364-
path: candidate.path,
365-
});
366-
return;
367-
}
368-
if (kind === "prettier-nonconvergent") {
360+
} else if (kind === "prettier-nonconvergent") {
369361
summary.prettierNonconvergent += 1;
370-
pending.push({
371-
attribute,
372-
...comparison,
373-
kind,
374-
path: candidate.path,
375-
});
376-
return;
377-
}
378-
if (kind === "exact") {
362+
} else if (kind === "exact") {
379363
summary.exact += 1;
380364
return;
365+
} else if (kind !== "order-difference") {
366+
throw new Error(`Unexpected comparison kind: ${kind}`);
381367
}
368+
382369
pending.push({
383370
attribute,
384371
...comparison,
372+
kind,
385373
path: candidate.path,
386374
});
387375
}
@@ -505,7 +493,7 @@ async function compareCandidates(configuration, candidates) {
505493
}
506494

507495
const orderDifferences = pending.filter(
508-
(detail) => detail.kind === undefined,
496+
(detail) => detail.kind === "order-difference",
509497
);
510498
let known;
511499
try {

tests/tailwind-compare/lib.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ export function classifyDifference(comparison, known) {
217217
} = comparison;
218218
if (
219219
!sameMultiset(original, scrambled) ||
220-
![prettierScrambled, rustywind].every((tokens) =>
221-
sameMultiset(prettierOriginal, tokens),
222-
)
220+
!sameMultiset(original, prettierOriginal) ||
221+
!sameMultiset(scrambled, prettierScrambled) ||
222+
!sameMultiset(scrambled, rustywind)
223223
) {
224224
return "token-multiset";
225225
}

tests/tailwind-compare/test/lib.test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ test("rejects order classification without a result for every token", () => {
189189
);
190190
});
191191

192-
test("allows convergent duplicate removal by both formatters", () => {
192+
test("rejects convergent token removal by both formatters", () => {
193193
assert.equal(
194194
classifyDifference({
195195
original: ["rtl:mr-0", "flex", "rtl:mr-0"],
@@ -198,7 +198,7 @@ test("allows convergent duplicate removal by both formatters", () => {
198198
prettierScrambled: ["flex", "rtl:mr-0"],
199199
rustywind: ["flex", "rtl:mr-0"],
200200
}),
201-
"exact",
201+
"token-multiset",
202202
);
203203
});
204204

0 commit comments

Comments
 (0)