|
|
@@ -170,41 +170,6 @@ var targets = map[string]target{
|
|
|
},
|
|
|
}
|
|
|
|
|
|
-var (
|
|
|
- // fast linters complete in a fraction of a second and might as well be
|
|
|
- // run always as part of the build
|
|
|
- fastLinters = []string{
|
|
|
- "deadcode",
|
|
|
- "golint",
|
|
|
- "ineffassign",
|
|
|
- "vet",
|
|
|
- }
|
|
|
-
|
|
|
- // slow linters take several seconds and are run only as part of the
|
|
|
- // "metalint" command.
|
|
|
- slowLinters = []string{
|
|
|
- "gosimple",
|
|
|
- "staticcheck",
|
|
|
- "structcheck",
|
|
|
- "unused",
|
|
|
- "varcheck",
|
|
|
- }
|
|
|
-
|
|
|
- // Which parts of the tree to lint
|
|
|
- lintDirs = []string{".", "./lib/...", "./cmd/..."}
|
|
|
-
|
|
|
- // Messages to ignore
|
|
|
- lintExcludes = []string{
|
|
|
- ".pb.go",
|
|
|
- "should have comment",
|
|
|
- "protocol.Vector composite literal uses unkeyed fields",
|
|
|
- "cli.Requires composite literal uses unkeyed fields",
|
|
|
- "Use DialContext instead", // Go 1.7
|
|
|
- "os.SEEK_SET is deprecated", // Go 1.7
|
|
|
- "SA4017", // staticcheck "is a pure function but its return value is ignored"
|
|
|
- }
|
|
|
-)
|
|
|
-
|
|
|
func init() {
|
|
|
// The "syncthing" target includes a few more files found in the "etc"
|
|
|
// and "extra" dirs.
|
|
|
@@ -285,7 +250,7 @@ func runCommand(cmd string, target target) {
|
|
|
tags = []string{"noupgrade"}
|
|
|
}
|
|
|
install(target, tags)
|
|
|
- metalint(fastLinters, lintDirs)
|
|
|
+ metalintShort()
|
|
|
|
|
|
case "build":
|
|
|
var tags []string
|
|
|
@@ -293,7 +258,7 @@ func runCommand(cmd string, target target) {
|
|
|
tags = []string{"noupgrade"}
|
|
|
}
|
|
|
build(target, tags)
|
|
|
- metalint(fastLinters, lintDirs)
|
|
|
+ metalintShort()
|
|
|
|
|
|
case "test":
|
|
|
test("./lib/...", "./cmd/...")
|
|
|
@@ -329,14 +294,13 @@ func runCommand(cmd string, target target) {
|
|
|
clean()
|
|
|
|
|
|
case "vet":
|
|
|
- metalint(fastLinters, lintDirs)
|
|
|
+ metalintShort()
|
|
|
|
|
|
case "lint":
|
|
|
- metalint(fastLinters, lintDirs)
|
|
|
+ metalintShort()
|
|
|
|
|
|
case "metalint":
|
|
|
- metalint(fastLinters, lintDirs)
|
|
|
- metalint(slowLinters, lintDirs)
|
|
|
+ metalint()
|
|
|
|
|
|
case "version":
|
|
|
fmt.Println(getVersion())
|
|
|
@@ -1055,59 +1019,12 @@ func macosCodesign(file string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func metalint(linters []string, dirs []string) {
|
|
|
- ok := true
|
|
|
- if isGometalinterInstalled() {
|
|
|
- if !gometalinter(linters, dirs, lintExcludes...) {
|
|
|
- ok = false
|
|
|
- }
|
|
|
- }
|
|
|
- if !ok {
|
|
|
- log.Fatal("Build succeeded, but there were lint warnings")
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func isGometalinterInstalled() bool {
|
|
|
- if _, err := runError("gometalinter", "--disable-all"); err != nil {
|
|
|
- log.Println("gometalinter is not installed")
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
+func metalint() {
|
|
|
+ lazyRebuildAssets()
|
|
|
+ runPrint("go", "test", "-run", "Metalint", "./meta")
|
|
|
}
|
|
|
|
|
|
-func gometalinter(linters []string, dirs []string, excludes ...string) bool {
|
|
|
- params := []string{"--disable-all", "--concurrency=2", "--deadline=300s"}
|
|
|
-
|
|
|
- for _, linter := range linters {
|
|
|
- params = append(params, "--enable="+linter)
|
|
|
- }
|
|
|
-
|
|
|
- for _, exclude := range excludes {
|
|
|
- params = append(params, "--exclude="+exclude)
|
|
|
- }
|
|
|
-
|
|
|
- for _, dir := range dirs {
|
|
|
- params = append(params, dir)
|
|
|
- }
|
|
|
-
|
|
|
- bs, _ := runError("gometalinter", params...)
|
|
|
-
|
|
|
- nerr := 0
|
|
|
- lines := make(map[string]struct{})
|
|
|
- for _, line := range strings.Split(string(bs), "\n") {
|
|
|
- if line == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
- if _, ok := lines[line]; ok {
|
|
|
- continue
|
|
|
- }
|
|
|
- log.Println(line)
|
|
|
- if strings.Contains(line, "executable file not found") {
|
|
|
- log.Println(` - Try "go run build.go setup" to install missing tools`)
|
|
|
- }
|
|
|
- lines[line] = struct{}{}
|
|
|
- nerr++
|
|
|
- }
|
|
|
-
|
|
|
- return nerr == 0
|
|
|
+func metalintShort() {
|
|
|
+ lazyRebuildAssets()
|
|
|
+ runPrint("go", "test", "-short", "-run", "Metalint", "./meta")
|
|
|
}
|