generated from dogmatiq/template-go
/
lint.go
54 lines (44 loc) 路 1.21 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
package linter
import (
"github.com/dogmatiq/dogmacli/internal/linter/diagnostic"
"github.com/dogmatiq/dogmacli/internal/linter/internal/lint"
"github.com/dogmatiq/dogmacli/internal/linter/internal/rules/identity"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
)
// Lint runs the linter against the given packages.
func Lint(pkgs ...*packages.Package) []diagnostic.Diagnostic {
var diags []diagnostic.Diagnostic
prog, packages := ssautil.AllPackages(pkgs, SSABuilderMode)
prog.Build()
for i, pkg := range packages {
if pkg == nil {
continue
}
ctx := lint.NewContext(
pkgs[i],
prog,
pkg,
)
identity.Lint(ctx)
for _, d := range ctx.Diagnostics {
diags = append(diags, *d)
}
}
return diags
}
const (
// PackageLoadMode is the packages.LoadMode required by the linter.
PackageLoadMode = packages.NeedName |
packages.NeedFiles |
packages.NeedCompiledGoFiles |
packages.NeedSyntax |
packages.NeedTypes |
packages.NeedTypesInfo |
packages.NeedTypesSizes |
packages.NeedImports |
packages.NeedDeps
// SSABuilderMode is the ssa.BuilderMode required by the linter.
SSABuilderMode = ssa.SanityCheckFunctions | ssa.GlobalDebug
)