-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchecks.go
48 lines (40 loc) · 1.31 KB
/
checks.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
package vsaur
import (
"context"
"fmt"
)
// Checker is a static analysis tool that given a module top level directory
// will report back a list of locations where issues have been found
type Checker interface {
CheckName() string
Check(context.Context) ([]Issue, error)
}
// Issue is a problem found in the project by a checker
type Issue struct {
Description string
Path string // file system path to issue
Line uint // line number within file (starting at 0)
Column uint // column within line ( starting at 0)
}
// CheckerFactory constructs a checker from a module's top level directory path
type CheckerFactory func(moddir string) Checker
// allCheckers is a collection of all known checker factories keyed by the
// checker name
var allCheckers = map[string]CheckerFactory{}
// AllCheckers returns a list of all known checker names
func AllCheckerMakers() []CheckerFactory {
var checkers []CheckerFactory
for _, v := range allCheckers {
checkers = append(checkers, v)
}
return checkers
}
// MustAddChecker will add a checker to the global list. If there is a name
// conflict, a panic will be raised.
func MustAddChecker(name string, c CheckerFactory) {
_, ok := allCheckers[name]
if ok {
panic(fmt.Errorf("a checker is already registered as %s", name))
}
allCheckers[name] = c
}