Skip to content

[analysis_server] Fix blank-line placement in sort_constructors_first fix - #64041

Open
hkarmoush wants to merge 2 commits into
dart-lang:mainfrom
hkarmoush:fix-sort-constructors-first-spacing
Open

[analysis_server] Fix blank-line placement in sort_constructors_first fix#64041
hkarmoush wants to merge 2 commits into
dart-lang:mainfrom
hkarmoush:fix-sort-constructors-first-spacing

Conversation

@hkarmoush

@hkarmoush hkarmoush commented Aug 13, 2026

Copy link
Copy Markdown

Summary

  • The sort_constructors_first quick-fix moved a constructor's leading whitespace gap (including any blank line separating it from its previous sibling) verbatim to the insertion point, producing a stray leading blank line at the top of the body and no separator between the relocated constructor and the member that now follows it.
  • The constructor now always starts on its own line at the insertion point with no leading blank line. If a blank line used to separate it from its previous member, that separation moves to after the constructor instead — unless the insertion point already has its own blank line there naturally, to avoid doubling up.

Fixes #60703

Test plan

  • Added test_noBlankLineAfterOpeningBrace, test_enum_noBlankLineAfterSemicolon, and test_enum_blankLineMovesFromOldGapToAfterConstructor to sort_constructor_first_test.dart, covering the class and enum scenarios from the issue.
  • Updated SortConstructorFirstBulkTest.test_single_class's expected output to match the corrected, consistent spacing behavior.
  • dart test test/src/services/correction/fix/sort_constructor_first_test.dart — all 17 tests pass.
  • Full regression run of pkg/analysis_server/test/src/services/correction/fix/ — all 4765 tests pass, no regressions.
  • dart format / dart analyze clean on changed files.

… fix

The quick-fix moved a constructor's leading gap (any blank line
separating it from its previous sibling) verbatim to the insertion
point. That turned a blank line that used to separate the constructor
from the *previous* member into a stray leading blank line at the top
of the body, while leaving no separator between the relocated
constructor and the member that now follows it.

The constructor now always starts on its own line at the insertion
point with no leading blank line. If a blank line used to separate it
from its previous member, that separation is preserved by moving it
after the constructor instead, unless the insertion point already has
its own blank line there naturally, to avoid doubling up.

Fixes dart-lang#60703
@copybara-service

Copy link
Copy Markdown

Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at:

https://dart-review.googlesource.com/c/sdk/+/536000

Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly.

Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR).

@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/536000 has been updated with the latest commits from this pull request.

…ed constructor

Address review feedback on the previous commit: when a constructor is
moved to sit right after an enum's constant list, and the file
already separates members with blank lines (evidenced by a blank line
having separated the constructor from its own previous member), also
add a blank line between the constant list and the relocated
constructor, so that boundary isn't left inconsistent with the rest
of the file's style. A class body has no analogous boundary: its
insertion point is the opening brace, where a leading blank line is
never wanted.
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/536000 has been updated with the latest commits from this pull request.

1 similar comment
@copybara-service

Copy link
Copy Markdown

https://dart-review.googlesource.com/c/sdk/+/536000 has been updated with the latest commits from this pull request.

@copybara-service

Copy link
Copy Markdown

CL has new comments, please view and respond to them in Gerrit.

If a reviewer requested changes, push new commits to this PR and it will be automatically copied to Gerrit. After that you can mark reviewer comments as resolved in Gerrit and request another round of reviews.

Note: when you add comments in Gerrit they only become visible after you send them by clicking Reply and Send.

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

Successfully merging this pull request may close these issues.

Issues with quick fix for sort_constructors_first lint rule

1 participant