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

Update buf format to work correctly with editions #2969

Merged
merged 1 commit into from
May 13, 2024

Conversation

jhump
Copy link
Member

@jhump jhump commented May 10, 2024

Thanks @stefanvanburen for noticing this!

The formatter needed to be updated to be aware of the edition AST node (which appears instead of syntax in Editions files) and also needed updates to reserved names, which use identifiers instead of string literals in Editions.

if editionNode != nil {
f.writeEdition(editionNode)
}
if syntaxNode := f.fileNode.Syntax; syntaxNode != nil && editionNode == nil {
Copy link
Member

Choose a reason for hiding this comment

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

This would effectively wipe a syntax line from the file if an edition line exists, but that seems reasonable, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

They cannot both exist. You either specify syntax proto2 or proto3 or you specify an edition.

Copy link
Member

Choose a reason for hiding this comment

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

makes sense — just wondering if we should leave it up to a linter or a buf build failing to point that out to the user, rather than removing it altogether. But I don't think this is unreasonable behavior, and should be a niche case anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's an invariant of the AST. This logic is really here just to try to produce a valid source file even if there's something unexpectedly wrong with the AST. FWIW, we already do similar in the reserved nodes, where we prefer names, then identifiers, and then ranges. If a node had more than one set, the others would be ignored (which is correct to produce a valid source file since only one is allowed).

@jhump jhump merged commit 137015e into dev May 13, 2024
11 checks passed
@jhump jhump deleted the jh/formatter-works-with-editions branch May 13, 2024 13:41
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.

None yet

3 participants