Skip to content

Commit 86d4b2a

Browse files
fix: #461
False positives with `border` and `divide` by `no-contradicting-classname` rule
1 parent 5d0c0e6 commit 86d4b2a

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/rules/no-contradicting-classname.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ruleTester.run(RULE_NAME, noContradictingClassname, {
5757
`<p class="to-[2.5px] to-transparent">Issue 271</p>`,
5858
`<p class="![width:_0] [height:_0]">Issue 269</p>`,
5959
`<p class="bg-[size:20px_20px] bg-[position:right_16px_center]">Issue 321</p>`,
60-
// `<p class="divide-red-800 border-blue-500">Issue 461</p>`,
60+
`<p class="divide-red-800 border-blue-500">Issue 461</p>`,
6161
].map((testedNgCode) => ({
6262
code: testedNgCode,
6363
languageOptions: withAngularParser,
@@ -79,6 +79,13 @@ ruleTester.run(RULE_NAME, noContradictingClassname, {
7979
],
8080
languageOptions: withAngularParser,
8181
},
82+
{
83+
code: `ctl(\`lg:w-full lg:w-1/2\`);`,
84+
errors: [
85+
suggest("lg:w-full", `ctl(\`lg:w-full\`);`, ["lg:w-1/2"]),
86+
suggest("lg:w-1/2", `ctl(\`lg:w-1/2\`);`, ["lg:w-full"]),
87+
],
88+
},
8289
{
8390
code: `ctl(\`w-[\${width}] block flex h-[\${height}] rounded\`);`,
8491
errors: [

src/rules/no-contradicting-classname.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,16 @@ const getCompiledGroup = (
8585
}
8686

8787
const flattenedSelectors = flattenNestingWorker(cssRule);
88-
const hasValidSelector = flattenedSelectors.some(
89-
// Ignore rules that only have pseudo selectors (e.g. `::before`, `::after`)
90-
(selector) => !selector.includes("::"),
88+
const hasExoticSelector = flattenedSelectors.some(
89+
// Detect complex selectors
90+
// examples:
91+
// `no-marker` → will include `::before`, `::after`
92+
// `space-x-0` → will include `:where(.space-x-0 > :not(:last-child))`)
93+
(selector) => selector.includes("::") || selector.includes(" "),
9194
);
9295

93-
if (!hasValidSelector) {
96+
if (hasExoticSelector) {
97+
// Ignore the complex selectors, we focus on `.single-simple-class-names`
9498
cssPropertiesCache.set(fullClassName, undefined);
9599
continue;
96100
}

0 commit comments

Comments
 (0)