Skip to content

feat(bufformat): add comment spacing normalization#4430

Open
xingzihai wants to merge 1 commit intobufbuild:mainfrom
xingzihai:feat/comment-spacing-normalization
Open

feat(bufformat): add comment spacing normalization#4430
xingzihai wants to merge 1 commit intobufbuild:mainfrom
xingzihai:feat/comment-spacing-normalization

Conversation

@xingzihai
Copy link
Copy Markdown

Summary

This PR implements comment spacing normalization for buf format as requested in issue #4198.

Changes

  • Added normalizeCommentSpacing function in formatter.go that ensures single-line comments have a space after the // delimiter
  • Added test case in formatter_test.go to verify the behavior
  • Added test data files for the comment_spacing scenario

Behavior

Comments without proper spacing are transformed:

  • //no space// no space
  • //TODO:// TODO:
  • //FIXME:// FIXME:

Comments with existing proper spacing (like // one space or // multiple spaces) remain unchanged.

Testing

Added test case testFormatNoDiff(t, "testdata/proto3/comment_spacing") which verifies:

  1. Input file with various comment spacing scenarios
  2. Output file with normalized spacing

Related Issue

Closes #4198


This implementation was created to address the feature request for consistent comment formatting in protobuf files.

Normalize single-line comment spacing to ensure consistent formatting.
Comments without proper spacing after // are transformed:
- //no space -> // no space
- //TODO: -> // TODO:

This addresses issue bufbuild#4198 for comment formatting consistency.

Changes:
- Add normalizeCommentSpacing function in formatter.go
- Add test case in formatter_test.go
- Add test data for comment_spacing scenario
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.

format comments with consistent spacing

1 participant