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 #17514

Closed
DartBot opened this issue Mar 16, 2014 · 15 comments
Closed

Formatter problem with initializer list #17514

DartBot opened this issue Mar 16, 2014 · 15 comments
Assignees
Labels
closed-obsolete Closed as the reported issue is no longer relevant

Comments

@DartBot
Copy link

DartBot commented Mar 16, 2014

This issue was originally filed by @Fox32


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

@kevmoo
Copy link
Member

kevmoo commented Mar 17, 2014

Added Area-Formatter, Triaged labels.

@clayberg
Copy link

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

@pq
Copy link
Member

pq commented Apr 9, 2014

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

@pq
Copy link
Member

pq commented Apr 9, 2014

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 r34893, please re-open this bug and include the expected output.

Again thanks for the feedback!


Added AssumedStale label.

@DartBot
Copy link
Author

DartBot commented Apr 10, 2014

This comment was originally written 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

@pq
Copy link
Member

pq commented Apr 10, 2014

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.

@sigmundch
Copy link
Member

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 {
    ...
  }

@munificent
Copy link
Member

+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 Apr 10, 2014

This comment was originally written by @Fox32


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

@kasperl
Copy link

kasperl commented May 8, 2014

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

@kasperl
Copy link

kasperl commented Jun 4, 2014

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

@kasperl
Copy link

kasperl commented Jul 10, 2014

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

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-1.6 label.

@munificent
Copy link
Member

Added AssumedStale label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/dart_style#335.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-obsolete Closed as the reported issue is no longer relevant
Projects
None yet
Development

No branches or pull requests

7 participants