imports: allow nil Options in Process

Forgot this case in CL 175437.

Change-Id: I9825cf010611fed9f47b1a87fc793bf3a5a36f68
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178257
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Heschi Kreinick 2019-05-20 18:00:48 -04:00
parent eda2c2f1ae
commit 26647e34d3
2 changed files with 3 additions and 3 deletions

View File

@ -35,6 +35,9 @@ var LocalPrefix string
// so it is important that filename be accurate. // so it is important that filename be accurate.
// To process data ``as if'' it were in filename, pass the data as a non-nil src. // To process data ``as if'' it were in filename, pass the data as a non-nil src.
func Process(filename string, src []byte, opt *Options) ([]byte, error) { func Process(filename string, src []byte, opt *Options) ([]byte, error) {
if opt == nil {
opt = &Options{Comments: true, TabIndent: true, TabWidth: 8}
}
intopt := &intimp.Options{ intopt := &intimp.Options{
Env: &intimp.ProcessEnv{ Env: &intimp.ProcessEnv{
GOPATH: build.Default.GOPATH, GOPATH: build.Default.GOPATH,

View File

@ -42,9 +42,6 @@ type Options struct {
// Process implements golang.org/x/tools/imports.Process with explicit context in env. // Process implements golang.org/x/tools/imports.Process with explicit context in env.
func Process(filename string, src []byte, opt *Options) ([]byte, error) { func Process(filename string, src []byte, opt *Options) ([]byte, error) {
if opt == nil {
opt = &Options{Comments: true, TabIndent: true, TabWidth: 8}
}
if src == nil { if src == nil {
b, err := ioutil.ReadFile(filename) b, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {