Problem: tl;dr—Previously the generation approach was just to ignore all import statements and let goimports generate the correct import block. This mostly worked but broke down in the case of an import being renamed.
Described more thoroughly in #19.
Solution: The naive approach was to just pull out the imports on the first pass then reinsert them in an import ( ... ) block at the top but that fails in the case that imports were done as a series of import "..." statements. This change collects all imports for each pass through the file (meaning duplicates will be found in the case of multiple type assignments) then reconstructs the file before passing to imports.Process.
I added a test for the broken case this change resolves and updated the test where this changes output.
Problem: tl;dr—Previously the generation approach was just to ignore all import statements and let
goimports
generate the correct import block. This mostly worked but broke down in the case of an import being renamed.Described more thoroughly in #19.
Solution: The naive approach was to just pull out the imports on the first pass then reinsert them in an
import ( ... )
block at the top but that fails in the case that imports were done as a series ofimport "..."
statements. This change collects all imports for each pass through the file (meaning duplicates will be found in the case of multiple type assignments) then reconstructs the file before passing toimports.Process
.I added a test for the broken case this change resolves and updated the test where this changes output.