-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Analyzers: testcheckresourceattr, testcheckresourceattrset, testm…
…atchresourceattr
- Loading branch information
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package testcheckresourceattr | ||
|
||
import ( | ||
"go/ast" | ||
"reflect" | ||
|
||
"github.com/bflad/tfproviderlint/helper/terraformtype" | ||
"golang.org/x/tools/go/analysis" | ||
"golang.org/x/tools/go/analysis/passes/inspect" | ||
"golang.org/x/tools/go/ast/inspector" | ||
) | ||
|
||
var Analyzer = &analysis.Analyzer{ | ||
Name: "testcheckresourceattr", | ||
Doc: "find github.com/hashicorp/terraform-plugin-sdk/helper/resource.TestCheckResourceAttr calls for later passes", | ||
Requires: []*analysis.Analyzer{ | ||
inspect.Analyzer, | ||
}, | ||
Run: run, | ||
ResultType: reflect.TypeOf([]*ast.CallExpr{}), | ||
} | ||
|
||
func run(pass *analysis.Pass) (interface{}, error) { | ||
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) | ||
nodeFilter := []ast.Node{ | ||
(*ast.CallExpr)(nil), | ||
} | ||
var result []*ast.CallExpr | ||
|
||
inspect.Preorder(nodeFilter, func(n ast.Node) { | ||
callExpr := n.(*ast.CallExpr) | ||
|
||
if !terraformtype.IsHelperResourceFunc(callExpr.Fun, pass.TypesInfo, terraformtype.FuncNameTestCheckResourceAttr) { | ||
return | ||
} | ||
|
||
result = append(result, callExpr) | ||
}) | ||
|
||
return result, nil | ||
} |
41 changes: 41 additions & 0 deletions
41
passes/testcheckresourceattrset/testcheckresourceattrset.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package testcheckresourceattrset | ||
|
||
import ( | ||
"go/ast" | ||
"reflect" | ||
|
||
"github.com/bflad/tfproviderlint/helper/terraformtype" | ||
"golang.org/x/tools/go/analysis" | ||
"golang.org/x/tools/go/analysis/passes/inspect" | ||
"golang.org/x/tools/go/ast/inspector" | ||
) | ||
|
||
var Analyzer = &analysis.Analyzer{ | ||
Name: "testcheckresourceattrset", | ||
Doc: "find github.com/hashicorp/terraform-plugin-sdk/helper/resource.TestCheckResourceAttrSet calls for later passes", | ||
Requires: []*analysis.Analyzer{ | ||
inspect.Analyzer, | ||
}, | ||
Run: run, | ||
ResultType: reflect.TypeOf([]*ast.CallExpr{}), | ||
} | ||
|
||
func run(pass *analysis.Pass) (interface{}, error) { | ||
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) | ||
nodeFilter := []ast.Node{ | ||
(*ast.CallExpr)(nil), | ||
} | ||
var result []*ast.CallExpr | ||
|
||
inspect.Preorder(nodeFilter, func(n ast.Node) { | ||
callExpr := n.(*ast.CallExpr) | ||
|
||
if !terraformtype.IsHelperResourceFunc(callExpr.Fun, pass.TypesInfo, terraformtype.FuncNameTestCheckResourceAttrSet) { | ||
return | ||
} | ||
|
||
result = append(result, callExpr) | ||
}) | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package testmatchresourceattr | ||
|
||
import ( | ||
"go/ast" | ||
"reflect" | ||
|
||
"github.com/bflad/tfproviderlint/helper/terraformtype" | ||
"golang.org/x/tools/go/analysis" | ||
"golang.org/x/tools/go/analysis/passes/inspect" | ||
"golang.org/x/tools/go/ast/inspector" | ||
) | ||
|
||
var Analyzer = &analysis.Analyzer{ | ||
Name: "testmatchresourceattr", | ||
Doc: "find github.com/hashicorp/terraform-plugin-sdk/helper/resource.TestMatchResourceAttr calls for later passes", | ||
Requires: []*analysis.Analyzer{ | ||
inspect.Analyzer, | ||
}, | ||
Run: run, | ||
ResultType: reflect.TypeOf([]*ast.CallExpr{}), | ||
} | ||
|
||
func run(pass *analysis.Pass) (interface{}, error) { | ||
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) | ||
nodeFilter := []ast.Node{ | ||
(*ast.CallExpr)(nil), | ||
} | ||
var result []*ast.CallExpr | ||
|
||
inspect.Preorder(nodeFilter, func(n ast.Node) { | ||
callExpr := n.(*ast.CallExpr) | ||
|
||
if !terraformtype.IsHelperResourceFunc(callExpr.Fun, pass.TypesInfo, terraformtype.FuncNameTestMatchResourceAttr) { | ||
return | ||
} | ||
|
||
result = append(result, callExpr) | ||
}) | ||
|
||
return result, nil | ||
} |