Skip to content

fix: preserve standalone comments in import blocks#244

Open
yammesicka wants to merge 1 commit into
daixiang0:masterfrom
yammesicka:fix/preserve-standalone-import-comments
Open

fix: preserve standalone comments in import blocks#244
yammesicka wants to merge 1 commit into
daixiang0:masterfrom
yammesicka:fix/preserve-standalone-import-comments

Conversation

@yammesicka
Copy link
Copy Markdown

@yammesicka yammesicka commented Mar 5, 2026

Fixes #135.

GCI was removing standalone line comments (e.g. // +kubebuilder:scaffold:imports) from import blocks when reformatting imports.

Limitations

Only // line comments are preserved. Standalone /* */ block comments as the last element before ) are not supported because go/format merges them with the closing ), producing non-idempotent output.

@yammesicka yammesicka force-pushed the fix/preserve-standalone-import-comments branch 2 times, most recently from a8b836d to b8565a7 Compare March 5, 2026 17:15
Fixes daixiang0#135.

GCI was removing standalone line comments (e.g. // +kubebuilder:scaffold:imports)
from import blocks. This change scans the region between the last import and the
closing ) for standalone // line comments and preserves them in the output.

Standalone /* */ block comments are not preserved because go/format merges them
with the closing ), producing non-idempotent output.

Signed-off-by: yammesicka <yammesicka@gmail.com>
@yammesicka yammesicka force-pushed the fix/preserve-standalone-import-comments branch from b8565a7 to 74d9006 Compare March 5, 2026 17:35
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.

Fix removal of kubebuilder imports marker

1 participant