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

Trailing comma in for loop parts updaters #1354

Open
munificent opened this issue Jan 9, 2024 · 0 comments
Open

Trailing comma in for loop parts updaters #1354

munificent opened this issue Jan 9, 2024 · 0 comments

Comments

@munificent
Copy link
Member

Today I learned that the implementations allow a trailing comma in for loop updater clauses:

void main() {
  for (int i; i < 10; print("foo"), ++i, print("bar"),) {
    break;
  }
}

The current formatter preserves the trailing comma (yay!) but doesn't force the clauses to split like trailing commas do elsewhere. That's probably not worth fixing since we're working on the new style.

I don't know what the new formatter does with this. I think what it should do is just discard the trailing comma, whether the updaters split or not. (The other option would be to have it drop the trailing comma if the for loop parts don't split and add them if they do, but I don't think that's what users would want. When the for loop parts split, it's rarely because there are multiple updaters and usually because the clauses themselves don't all fit. In that case, I think users would be unpleasantly surprised to see a trailing comma appear after the last [and likely only] updater.)

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

No branches or pull requests

1 participant