forked from bflad/tfproviderlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAT002.go
51 lines (40 loc) · 1.48 KB
/
AT002.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
// Package AT002 defines an Analyzer that checks for
// acceptance test names including the word import
package AT002
import (
"go/ast"
"strings"
"golang.org/x/tools/go/analysis"
"github.com/bflad/tfproviderlint/passes/commentignore"
"github.com/bflad/tfproviderlint/passes/testaccfuncdecl"
)
const Doc = `check for acceptance test function names including the word import
The AT002 analyzer reports where the word import or Import is used
in an acceptance test function name, which generally means there is an extraneous
acceptance test. ImportState testing should be included as a TestStep with each
applicable acceptance test, rather than a separate test that only verifies import
of a single test configuration.`
const analyzerName = "AT002"
var Analyzer = &analysis.Analyzer{
Name: analyzerName,
Doc: Doc,
Requires: []*analysis.Analyzer{
testaccfuncdecl.Analyzer,
commentignore.Analyzer,
},
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer)
testAccFuncs := pass.ResultOf[testaccfuncdecl.Analyzer].([]*ast.FuncDecl)
for _, testAccFunc := range testAccFuncs {
if ignorer.ShouldIgnore(analyzerName, testAccFunc) {
continue
}
funcName := testAccFunc.Name.Name
if strings.Contains(funcName, "_import") || strings.Contains(funcName, "_Import") {
pass.Reportf(testAccFunc.Name.NamePos, "%s: acceptance test function name should not include import", analyzerName)
}
}
return nil, nil
}