forked from scroll-tech/scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.go
66 lines (51 loc) · 1.31 KB
/
lint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//go:build none
// +build none
package main
import (
"flag"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
)
const (
// GolangCIVersion to be used for linting.
GolangCIVersion = "github.com/golangci/golangci-lint/cmd/[email protected]"
)
// GOBIN environment variable.
func goBin() string {
if os.Getenv("GOBIN") == "" {
log.Fatal("GOBIN not set")
}
return os.Getenv("GOBIN")
}
func main() {
log.SetFlags(log.Lshortfile)
if _, err := os.Stat(filepath.Join("../build", "lint.go")); os.IsNotExist(err) {
log.Fatal("should run build from root dir")
}
lint()
}
//nolint:gosec
func lint() {
v := flag.Bool("v", false, "log verbosely")
// Make sure GOLANGCI is downloaded and available.
argsGet := []string{"install", GolangCIVersion}
cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), argsGet...)
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("could not list pkgs: %v\n%s", err, string(out))
}
cmd = exec.Command(filepath.Join(goBin(), "golangci-lint"))
cmd.Args = append(cmd.Args, "run", "--config", "../build/.golangci.yml")
if *v {
cmd.Args = append(cmd.Args, "-v")
}
fmt.Println("Linting...")
cmd.Stderr, cmd.Stdout = os.Stderr, os.Stdout
if err := cmd.Run(); err != nil {
log.Fatal("Error: Could not Lint ", "error: ", err, ", cmd: ", cmd)
}
}