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 {
// 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))
}
}
// 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))
}
}
// 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)