Skip to content

If statements test clause is wrapped. Probably better to add parentheses and wrap after. #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xxgreg opened this issue Feb 24, 2015 · 5 comments

Comments

@xxgreg
Copy link

xxgreg commented Feb 24, 2015

The following:

if (object is List && _integerTag.hasMatch(name))
      return object[int.parse(name)];

Is transformed to:

if (object is List &&
        _integerTag.hasMatch(name)) return object[int.parse(name)];

This probably would be better as:

if (object is List && _integerTag.hasMatch(name)) {
      return object[int.parse(name)];
}

Though I agree this is matter of taste and people will disagree.

On a side note - In my own private style guide I often write 2 line if statements as in the top example. I am aware that this doesn't match the Dart style guide. But I'm ok with adding parentheses - just so I can leave formatting to the machines.

@xxgreg
Copy link
Author

xxgreg commented Feb 25, 2015

I re-ran using dartformat instead of dartfmt.

Now the output is transformed to:

   if (object is List && _integerTag.hasMatch(name)) return object[
        int.parse(name)];

@munificent
Copy link
Member

This is as-designed. The formatter's charter is to only touch whitespace, so it doesn't add brackets or any other substantive changes like that. The linter that @pq is working on likely will handle this.

@pq
Copy link
Member

pq commented Feb 25, 2015

I expect we'll have a bunch of lints along these lines down the road. Feel free to open a request so we can track this one.

https://github.com/dart-lang/linter

Thanks!

@xxgreg
Copy link
Author

xxgreg commented Feb 25, 2015

Looks like you've got it already. Keep up the good work!

dart-lang/sdk#57151

@pq
Copy link
Member

pq commented Feb 25, 2015

:) Thanks! Feel free to chime in with more!

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

No branches or pull requests

3 participants