mirror of
https://github.com/golang/go
synced 2024-11-18 08:54:45 -07:00
cmd/go: ignore dot and underscore files in fmt, fix, and get -fix
No test because as far as I can tell, there aren't existing tests for these. Fixes #18383 Change-Id: I06eaef05777a1474886167e3797c5bcd93189d1b Reviewed-on: https://go-review.googlesource.com/45156 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
a48998beb5
commit
760636d55a
@ -44,6 +44,28 @@ func RelPaths(paths []string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// FilterDotUnderscoreFiles returns a slice containing all elements
|
||||
// of path whose base name doesn't begin with "." or "_".
|
||||
func FilterDotUnderscoreFiles(path []string) []string {
|
||||
var out []string // lazily initialized
|
||||
for i, p := range path {
|
||||
base := filepath.Base(p)
|
||||
if strings.HasPrefix(base, ".") || strings.HasPrefix(base, "_") {
|
||||
if out == nil {
|
||||
out = append(make([]string, 0, len(path)), path[:i]...)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if out != nil {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
if out == nil {
|
||||
return path
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// IsTestFile reports whether the source file is a set of tests and should therefore
|
||||
// be excluded from coverage analysis.
|
||||
func IsTestFile(file string) bool {
|
||||
|
@ -33,6 +33,7 @@ func runFix(cmd *base.Command, args []string) {
|
||||
// Use pkg.gofiles instead of pkg.Dir so that
|
||||
// the command only applies to this package,
|
||||
// not to packages in subdirectories.
|
||||
base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), base.RelPaths(pkg.Internal.AllGoFiles)))
|
||||
files := base.FilterDotUnderscoreFiles(base.RelPaths(pkg.Internal.AllGoFiles))
|
||||
base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), files))
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ func runFmt(cmd *base.Command, args []string) {
|
||||
// Use pkg.gofiles instead of pkg.Dir so that
|
||||
// the command only applies to this package,
|
||||
// not to packages in subdirectories.
|
||||
base.Run(str.StringList(gofmt, "-l", "-w", base.RelPaths(pkg.Internal.AllGoFiles)))
|
||||
files := base.FilterDotUnderscoreFiles(base.RelPaths(pkg.Internal.AllGoFiles))
|
||||
base.Run(str.StringList(gofmt, "-l", "-w", files))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +298,8 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
|
||||
// due to wildcard expansion.
|
||||
for _, p := range pkgs {
|
||||
if *getFix {
|
||||
base.Run(cfg.BuildToolexec, str.StringList(base.Tool("fix"), base.RelPaths(p.Internal.AllGoFiles)))
|
||||
files := base.FilterDotUnderscoreFiles(base.RelPaths(p.Internal.AllGoFiles))
|
||||
base.Run(cfg.BuildToolexec, str.StringList(base.Tool("fix"), files))
|
||||
|
||||
// The imports might have changed, so reload again.
|
||||
p = load.ReloadPackage(arg, stk)
|
||||
|
Loading…
Reference in New Issue
Block a user