Skip to content

Commit 299ba07

Browse files
committed
Show all potential class conflicts in v4 projects
1 parent 2e92af0 commit 299ba07

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

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

Lines changed: 61 additions & 0 deletions
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.only(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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)