Joined in one import declaration (except "C", which is always alone)
Splitted in groups (can be tweaked with custom imports grouper)
Sorted lexicographically within each group
Provides default formatting for
Multiline functions declarations
Multiline calls
Multiline composite literals, slices and arrays get a special care at that
Multiline chaining
Screencast
Remarks
fancyfmt stores a cache of packages from standard library in a os.TempDir() directory. This was done to speedup
things as package.Load(cfg, "std") is slow, about 0.2s on my machine, cached access is about ten times faster. You
may notice a slugishness in case of the first formatting in the screencast, that is it. The further formats are much
faster.
fancyfmt mutates []byte{…} literals if they only have numbers replacing them with hex numbers.
You may fix composite literals formatting (except the new line before the first item and after the last one) by
adding a comment after an element.
type ImportsGrouper interface {
Weight(path string) int}
ImportsGrouper a facility to give an import path a certain weight what will be used to group a set of imports by it,
i.e. import paths with the same weight will be in one groups of imports
DefaultImportsGrouper provides an import grouper with a policy that is supposed to be the default:
"C" - 0
Standard library - 1
3rd party - 2
Current project - 3
Relative imports - 4
It tried to determine a current project once called and may return an error if it failed to detect it. Use
DefaultImportGroupsWithCurrent if you don't need it or need to set up your own