@@ -9,8 +9,11 @@ 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"
13
- import { default as selectorParser , type Node } from "postcss-selector-parser"
12
+ import type { AnyNode } from "postcss"
13
+ import {
14
+ default as selectorParser ,
15
+ type Node as SelectorNode ,
16
+ } from "postcss-selector-parser"
14
17
15
18
export default createRule ( "no-unused-class-name" , {
16
19
meta : {
@@ -88,32 +91,27 @@ function findClassesInAttribute(
88
91
/**
89
92
* Extract all class names used in a PostCSS node.
90
93
*/
91
- function findClassesInPostCSSNode < T extends AnyNode > (
92
- node : ESLintCompatiblePostCSSNode < T > ,
94
+ function findClassesInPostCSSNode (
95
+ node : ESLintCompatiblePostCSSNode < AnyNode > ,
93
96
) : string [ ] {
94
97
if ( node . type === "SvelteStyle-rule" ) {
95
- const typedNode = node as ESLintCompatiblePostCSSNode < Rule >
96
- let classes = typedNode . nodes . flatMap ( findClassesInPostCSSNode )
98
+ let classes = node . nodes . flatMap ( findClassesInPostCSSNode )
97
99
const processor = selectorParser ( )
98
100
classes = classes . concat (
99
- findClassesInSelector ( processor . astSync ( typedNode . selector ) ) ,
101
+ findClassesInSelector ( processor . astSync ( node . selector ) ) ,
100
102
)
101
103
return classes
102
104
}
103
105
if ( node . type === "SvelteStyle-root" || node . type === "SvelteStyle-atrule" ) {
104
- return (
105
- node as
106
- | ESLintCompatiblePostCSSNode < Root >
107
- | ESLintCompatiblePostCSSNode < AtRule >
108
- ) . nodes . flatMap ( findClassesInPostCSSNode )
106
+ return node . nodes . flatMap ( findClassesInPostCSSNode )
109
107
}
110
108
return [ ]
111
109
}
112
110
113
111
/**
114
112
* Extract all class names used in a PostCSS selector.
115
113
*/
116
- function findClassesInSelector ( node : Node ) : string [ ] {
114
+ function findClassesInSelector ( node : SelectorNode ) : string [ ] {
117
115
if ( node . type === "class" ) {
118
116
return [ node . value ]
119
117
}
0 commit comments