DisposaBoy / GoSublime

A Golang plugin collection for SublimeText 3, providing code completion and other IDE-like features.
MIT License
3.42k stars 302 forks source link

Unable to configure GoImports linter #939

Open gz-c opened 4 years ago

gz-c commented 4 years ago

There is no way to pass argument to the goimports linter. Previously this could be done with something like:

"fmt_cmd": ["goimports", "-srcdir", "$_dir", "-local", "github.com/gz-c/foo"],

Now it seems that the Args are buried inside here: https://github.com/KurokuLabs/margo/blob/45053645555797217b3f6df7d90975cbfae7e609/golang/gofmt.go#L47

In my case I use the -local flag to sort the imports differently. It would need to be configured per-package.

DisposaBoy commented 4 years ago

You can just create your own reducer to do fmt'ing:

    mg.NewReducer(func(mx *mg.Ctx) *mg.State {
        return mgformat.FmtCmd{
            Name:  "goimports",
            Args:  []string{"-srcdir", mx.View.Filename()},
            Langs: []mg.Lang{mg.Go},
            Actions: []mg.Action{
                mg.ViewFmt{},
                mg.ViewPreSave{},
            },
        }.Reduce(mx)
    }),