dart_style icon indicating copy to clipboard operation
dart_style copied to clipboard

End-of-line comments should not be moved to a new line

Open bwilkerson opened this issue 4 years ago • 1 comments

Given the following code:

SizedBox newBox() {
  return SizedBox( // LINT
    height: 0,
    width: 0,
    child: Container(),
  );
}

class Container {}

class SizedBox {
  SizedBox({int height = 0, int width = 0, Container? child});
}

The formatter will move the end-of-line comment on line 2 to be on a separate line.

My general interpretation of end-of-line comments is that

  • if there is non-whitespace to the left of the comment then it applies to the code on the line the comment is on,
  • otherwise it applies to the first line following it that contains non-whitespace.

Moving the comment changes my default assumption of which code the comment applies to, so I don't think the formatter should move it, even when every argument is being placed on a separate line.

As the comment might imply, this is impacting the tests for the linter because it also assumes that the lint should be produced on the line containing the marker comment. It's forcing us to not format some of the test code.

bwilkerson avatar Oct 28 '21 15:10 bwilkerson

Similar to #798

a14n avatar Oct 28 '21 15:10 a14n