Skip to content
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

Formatter problem with initializer list #335

Closed
DartBot opened this issue Jun 5, 2015 · 14 comments
Closed

Formatter problem with initializer list #335

DartBot opened this issue Jun 5, 2015 · 14 comments
Assignees
Labels

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/648527?v=3" align="left" width="96" height="96"hspace="10"> Issue by Fox32
Originally opened as dart-lang/sdk#17514


Dart formatter is unable to format this code correctly:

  Vector3(double x_, double y_, double z_): storage = new Float32List(3) {
    setValues(x_, y_, z_);
  }

If I give a hint by adding a line break before the ":", everything works fine. If I add a space instead, the space is removed.

Dart Editor version 1.3.0.dev_03_02 (DEV)
Dart SDK version 1.3.0-dev.3.2

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo


Added Area-Formatter, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/8616782?v=3" align="left" width="48" height="48"hspace="10"> Comment by clayberg


Set owner to @pq.
Added this to the 1.3 milestone.
Removed Priority-Unassigned label.
Added Priority-Medium label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/67586?v=3" align="left" width="48" height="48"hspace="10"> Comment by pq


Removed this from the 1.3 milestone.
Added this to the 1.4 milestone.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/67586?v=3" align="left" width="48" height="48"hspace="10"> Comment by pq


Thanks for the report. I just landed a related fix that might address this (https://codereview.chromium.org/231743002/). The current behavior formats this:

class Vector3 {
  var storage;
  Vector3(double x_, double y_, double z_): storage = new Float32List(3) {
    setValues(x_, y_, z_);
  }
}

to:

class Vector3 {
  var storage;
  Vector3(double x_, double y_, double z_) : storage = new Float32List(3) {
    setValues(x_, y_, z_);
  }
}

If you're still seeing surprising results after dart-lang/sdk@3edb0ef, please re-open this bug and include the expected output.

Again thanks for the feedback!


Added AssumedStale label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/648527?v=3" align="left" width="48" height="48"hspace="10"> Comment by Fox32


Maybe the formatting rule should be more specific in the Dart Style Guide as I assumed that it is required to always do a new line before the ':'.

https://www.dartlang.org/articles/style-guide/#do-format-constructor-initialization-lists-with-each-field-on-its-own-line

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/67586?v=3" align="left" width="48" height="48"hspace="10"> Comment by pq


Ah, wait. Good catch. I think we agreed that a single initializer could live on a single line but now I'm not sure. Anyway, either this or the style guide need updating. :)

Bob, Siggi: thoughts?


cc @sigmundch.
Set owner to @munificent.
Added Triaged label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2049220?v=3" align="left" width="48" height="48"hspace="10"> Comment by sigmundch


Yes - inline initializers are allowed, and are not necessarily limited to just one. Only when you exceed the 80 column limit we need to break on the ":".

I believe all of these are valid (correctly formatted) as is:

class Classname {
  int a;
  int b;
  int c;

  Classname.one() : a = 1, b = 2, c = 3;

  Classname.two() : a = 1, b = 2, c = 3 {
    ...
  }

  Classname.three()
    : a = 1, b = 2, c = 3 {
    ...
  }

  Classname.three()
    : a = 1,
      b = 2,
      c = 3 {
    ...
  }

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent


+1 what Siggy said (though personally I always wrap them). One nit: the ":" should be indented +4, like:

  Classname.three()
      : a = 1, b = 2, c = 3 {
    ...
  }

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/648527?v=3" align="left" width="48" height="48"hspace="10"> Comment by Fox32


Then the guide should be updated, as it states: "DO format constructor initialization lists with each field on its own line."

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2156198?v=3" align="left" width="48" height="48"hspace="10"> Comment by kasperl


Removed this from the 1.4 milestone.
Added this to the 1.5 milestone.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2156198?v=3" align="left" width="48" height="48"hspace="10"> Comment by kasperl


Removed this from the 1.5 milestone.
Added this to the 1.6 milestone.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2156198?v=3" align="left" width="48" height="48"hspace="10"> Comment by kasperl


Removed this from the 1.6 milestone.
Added Oldschool-Milestone-1.6 label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2156198?v=3" align="left" width="48" height="48"hspace="10"> Comment by kasperl


Removed Oldschool-Milestone-1.6 label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent


Added AssumedStale label.

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

No branches or pull requests

2 participants