Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

invariant_boolean: When searching for references reassignment include PostfixExpression and similar, e.g. variable++. #412

Merged
merged 1 commit into from
Mar 7, 2017

Conversation

alexeieleusis
Copy link
Contributor

@pq
Copy link
Contributor

pq commented Feb 9, 2017

@bwilkerson ?

.length ==
0;
return (AstNode statement) {
bool isMutation(AstNode n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fairly inefficient because you have to perform multiple is checks for every node, even when you've already determined that it isn't necessary. Perhaps re-structure slightly:

if (n is AssignmentExpression) {
  return !identifiers.contains(n.leftHandSide);
} else if (n is PostfixExpression) {
  TokenType type = n.operator.type;
  return (type == TokenType.PLUS_PLUS || type == TokenType.MINUS_MINUS) && !identifiers.contains(n.operand);
} else ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bwilkerson: take another look?

return;
}

offset++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to introduce other variables so that you can check other operators.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very good idea, but I am not sure which ones to check, can you please provide a few examples?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bwilkerson : thoughts on what @alexeieleusis should check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks the postfix increment operator, but the rule checks for all four combinations of (prefix | postfix) (increment | decrement) operators. There are three operators that are not being tested, and I think they should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I was confused, somehow I thought this was the rule's code. Will add those cases to the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@alexeieleusis
Copy link
Contributor Author

Fixes dart-lang/sdk#28967

.length ==
0;
return (AstNode statement) {
bool isMutation(AstNode n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bwilkerson: take another look?

.takeWhile((n) => n != node)
.where(isMutation)
.length ==
0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEmpty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha! Irony, I should be using the linter :)

return;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a newline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@alexeieleusis alexeieleusis merged commit 9bf625c into dart-archive:master Mar 7, 2017
@alexeieleusis alexeieleusis deleted the 337_postfixExpression branch March 7, 2017 17:31
JPaulsen pushed a commit to JPaulsen/linter that referenced this pull request Mar 7, 2017
…ression

invariant_boolean: When searching for references reassignment include PostfixExpression and similar, e.g. variable++.
JPaulsen pushed a commit to JPaulsen/linter that referenced this pull request Mar 8, 2017
…ression

invariant_boolean: When searching for references reassignment include PostfixExpression and similar, e.g. variable++.
JPaulsen pushed a commit to JPaulsen/linter that referenced this pull request Mar 8, 2017
…ression

invariant_boolean: When searching for references reassignment include PostfixExpression and similar, e.g. variable++.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

4 participants