Skip to content

fix: deduplicate identical generated import bindings - #126

Merged
hexdigest merged 2 commits into
hexdigest:masterfrom
jihtsan:codex/98-deduplicate-imports
Oct 21, 2026
Merged

hexdigest merged 2 commits into
hexdigest:masterfrom
jihtsan:codex/98-deduplicate-imports

Conversation

@jihtsan

@jihtsan jihtsan commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #98.

The default header and {{.Import}} can emit the same aliased import in separate blocks. After goimports resolves the generated source, remove duplicate import bindings by decoded path and explicit alias. Keep the first binding, distinct aliases, comments, custom headers and the existing template helper compatible. No template changes are required.

Validation on Go 1.24.2:

  • Both duplicate-generation regression cases fail on the original implementation and pass with this change; the distinct-alias control passes.
  • go test -count=1 ./..., go test -race ./..., go vet ./... and go build ./... pass.
  • The locked golangci-lint v1.64.8 command from the Makefile passes: golangci-lint run --enable=goimports --disable=unused --exclude=S1023,'Error return value' ./....
  • Generated the Prometheus wrapper from the issue author's public reproduction with the built CLI. It now contains one dtoAlias import and go test ./... compiles it.
  • An independent public-generator harness verifies nine boundary cases, including cross-block imports, distinct aliases, custom headers, raw/quoted paths and comment preservation.

Validation ran on macOS; Linux and Windows were not run locally.

jihtsan and others added 2 commits October 18, 2026 18:01
@hexdigest
hexdigest merged commit d146d4f into hexdigest:master Oct 21, 2026
1 check passed
@hexdigest

Copy link
Copy Markdown
Owner

Thank you @jihtsan !

This one has been bothering me for a very long time.

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.

Duplicate import statements with gowrap >=1.4.0

2 participants