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

Don't move a comment between a modifier and return type. #1588

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

munificent
Copy link
Member

When formatting a function, method, getter, or function type, the formatter hoists any leading comments out so that they don't force a split between the return type and body.

However, it failed to take into account modifiers that may occur before the return type but after the comment. If that happened, the comment would get moved before the modifiers.

Fix #1585.

When formatting a function, method, getter, or function type, the
formatter hoists any leading comments out so that they don't force a
split between the return type and body.

However, it failed to take into account modifiers that may occur before
the return type but after the comment. If that happened, the comment
would get moved before the modifiers.

Fix #1585.
@munificent munificent merged commit 0f448ba into main Oct 24, 2024
7 checks passed
@munificent munificent deleted the 1585-comment-before-function-modifier branch October 24, 2024 18:23
@@ -626,8 +627,9 @@ mixin PieceFactory {
// @meta
// // Weird place for comment.
// int f() {}
var leadingComments =
pieces.takeCommentsBefore(returnType.firstNonCommentToken);
var firstToken = modifiers.firstWhereOrNull((token) => token != null) ??
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] You could use a non-null filter instead of writing it as a callback.

Suggested change
var firstToken = modifiers.firstWhereOrNull((token) => token != null) ??
var firstToken = modifiers.nonNulls.firstOrNull ??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well crap. I landed this before I saw your suggestion. Today I learned about nonNulls.

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.

Formatter moves inline comment in external declaration
3 participants