blob: 3f938db6474384a9021ea87f70afbe546fb03916 (
plain)
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
|
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"strings"
)
func main() {
if err := lint(); err != nil {
fmt.Printf("error: %v\n", err)
os.Exit(1)
}
}
func lint() (err error) {
cmd := exec.Command("golint", "./...")
cmd.Stderr = os.Stderr
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil
}
if err := cmd.Start(); err != nil {
return err
}
defer func() {
if waitErr := cmd.Wait(); waitErr != nil {
err = fmt.Errorf("wait error: %v", waitErr)
}
}()
scanner := bufio.NewScanner(stdout)
offenses := 0
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "vendor/") || strings.HasPrefix(line, "ruby/vendor/") {
// We cannot and should not "fix" vendored code.
continue
}
offenses++
fmt.Println(line)
}
if err := scanner.Err(); err != nil {
return fmt.Errorf("scanner error: %v", err)
}
if offenses > 0 {
return fmt.Errorf("golint found %d offense(s)", offenses)
}
return nil
}
|