From 6d32be89d569efd9d2426c967e8d133fd4abb9f0 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 16 Jul 2016 14:48:20 -0700 Subject: [PATCH] imports: minor fixes These are mostly comments for CL 24941 that didn't get sent quickly enough. strings.Trim(`\"`) works, but by accident. It trims all leading and trailing "s and \s, but there are never leading or trailing \s. Semantic line breaks and punctuation cleanup. The reflow of comments in the pkgName == "main" if block is to silence this spurious vet failure: fix.go:247: +build comment must appear before package clause and be followed by a blank line Plain sync.Once values are enough. Change-Id: I241f3025031b6f21605da78ea52066713a203327 Reviewed-on: https://go-review.googlesource.com/24983 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- imports/fix.go | 18 ++++++++---------- imports/fix_test.go | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/imports/fix.go b/imports/fix.go index 42f1cf92..73477e26 100644 --- a/imports/fix.go +++ b/imports/fix.go @@ -83,7 +83,7 @@ func fixImports(fset *token.FileSet, f *ast.File, filename string) (added []stri decls[v.Name.Name] = v break } - ipath := strings.Trim(v.Path.Value, `\"`) + ipath := strings.Trim(v.Path.Value, `"`) if ipath == "C" { break } @@ -184,7 +184,7 @@ func importPathToNameBasic(importPath, srcDir string) (packageName string) { // importPathToNameGoPath finds out the actual package name, as declared in its .go files. // If there's a problem, it falls back to using importPathToNameBasic. func importPathToNameGoPath(importPath, srcDir string) (packageName string) { - // Fast path for standard library without going to disk: + // Fast path for standard library without going to disk. if pkg, ok := stdImportPackage[importPath]; ok { return pkg } @@ -243,10 +243,8 @@ func importPathToNameGoPathParse(importPath, srcDir string) (packageName string, continue } if pkgName == "main" { - // Also skip package main, assuming it's a - // +build ignore generator or example. Since - // you can't import a package main anyway, - // there's no harm here. + // Also skip package main, assuming it's a +build ignore generator or example. + // Since you can't import a package main anyway, there's no harm here. continue } return pkgName, nil @@ -272,9 +270,9 @@ func init() { // Directory-scanning state. var ( // scanGoRootOnce guards calling scanGoRoot (for $GOROOT) - scanGoRootOnce = &sync.Once{} + scanGoRootOnce sync.Once // scanGoPathOnce guards calling scanGoPath (for $GOPATH) - scanGoPathOnce = &sync.Once{} + scanGoPathOnce sync.Once dirScanMu sync.RWMutex dirScan map[string]*pkg // abs dir path => *pkg @@ -615,8 +613,8 @@ func loadExportsGoPath(expectPackage, dir string) map[string]bool { // to satisfy uses of pkg.X in the file. var findImport func(pkgName string, symbols map[string]bool, filename string) (foundPkg string, rename bool, err error) = findImportGoPath -// findImportGoPath is the normal implementation of findImport. (Some -// companies have their own internally) +// findImportGoPath is the normal implementation of findImport. +// (Some companies have their own internally.) func findImportGoPath(pkgName string, symbols map[string]bool, filename string) (foundPkg string, rename bool, err error) { // Fast path for the standard library. // In the common case we hopefully never have to scan the GOPATH, which can diff --git a/imports/fix_test.go b/imports/fix_test.go index d9534605..0cd596cd 100644 --- a/imports/fix_test.go +++ b/imports/fix_test.go @@ -982,8 +982,8 @@ type Buffer2 struct {} func withEmptyGoPath(fn func()) { dirScanMu.Lock() - scanGoRootOnce = &sync.Once{} - scanGoPathOnce = &sync.Once{} + scanGoRootOnce = sync.Once{} + scanGoPathOnce = sync.Once{} dirScan = nil ignoredDirs = nil dirScanMu.Unlock()