forked from bflad/tfproviderlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAT008.go
58 lines (43 loc) · 1.33 KB
/
AT008.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
package AT008
import (
"go/ast"
"github.com/bflad/tfproviderlint/passes/commentignore"
"github.com/bflad/tfproviderlint/passes/testaccfuncdecl"
"golang.org/x/tools/go/analysis"
)
const Doc = `check for acceptance test function declaration *testing.T parameter naming
The AT008 analyzer reports where the *testing.T parameter of an acceptance test
declaration is not named t, which is a standard convention.`
const analyzerName = "AT008"
var Analyzer = &analysis.Analyzer{
Name: analyzerName,
Doc: Doc,
Requires: []*analysis.Analyzer{
commentignore.Analyzer,
testaccfuncdecl.Analyzer,
},
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer)
funcDecls := pass.ResultOf[testaccfuncdecl.Analyzer].([]*ast.FuncDecl)
for _, funcDecl := range funcDecls {
if ignorer.ShouldIgnore(analyzerName, funcDecl) {
continue
}
params := funcDecl.Type.Params
if params == nil || len(params.List) != 1 {
continue
}
firstParam := params.List[0]
if firstParam == nil || len(firstParam.Names) != 1 {
continue
}
name := firstParam.Names[0]
if name == nil || name.Name == "t" {
continue
}
pass.Reportf(name.Pos(), "%s: acceptance test function declaration *testing.T parameter should be named t", analyzerName)
}
return nil, nil
}