Open
Description
Proposal Details
I'm considering to utilize imports.Process
with imports.LocalPrefix
. Configuring imports.LocalPrefix
is not concurrent safe since it is a global variable.
My proposal is adding LocalPrefix
field into Options
(same as Options
in internal).
type Options struct {
Fragment bool // Accept fragment of a source file (no package statement)
AllErrors bool // Report all errors (not just the first 10 on different lines)
// LocalPrefix is a comma-separated string of import path prefixes, which, if
// set, instructs Process to sort the import paths with the given prefixes
// into another group after 3rd-party packages.
LocalPrefix string
Comments bool // Print comments (true if nil *Options provided)
TabIndent bool // Use tabs for indent (true if nil *Options provided)
TabWidth int // Tab width (8 if nil *Options provided)
FormatOnly bool // Disable the insertion and deletion of imports
}
import.Process
will respect both opt.LocalPrefix
and imports.LocalPrefix
.
prefixes := []string{}
if LocalPrefix != "" {
prefixes = append(prefixes, LocalPrefix)
}
if opts.LocalPrefix != "" {
prefixes = append(prefixes, opts.LocalPrefix)
}
intopt := &intimp.Options{
Env: &intimp.ProcessEnv{
GocmdRunner: &gocommand.Runner{},
},
LocalPrefix: strings.Join(prefixes, ","),
AllErrors: opt.AllErrors,
Comments: opt.Comments,
FormatOnly: opt.FormatOnly,
Fragment: opt.Fragment,
TabIndent: opt.TabIndent,
TabWidth: opt.TabWidth,
}