Skip to content

Trailing comma in for loop parts updaters #1354

@munificent

Description

@munificent

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions