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

Remove all-whitespace on first line of multiline string literal. #1235

Open
lrhn opened this issue Jun 21, 2023 · 0 comments
Open

Remove all-whitespace on first line of multiline string literal. #1235

lrhn opened this issue Jun 21, 2023 · 0 comments

Comments

@lrhn
Copy link
Member

lrhn commented Jun 21, 2023

Dart-format should remove unnecessary trailing whitespace, also if it's the first line of a multiline string literal.

The syntax allows whitespace, and backslash-preceded whitespace, to be ignored if it's the only thing on the first line of a multiline string literal. The trailing newline of that line is also ignored, but that's probably wanted to preserve formatting,
but the backslash/whitespace characters have no effect other than be ignored.

Example:

  // Source of string literal contains: space, backslash, space, tab, backslash, tab, backslash, newline, z
  var string = """ \  \  \
z""";
  print(string.length); // 1 - only the `z` counts.

All the whitespace, and backslash-preceded whitespace (I don't want to call it "escaped", because it isn't, it works in raw strings too), is ignored, and the string has the same behavior and formatting without it. It is really just "trailing whitespace," and therefore I think Dart Format should remove it.

(It's a very specific exception that leading/trailing (so, only) whitespace is ignored on only the first line, but any trailing whitespace on the following lines is included. It makes sense only because it leads up to a newline which is also ignored, and allowing the string proper to begin on the next line is a good feature. But the extra allowed whitespace is just noise and can safely be removed.)

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

No branches or pull requests

2 participants