From aaa76ee82d78834d5701ca08f4970dcae9a758fc Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Thu, 9 Aug 2018 15:43:28 -0400 Subject: [PATCH] go/packages: cleanup style This change addresses some style issues pointed out by rsc in golang.org/cl/126177. It doesn't fix the comment on listfunc or the comment on the processing of the containing directories. Those will be handled in a separate cl. Change-Id: I2094ad1e5e2ee181a646466675f4d993bd69ff9b Reviewed-on: https://go-review.googlesource.com/128897 Run-TryBot: Michael Matloob TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox Reviewed-by: Alan Donovan --- go/packages/golist/golist.go | 19 +++++++++---------- go/packages/packages.go | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/go/packages/golist/golist.go b/go/packages/golist/golist.go index f0bbeb4b..a04b1b9d 100644 --- a/go/packages/golist/golist.go +++ b/go/packages/golist/golist.go @@ -44,18 +44,17 @@ func LoadRaw(ctx context.Context, cfg *raw.Config, patterns ...string) ([]string } // Determine files requested in contains patterns var containFiles []string - { - restPatterns := make([]string, 0, len(patterns)) - for _, pattern := range patterns { - if containFile := strings.TrimPrefix(pattern, "contains:"); containFile != pattern { - containFiles = append(containFiles, containFile) - } else { - restPatterns = append(restPatterns, pattern) - } + restPatterns := make([]string, 0, len(patterns)) + for _, pattern := range patterns { + if strings.HasPrefix(pattern, "contains:") { + containFile := strings.TrimPrefix(pattern, "contains:") + containFiles = append(containFiles, containFile) + } else { + restPatterns = append(restPatterns, pattern) } - containFiles = absJoin(cfg.Dir, containFiles) - patterns = restPatterns } + containFiles = absJoin(cfg.Dir, containFiles) + patterns = restPatterns // TODO(matloob): Remove the definition of listfunc and just use golistPackages once go1.12 is released. var listfunc func(ctx context.Context, cfg *raw.Config, words ...string) ([]string, []*raw.Package, error) diff --git a/go/packages/packages.go b/go/packages/packages.go index 2bdac145..89076ab6 100644 --- a/go/packages/packages.go +++ b/go/packages/packages.go @@ -258,8 +258,8 @@ func newLoader(cfg *Config) *loader { ld.Context = context.Background() } if ld.Dir == "" { - if cwd, err := os.Getwd(); err == nil { - ld.Dir = cwd + if dir, err := os.Getwd(); err == nil { + ld.Dir = dir } }