Denis Isaev c02a6daa5c Fix #263: fix goimports performance with modules
Apply https://go-review.googlesource.com/c/tools/+/132598/ as a
temporary fix before a proper fix is in golang.org/x/tools
2018-11-05 12:37:54 +03:00

34 lines
527 B
Go

package goimports
import (
"bytes"
"fmt"
"io/ioutil"
"github.com/golangci/tools/imports"
)
func Run(filename string) ([]byte, error) {
src, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
res, err := imports.Process(filename, src, options)
if err != nil {
return nil, err
}
if bytes.Equal(src, res) {
return nil, nil
}
// formatting has changed
data, err := diff(src, res, filename)
if err != nil {
return nil, fmt.Errorf("error computing diff: %s", err)
}
return data, nil
}