@@ -9,6 +9,7 @@ import type {
9
9
SvelteSpreadAttribute ,
10
10
SvelteStyleDirective ,
11
11
} from "svelte-eslint-parser/lib/ast"
12
+ import type { AnyNode , AtRule , Root , Rule } from "postcss"
12
13
import { default as selectorParser , type Node } from "postcss-selector-parser"
13
14
14
15
export default createRule ( "no-unused-class-name" , {
@@ -87,17 +88,24 @@ function findClassesInAttribute(
87
88
/**
88
89
* Extract all class names used in a PostCSS node.
89
90
*/
90
- function findClassesInPostCSSNode ( node : ESLintCompatiblePostCSSNode ) : string [ ] {
91
+ function findClassesInPostCSSNode < T extends AnyNode > (
92
+ node : ESLintCompatiblePostCSSNode < T > ,
93
+ ) : string [ ] {
91
94
if ( node . type === "SvelteStyle-rule" ) {
92
- let classes = node . nodes . flatMap ( findClassesInPostCSSNode )
95
+ const typedNode = node as ESLintCompatiblePostCSSNode < Rule >
96
+ let classes = typedNode . nodes . flatMap ( findClassesInPostCSSNode )
93
97
const processor = selectorParser ( )
94
98
classes = classes . concat (
95
- findClassesInSelector ( processor . astSync ( node . selector ) ) ,
99
+ findClassesInSelector ( processor . astSync ( typedNode . selector ) ) ,
96
100
)
97
101
return classes
98
102
}
99
103
if ( node . type === "SvelteStyle-root" || node . type === "SvelteStyle-atrule" ) {
100
- return node . nodes . flatMap ( findClassesInPostCSSNode )
104
+ return (
105
+ node as
106
+ | ESLintCompatiblePostCSSNode < Root >
107
+ | ESLintCompatiblePostCSSNode < AtRule >
108
+ ) . nodes . flatMap ( findClassesInPostCSSNode )
101
109
}
102
110
return [ ]
103
111
}
0 commit comments