Skip to content

Commit 8c63f78

Browse files
committed
chore(no-unused-class-name): switched from for cycle to flatMap
1 parent 281c287 commit 8c63f78

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ export default createRule("no-unused-class-name", {
3838
if (node.kind !== "html") {
3939
return
4040
}
41-
for (const attribute of node.startTag.attributes) {
42-
const classes = findClassesInAttribute(attribute)
43-
for (const className of classes) {
44-
classesUsedInTemplate[className] = node.startTag.loc
45-
}
41+
const classes = node.startTag.attributes.flatMap(findClassesInAttribute)
42+
for (const className of classes) {
43+
classesUsedInTemplate[className] = node.startTag.loc
4644
}
4745
},
4846
SvelteStyleElement(node) {
@@ -101,15 +99,15 @@ function findClassesInAttribute(
10199
*/
102100
function findClassesInPostCSSNode(node: AnyNode): string[] {
103101
if (node.type === "rule") {
104-
let classes = node.nodes.map(findClassesInPostCSSNode).flat()
102+
let classes = node.nodes.flatMap(findClassesInPostCSSNode)
105103
const processor = selectorParser()
106104
classes = classes.concat(
107105
findClassesInSelector(processor.astSync(node.selector)),
108106
)
109107
return classes
110108
}
111109
if (["root", "atrule"].includes(node.type)) {
112-
return (node as Root | AtRule).nodes.map(findClassesInPostCSSNode).flat()
110+
return (node as Root | AtRule).nodes.flatMap(findClassesInPostCSSNode)
113111
}
114112
return []
115113
}
@@ -122,7 +120,7 @@ function findClassesInSelector(node: Node): string[] {
122120
return [node.value]
123121
}
124122
if (["root", "selector"].includes(node.type)) {
125-
return (node as SelectorRoot).nodes.map(findClassesInSelector).flat()
123+
return (node as SelectorRoot).nodes.flatMap(findClassesInSelector)
126124
}
127125
return []
128126
}

0 commit comments

Comments
 (0)