1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
diff --git a/src/lsp/providers/diagnostics/diagnosticsProvider.ts b/src/lsp/providers/diagnostics/diagnosticsProvider.ts
index 56362d5488cc8776715de6feac2096c57149f255..1c98a391dfe30bdfd994e1c474d0c5251b6fdc42 100644
--- a/src/lsp/providers/diagnostics/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnostics/diagnosticsProvider.ts
@@ -29,6 +29,7 @@ InvalidConfigPathDiagnostic,
InvalidTailwindDirectiveDiagnostic,
AugmentedDiagnostic,
} from './types'
+import { joinWithAnd } from '../../util/joinWithAnd'
function getInvalidApplyDiagnostics(
state: State,
@@ -104,45 +105,58 @@ classLists.forEach((classList) => {
const classNames = getClassNamesInClassList(classList)
classNames.forEach((className, index) => {
+ let decls = getClassNameDecls(state, className.className)
+ if (!decls) return
+
+ let properties = Object.keys(decls)
+ let meta = getClassNameMeta(state, className.className)
+
let otherClassNames = classNames.filter((_className, i) => i !== index)
- otherClassNames.forEach((otherClassName) => {
- let decls = getClassNameDecls(state, className.className)
- if (!decls) return
+ let conflictingClassNames = otherClassNames.filter((otherClassName) => {
let otherDecls = getClassNameDecls(state, otherClassName.className)
- if (!otherDecls) return
+ if (!otherDecls) return false
- let meta = getClassNameMeta(state, className.className)
let otherMeta = getClassNameMeta(state, otherClassName.className)
- if (
- equal(Object.keys(decls), Object.keys(otherDecls)) &&
+ return (
+ equal(properties, Object.keys(otherDecls)) &&
!Array.isArray(meta) &&
!Array.isArray(otherMeta) &&
equal(meta.context, otherMeta.context) &&
equal(meta.pseudo, otherMeta.pseudo)
- ) {
- diagnostics.push({
- code: DiagnosticKind.UtilityConflicts,
- className,
- otherClassName,
- range: className.range,
- severity:
- severity === 'error'
- ? DiagnosticSeverity.Error
- : DiagnosticSeverity.Warning,
- message: `'${className.className}' and '${otherClassName.className}' apply the same CSS properties.`,
- relatedInformation: [
- {
- message: otherClassName.className,
- location: {
- uri: document.uri,
- range: otherClassName.range,
- },
+ )
+ })
+
+ if (conflictingClassNames.length === 0) return
+
+ diagnostics.push({
+ code: DiagnosticKind.UtilityConflicts,
+ className,
+ otherClassNames: conflictingClassNames,
+ range: className.range,
+ severity:
+ severity === 'error'
+ ? DiagnosticSeverity.Error
+ : DiagnosticSeverity.Warning,
+ message: `'${className.className}' applies the same CSS ${
+ properties.length === 1 ? 'property' : 'properties'
+ } as ${joinWithAnd(
+ conflictingClassNames.map(
+ (conflictingClassName) => `'${conflictingClassName.className}'`
+ )
+ )}.`,
+ relatedInformation: conflictingClassNames.map(
+ (conflictingClassName) => {
+ return {
+ message: conflictingClassName.className,
+ location: {
+ uri: document.uri,
+ range: conflictingClassName.range,
},
- ],
- })
- }
+ }
+ }
+ ),
})
})
})
|