Skip to content

Commit

Permalink
[Refactor] no-unused-state: avoid a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 6, 2020
1 parent 87a6b36 commit 66d9604
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,15 @@ module.exports = {
// Takes an ObjectExpression node and adds all named Property nodes to the
// current set of state fields.
function addStateFields(node) {
for (const prop of node.properties) {
const key = prop.key;

if (
prop.type === 'Property'
&& (key.type === 'Literal'
|| (key.type === 'TemplateLiteral' && key.expressions.length === 0)
|| (prop.computed === false && key.type === 'Identifier'))
node.properties.filter((prop) => (
prop.type === 'Property'
&& (prop.key.type === 'Literal'
|| (prop.key.type === 'TemplateLiteral' && prop.key.expressions.length === 0)
|| (prop.computed === false && prop.key.type === 'Identifier'))
&& getName(prop.key) !== null
) {
classInfo.stateFields.add(prop);
}
}
)).forEach((prop) => {
classInfo.stateFields.add(prop);
});
}

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

0 comments on commit 66d9604

Please sign in to comment.