Skip to content

Commit ffd8e73

Browse files
committed
fix(lint): no-unscoped-has checks named group/peer variants
1 parent 69b3711 commit ffd8e73

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎oxlint-plugin-t3code/rules/no-unscoped-has.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ describe("t3code/no-unscoped-has", () => {
9595
`const className = "[&_:is(.safe,:has(input))]:p-2";`,
9696
);
9797

98+
rule.invalid(
99+
"reports an unanchored :has() inside a named group variant",
100+
`const className = "group-[&_:has(x)]/row:p-2";`,
101+
);
102+
98103
rule.invalid(
99104
"reports :has() anchored to the document root",
100105
`const className = "[body:has([data-dialog-open])_&]:overflow-hidden";`,

‎oxlint-plugin-t3code/rules/no-unscoped-has.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const GROUP_PREFIX_PATTERN = /(?:^|:)(?:group|peer)-$/u;
1212
const ATTRIBUTE_PREFIX_PATTERN = /(?:^|:)(?:data|aria)-$/u;
1313
const QUOTED_PATTERN = /(["'])(?:\\.|(?!\1).)*\1/gu;
1414

15-
/** Tailwind arbitrary variants in a class token: top-level `[...]` groups followed by `:`. */
15+
// A variant's closing bracket is followed by ":" or a group/peer name like "/row:".
16+
const VARIANT_END_PATTERN = /^(?:\/[\w-]+)?:/u;
17+
18+
/** Tailwind arbitrary variants in a class token: top-level `[...]` groups used as variants. */
1619
function variantGroups(token: string): { prefix: string; group: string }[] {
1720
const groups: { prefix: string; group: string }[] = [];
1821
let depth = 0;
@@ -24,7 +27,7 @@ function variantGroups(token: string): { prefix: string; group: string }[] {
2427
depth++;
2528
} else if (char === "]" && depth > 0) {
2629
depth--;
27-
if (depth === 0 && token[index + 1] === ":") {
30+
if (depth === 0 && VARIANT_END_PATTERN.test(token.slice(index + 1))) {
2831
groups.push({ prefix: token.slice(0, start - 1), group: token.slice(start, index) });
2932
}
3033
}

0 commit comments

Comments
 (0)