Skip to content

Commit e371c5e

Browse files
committed
feat: add comprehensive tests for invalid class diagnostics and update find.ts getClassNamesInClassList logic for '$' handling
1 parent d61966d commit e371c5e

File tree

10 files changed

+426
-3
lines changed

10 files changed

+426
-3
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ withFixture('basic', (c) => {
3838
testFixture('invalid-screen/simple')
3939
testFixture('invalid-theme/simple')
4040
testFixture('invalid-class/simple')
41-
testFixture('invalid-class/valid-classes')
41+
testFixture('invalid-class/whitespace-negative')
42+
testFixture('invalid-class/variants')
43+
testFixture('invalid-class/jsx-concat-positive')
44+
testFixture('invalid-class/jsx-template-literal')
45+
testFixture('invalid-class/css')
46+
testFixture('invalid-class/css-multi-prop')
47+
testFixture('invalid-class/css-multi-rule')
48+
testFixture('invalid-class/vue-style-lang-sass')
4249
})
4350

4451
withFixture('v4/basic', (c) => {
@@ -91,7 +98,14 @@ withFixture('v4/basic', (c) => {
9198
// testFixture('css-conflict/css-multi-prop')
9299
// testFixture('invalid-screen/simple')
93100
testFixture('invalid-class/simple')
94-
testFixture('invalid-class/valid-classes')
101+
testFixture('invalid-class/whitespace-negative')
102+
testFixture('invalid-class/variants')
103+
testFixture('invalid-class/jsx-concat-positive')
104+
testFixture('invalid-class/jsx-template-literal')
105+
testFixture('invalid-class/css')
106+
testFixture('invalid-class/css-multi-prop')
107+
testFixture('invalid-class/css-multi-rule')
108+
testFixture('invalid-class/vue-style-lang-sass')
95109

96110
testInline('simple typos in theme keys (in key)', {
97111
code: '.test { color: theme(--color-red-901) }',
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"code": ".test { @apply px-4; color: red; @apply nonexistent }",
3+
"language": "css",
4+
"expected": [
5+
{
6+
"code": "invalidClass",
7+
"source": "tailwindcss",
8+
"className": {
9+
"className": "nonexistent",
10+
"classList": {
11+
"classList": "nonexistent",
12+
"important": false,
13+
"range": {
14+
"start": {
15+
"line": 0,
16+
"character": 40
17+
},
18+
"end": {
19+
"line": 0,
20+
"character": 51
21+
}
22+
}
23+
},
24+
"range": {
25+
"start": {
26+
"line": 0,
27+
"character": 40
28+
},
29+
"end": {
30+
"line": 0,
31+
"character": 51
32+
}
33+
},
34+
"relativeRange": {
35+
"start": {
36+
"line": 0,
37+
"character": 0
38+
},
39+
"end": {
40+
"line": 0,
41+
"character": 11
42+
}
43+
}
44+
},
45+
"range": {
46+
"start": {
47+
"line": 0,
48+
"character": 40
49+
},
50+
"end": {
51+
"line": 0,
52+
"character": 51
53+
}
54+
},
55+
"severity": 3,
56+
"message": "Unknown utility class 'nonexistent'."
57+
}
58+
]
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"code": ".test { @apply px-4 }\n.test { @apply nonexistent }",
3+
"language": "css",
4+
"expected": [
5+
{
6+
"code": "invalidClass",
7+
"source": "tailwindcss",
8+
"className": {
9+
"className": "nonexistent",
10+
"classList": {
11+
"classList": "nonexistent",
12+
"important": false,
13+
"range": {
14+
"start": {
15+
"line": 1,
16+
"character": 15
17+
},
18+
"end": {
19+
"line": 1,
20+
"character": 26
21+
}
22+
}
23+
},
24+
"range": {
25+
"start": {
26+
"line": 1,
27+
"character": 15
28+
},
29+
"end": {
30+
"line": 1,
31+
"character": 26
32+
}
33+
},
34+
"relativeRange": {
35+
"start": {
36+
"line": 0,
37+
"character": 0
38+
},
39+
"end": {
40+
"line": 0,
41+
"character": 11
42+
}
43+
}
44+
},
45+
"range": {
46+
"start": {
47+
"line": 1,
48+
"character": 15
49+
},
50+
"end": {
51+
"line": 1,
52+
"character": 26
53+
}
54+
},
55+
"severity": 3,
56+
"message": "Unknown utility class 'nonexistent'."
57+
}
58+
]
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"code": ".test { @apply nonexistent; }",
3+
"language": "css",
4+
"expected": [
5+
{
6+
"code": "invalidClass",
7+
"source": "tailwindcss",
8+
"className": {
9+
"className": "nonexistent",
10+
"classList": {
11+
"classList": "nonexistent",
12+
"important": false,
13+
"range": {
14+
"start": {
15+
"line": 0,
16+
"character": 15
17+
},
18+
"end": {
19+
"line": 0,
20+
"character": 26
21+
}
22+
}
23+
},
24+
"range": {
25+
"start": {
26+
"line": 0,
27+
"character": 15
28+
},
29+
"end": {
30+
"line": 0,
31+
"character": 26
32+
}
33+
},
34+
"relativeRange": {
35+
"start": {
36+
"line": 0,
37+
"character": 0
38+
},
39+
"end": {
40+
"line": 0,
41+
"character": 11
42+
}
43+
}
44+
},
45+
"range": {
46+
"start": {
47+
"line": 0,
48+
"character": 15
49+
},
50+
"end": {
51+
"line": 0,
52+
"character": 26
53+
}
54+
},
55+
"severity": 3,
56+
"message": "Unknown utility class 'nonexistent'."
57+
}
58+
]
59+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"code": "<div className={`nonexistent ${'px-4'}`}>",
3+
"language": "javascriptreact",
4+
"expected": [
5+
{
6+
"className": {
7+
"classList": {
8+
"classList": "nonexistent $",
9+
"range": {
10+
"end": {
11+
"character": 30,
12+
"line": 0
13+
},
14+
"start": {
15+
"character": 17,
16+
"line": 0
17+
}
18+
}
19+
},
20+
"className": "nonexistent",
21+
"range": {
22+
"end": {
23+
"character": 28,
24+
"line": 0
25+
},
26+
"start": {
27+
"character": 17,
28+
"line": 0
29+
}
30+
},
31+
"relativeRange": {
32+
"end": {
33+
"character": 11,
34+
"line": 0
35+
},
36+
"start": {
37+
"character": 0,
38+
"line": 0
39+
}
40+
}
41+
},
42+
"code": "invalidClass",
43+
"message": "Unknown utility class 'nonexistent'.",
44+
"range": {
45+
"end": {
46+
"character": 28,
47+
"line": 0
48+
},
49+
"start": {
50+
"character": 17,
51+
"line": 0
52+
}
53+
},
54+
"severity": 3,
55+
"source": "tailwindcss"
56+
}
57+
]
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"code": "<div className={`nonexistent ${'px-4'}`}>",
3+
"language": "javascriptreact",
4+
"expected": [
5+
{
6+
"className": {
7+
"classList": {
8+
"classList": "nonexistent $",
9+
"range": {
10+
"end": {
11+
"character": 30,
12+
"line": 0
13+
},
14+
"start": {
15+
"character": 17,
16+
"line": 0
17+
}
18+
}
19+
},
20+
"className": "nonexistent",
21+
"range": {
22+
"end": {
23+
"character": 28,
24+
"line": 0
25+
},
26+
"start": {
27+
"character": 17,
28+
"line": 0
29+
}
30+
},
31+
"relativeRange": {
32+
"end": {
33+
"character": 11,
34+
"line": 0
35+
},
36+
"start": {
37+
"character": 0,
38+
"line": 0
39+
}
40+
}
41+
},
42+
"code": "invalidClass",
43+
"message": "Unknown utility class 'nonexistent'.",
44+
"range": {
45+
"end": {
46+
"character": 28,
47+
"line": 0
48+
},
49+
"start": {
50+
"character": 17,
51+
"line": 0
52+
}
53+
},
54+
"severity": 3,
55+
"source": "tailwindcss"
56+
}
57+
]
58+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"code": "<div class=\"hover:nonexistent\"></div>",
3+
"expected": [
4+
{
5+
"code": "invalidClass",
6+
"source": "tailwindcss",
7+
"className": {
8+
"className": "hover:nonexistent",
9+
"classList": {
10+
"classList": "hover:nonexistent",
11+
"range": {
12+
"start": {
13+
"line": 0,
14+
"character": 12
15+
},
16+
"end": {
17+
"line": 0,
18+
"character": 29
19+
}
20+
}
21+
},
22+
"range": {
23+
"start": {
24+
"line": 0,
25+
"character": 12
26+
},
27+
"end": {
28+
"line": 0,
29+
"character": 29
30+
}
31+
},
32+
"relativeRange": {
33+
"start": {
34+
"line": 0,
35+
"character": 0
36+
},
37+
"end": {
38+
"line": 0,
39+
"character": 17
40+
}
41+
}
42+
},
43+
"range": {
44+
"start": {
45+
"line": 0,
46+
"character": 12
47+
},
48+
"end": {
49+
"line": 0,
50+
"character": 29
51+
}
52+
},
53+
"severity": 3,
54+
"message": "Unknown utility class 'hover:nonexistent'."
55+
}
56+
]
57+
}

0 commit comments

Comments
 (0)