Skip to content

Commit 8aa5b9a

Browse files
committed
fix(no-unused-class-name): added support for class attributes with multiple spaces, newlines and tabs
1 parent 8476b47 commit 8aa5b9a

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/rules/no-unused-class-name.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function findClassesInAttribute(
7575
): string[] {
7676
if (attribute.type === "SvelteAttribute" && attribute.key.name === "class") {
7777
return attribute.value.flatMap((value) =>
78-
value.type === "SvelteLiteral" ? value.value.split(" ") : [],
78+
value.type === "SvelteLiteral" ? value.value.trim().split(/\s+/u) : [],
7979
)
8080
}
8181
if (attribute.type === "SvelteDirective" && attribute.kind === "Class") {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- message: Unused class "div-class-two".
2+
line: 1
3+
column: 1
4+
suggestions: null
5+
- message: Unused class "span-class-two".
6+
line: 3
7+
column: 1
8+
suggestions: null
9+
- message: Unused class "span-class-three".
10+
line: 3
11+
column: 1
12+
suggestions: null
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="div-class div-class-two">Hello</div>
2+
3+
<span
4+
class="
5+
span-class
6+
span-class-two
7+
span-class-three
8+
">World!</span>
9+
10+
<style>
11+
.div-class {
12+
color: red;
13+
}
14+
15+
.span-class {
16+
font-weight: bold;
17+
}
18+
</style>

0 commit comments

Comments
 (0)