Export AddImportFix and improve GCI-aware import insertion - #30
Merged
mmorel-35 merged 3 commits intoMar 16, 2026
Conversation
- Export addImportFix → AddImportFix so all checkers can share it without duplication (negated-assert, graceful-teardown, etc.) - Improve importInsertEdit: scan non-stdlib specs in file order and insert before the first entry whose path is lexicographically greater, so that go/format produces alphabetically sorted, GCI-compliant import groups - Use safe type assertion in the new scan loop (imp, ok := spec.(*ast.ImportSpec)) - Update httpNetPkgName to call AddImportFix - Add unit tests: AlreadyImported, GCIOrdering, GCIOrderingPreservesGroup, BlankImported Co-authored-by: mmorel-35 <6032561+mmorel-35@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor importfix and challenge methods for better visibility
Export AddImportFix and improve GCI-aware import insertion
Mar 16, 2026
Owner
|
@copilot , |
Co-authored-by: mmorel-35 <6032561+mmorel-35@users.noreply.github.com>
Author
Fixed in fb0557a. The |
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.
addImportFixwas package-private, forcing every new checker (negated-assert, graceful-teardown, …) to either duplicate it or addexport_test.goworkarounds. Import insertion also blindly appended non-stdlib packages before), which breaks GCI group ordering when a file has blank-line-separated import groups.Changes
helpers_import.go—addImportFix→AddImportFix(exported);importInsertEditnow scans non-stdlib specs in file order and inserts before the first spec whose path is lexicographically greater, instead of appending at the end:helpers_http.go—httpNetPkgNameupdated to callAddImportFix.helpers_import_test.go— added unit tests forAddImportFix: already-imported (no-op edit), GCI ordering, GCI group boundary preservation across blank lines, and blank-import (ok=false).📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.