fix(protobuf): count string literals so /* inside an option is not a comment - #745
Merged
boyter merged 1 commit intoAug 11, 2026
Merged
Conversation
…comment
Protocol Buffers declared an empty quotes list despite using "..." string
literals everywhere (syntax = "proto3"; option (x) = "..."; string field
defaults). With no string rule an option value such as "see /* legacy block"
was parsed as code: the embedded /* opened a block comment that ran to the
next */ or to EOF, swallowing every following line as a comment.
syntax = "proto3";
package demo;
option (desc) = "see /* legacy block";
message Foo {
string name = 1;
}
master reports 8 lines / 3 code / 4 comments; after the fix 8 lines / 6 code
/ 0 comments / 2 blanks. Add the single "..." quote rule and regenerate
processor/constants.go. Regression test asserts the option-string case.
Owner
|
Cheers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Protocol Buffersdeclares an emptyquoteslist, despite using"..."string literals throughout the language —syntax = "proto3";,option java_package = "com.example";, string field defaults, and validation regex options. With no string rule, an option value such as"see /* legacy block"is parsed as code: the embedded/*opens a block comment that runs to the next*/or to EOF, swallowing every following line as a comment.On master this reports 8 lines / 3 code / 4 comments — the blank line,
message Foo {,string name = 1;and}are all miscounted as comments.Fix
Add the single
"..."quote rule (Protobuf string literals are double-quoted) and regenerateprocessor/constants.go. No other language is touched.Test plan
go test ./...— green, including a newTestCountStatsProtobufStringNotCommentthat feeds the option-string above and asserts8 lines / 6 code / 0 comments / 2 blanks. On master the same input returns4 comments(the test fails); with the fix it returns0 comments.I licence this contribution under the MIT licence.