Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

New rule: no_condition_parens_rule #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

mik01aj
Copy link

@mik01aj mik01aj commented Nov 9, 2018

This resolves issue #15.
Also implemented & tested WhileRule traversal.

Copy link
Collaborator

@srawlins srawlins left a comment

Choose a reason for hiding this comment

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

Thanks much!

@@ -263,7 +263,12 @@ abstract class Rule

@override
List<Lint> visitWhileRule(WhileRule node) {
throw new UnimplementedError();
var lint = <Lint>[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could shorten this to look like, e.g. visitStylesheet.

rule: this,
span: clause.expression.span,
message:
'Parentheses around ${clause.expression.span.text} are unnecessary'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

To avoid some wrapping here and lots of law-of-demeter, I'd recommend instantiating a variable either for clause.expression (above the if) or clause.expression.span (above the lint.add).

rule: this,
span: clause.expression.span,
message:
'Parentheses around ${clause.expression.span.text} are unnecessary'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please wrap ${clause.expression.span.text} in either single or double quotes. I forget what the convention is in other lints...

@@ -175,7 +175,7 @@ void main() {
expect(lint.column, 27);
});

test('reports lint when boolean is found in a @for condition', () {
test('reports lint when numbers are found in a @for condition', () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Haha yes, thanks for fixing this. You will get some merge conflicts with #29 where I overhaul this file.


void main() {
test('does not report lint when there are no parens', () {
var lints = getLints(r'@if 1 != 7 { @debug("quack"); }');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great tests! I'd love one more test with an inner expression that contains parens, like:

@if (a + b) * c < 3 { @debug("quack"); }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants