Skip to content

Commit 712b5ff

Browse files
Show all potential class conflicts in v4 projects (#1077)
Fixes #1047 --------- Co-authored-by: Robin Malfait <[email protected]>
1 parent e3cd1f2 commit 712b5ff

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

packages/tailwindcss-language-server/tests/diagnostics/diagnostics.test.js

+61
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,64 @@ withFixture('v4/with-prefix', (c) => {
254254
expected: [],
255255
})
256256
})
257+
258+
withFixture('v4/basic', (c) => {
259+
function testMatch(name, { code, expected, language = 'html' }) {
260+
test(name, async () => {
261+
let promise = new Promise((resolve) => {
262+
c.onNotification('textDocument/publishDiagnostics', ({ diagnostics }) => {
263+
resolve(diagnostics)
264+
})
265+
})
266+
267+
let doc = await c.openDocument({ text: code, lang: language })
268+
let diagnostics = await promise
269+
270+
expected = JSON.parse(JSON.stringify(expected).replaceAll('{{URI}}', doc.uri))
271+
272+
expect(diagnostics).toMatchObject(expected)
273+
})
274+
}
275+
276+
testMatch('conflicts show even when unknown classes are present', {
277+
code: `<div class="foo max-w-4xl max-w-6xl hover:underline">testing</div>`,
278+
expected: [
279+
{
280+
code: 'cssConflict',
281+
message: "'max-w-4xl' applies the same CSS properties as 'max-w-6xl'.",
282+
className: {
283+
className: 'max-w-4xl',
284+
classList: {
285+
classList: 'foo max-w-4xl max-w-6xl hover:underline',
286+
},
287+
},
288+
otherClassNames: [
289+
{
290+
className: 'max-w-6xl',
291+
classList: {
292+
classList: 'foo max-w-4xl max-w-6xl hover:underline',
293+
},
294+
},
295+
],
296+
},
297+
{
298+
code: 'cssConflict',
299+
message: "'max-w-6xl' applies the same CSS properties as 'max-w-4xl'.",
300+
className: {
301+
className: 'max-w-6xl',
302+
classList: {
303+
classList: 'foo max-w-4xl max-w-6xl hover:underline',
304+
},
305+
},
306+
otherClassNames: [
307+
{
308+
className: 'max-w-4xl',
309+
classList: {
310+
classList: 'foo max-w-4xl max-w-6xl hover:underline',
311+
},
312+
},
313+
],
314+
},
315+
],
316+
})
317+
})

packages/tailwindcss-language-service/src/diagnostics/getCssConflictDiagnostics.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ function* findConflicts(
353353
conflictingClassNames.push(otherClassName)
354354
}
355355

356-
if (conflictingClassNames.length === 0) return
356+
if (conflictingClassNames.length === 0) continue
357357

358358
yield [className, conflictingClassNames]
359359
}

packages/vscode-tailwindcss/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Properly validate `theme(…)` function paths in v4 ([#1074](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1074))
77
- Support loading TypeScript configs and plugins in v4 projects ([#1076](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1076))
88
- Show colors for logical border properties ([#1075](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1075))
9+
- Show all potential class conflicts in v4 projects ([#1077](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1077))
910

1011
## 0.12.12
1112

0 commit comments

Comments
 (0)