Skip to content

fix(protobuf): count string literals so /* inside an option is not a comment - #745

Merged
boyter merged 1 commit into
boyter:masterfrom
YuriNachos:YuriNachos/quick-proto-string-literals
Aug 11, 2026
Merged

fix(protobuf): count string literals so /* inside an option is not a comment#745
boyter merged 1 commit into
boyter:masterfrom
YuriNachos:YuriNachos/quick-proto-string-literals

Conversation

@YuriNachos

Copy link
Copy Markdown
Contributor

Problem

Protocol Buffers declares an empty quotes list, 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.

syntax = "proto3";
package demo;

option (desc) = "see /* legacy block";

message Foo {
  string name = 1;
}

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 regenerate processor/constants.go. No other language is touched.

Test plan

go test ./... — green, including a new TestCountStatsProtobufStringNotComment that feeds the option-string above and asserts 8 lines / 6 code / 0 comments / 2 blanks. On master the same input returns 4 comments (the test fails); with the fix it returns 0 comments.

I licence this contribution under the MIT licence.

…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.
@pr-insights pr-insights Bot added L/complexity Low complexity M/size Normal or medium sized change labels Aug 10, 2026
@boyter
boyter merged commit 6aad760 into boyter:master Aug 11, 2026
4 checks passed
@boyter

boyter commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L/complexity Low complexity M/size Normal or medium sized change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants