Skip to content

Commit 66d9604

Browse files
committed
[Refactor] no-unused-state: avoid a loop
1 parent 87a6b36 commit 66d9604

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lib/rules/no-unused-state.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,15 @@ module.exports = {
139139
// Takes an ObjectExpression node and adds all named Property nodes to the
140140
// current set of state fields.
141141
function addStateFields(node) {
142-
for (const prop of node.properties) {
143-
const key = prop.key;
144-
145-
if (
146-
prop.type === 'Property'
147-
&& (key.type === 'Literal'
148-
|| (key.type === 'TemplateLiteral' && key.expressions.length === 0)
149-
|| (prop.computed === false && key.type === 'Identifier'))
142+
node.properties.filter((prop) => (
143+
prop.type === 'Property'
144+
&& (prop.key.type === 'Literal'
145+
|| (prop.key.type === 'TemplateLiteral' && prop.key.expressions.length === 0)
146+
|| (prop.computed === false && prop.key.type === 'Identifier'))
150147
&& getName(prop.key) !== null
151-
) {
152-
classInfo.stateFields.add(prop);
153-
}
154-
}
148+
)).forEach((prop) => {
149+
classInfo.stateFields.add(prop);
150+
});
155151
}
156152

157153
// Adds the name of the given node as a used state field if the node is an

0 commit comments

Comments
 (0)