File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ export default createRule("no-unused-class-name", {
28
28
} ,
29
29
create ( context ) {
30
30
const classesUsedInTemplate : Record < string , SourceLocation > = { }
31
- let hasStyleNode = false
32
31
33
32
return {
34
33
SvelteElement ( node ) {
@@ -40,16 +39,19 @@ export default createRule("no-unused-class-name", {
40
39
classesUsedInTemplate [ className ] = node . startTag . loc
41
40
}
42
41
} ,
43
- SvelteStyleElement ( ) {
44
- hasStyleNode = true
45
- } ,
46
42
"Program:exit" ( ) {
47
- const styleAst = context . parserServices . getStyleSourceAst ( )
48
- if ( hasStyleNode && styleAst === null ) {
43
+ const styleContext = context . parserServices . getStyleContext ( )
44
+ if (
45
+ // There is a style element, but it couldn't be parsed
46
+ styleContext . sourceLang !== null &&
47
+ styleContext . sourceAst === null
48
+ ) {
49
49
return
50
50
}
51
51
const classesUsedInStyle =
52
- styleAst != null ? findClassesInPostCSSNode ( styleAst ) : [ ]
52
+ styleContext . sourceAst != null
53
+ ? findClassesInPostCSSNode ( styleContext . sourceAst )
54
+ : [ ]
53
55
for ( const className in classesUsedInTemplate ) {
54
56
if ( ! classesUsedInStyle . includes ( className ) ) {
55
57
context . report ( {
You can’t perform that action at this time.
0 commit comments