From dd16629584a66fe3a0cf0dae336b3cca51da15c7 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 9 Feb 2021 15:56:19 +0000 Subject: [PATCH] Update module bflad/tfproviderlint to v0.21.0 --- go.mod | 2 +- go.sum | 4 +- .../tfproviderlint/helper/astutils/package.go | 30 +++++++-- .../terraformtype/helper/acctest/consts.go | 6 ++ .../terraformtype/helper/acctest/funcs.go | 12 ++++ .../terraformtype/helper/acctest/package.go | 43 +++++++++++++ .../tfproviderlint/passes/AT001/AT001.go | 49 ++++++++++++++- .../tfproviderlint/passes/AT001/README.md | 6 +- .../tfproviderlint/passes/AT009/AT009.go | 50 +++++++++++++++ .../tfproviderlint/passes/AT009/README.md | 24 +++++++ .../bflad/tfproviderlint/passes/R018/R018.go | 40 ++++++++++++ .../tfproviderlint/passes/R018/README.md | 31 ++++++++++ .../bflad/tfproviderlint/passes/R019/R019.go | 62 +++++++++++++++++++ .../tfproviderlint/passes/R019/README.md | 28 +++++++++ .../tfproviderlint/passes/V009/README.md | 23 +++++++ .../bflad/tfproviderlint/passes/V009/V009.go | 56 +++++++++++++++++ .../tfproviderlint/passes/V010/README.md | 23 +++++++ .../bflad/tfproviderlint/passes/V010/V010.go | 56 +++++++++++++++++ .../bflad/tfproviderlint/passes/checks.go | 10 +++ .../passes/commentignore/ignore.go | 13 ++-- .../randstringfromcharsetcallexpr.go | 13 ++++ .../resourcedatahaschangescallexpr.go | 14 +++++ .../stringdoesnotmatchcallexpr.go | 13 ++++ .../stringmatchcallexpr.go | 13 ++++ .../timesleepcallexpr/timesleepfcallexpr.go | 11 ++++ vendor/modules.txt | 13 +++- 26 files changed, 628 insertions(+), 17 deletions(-) create mode 100644 vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/consts.go create mode 100644 vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/funcs.go create mode 100644 vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/package.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/AT009/AT009.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/AT009/README.md create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/R018/R018.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/R018/README.md create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/R019/R019.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/R019/README.md create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/V009/README.md create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/V009/V009.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/V010/README.md create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/V010/V010.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/helper/acctest/randstringfromcharsetcallexpr/randstringfromcharsetcallexpr.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatahaschangescallexpr/resourcedatahaschangescallexpr.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/helper/validation/stringdoesnotmatchcallexpr/stringdoesnotmatchcallexpr.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/helper/validation/stringmatchcallexpr/stringmatchcallexpr.go create mode 100644 vendor/github.com/bflad/tfproviderlint/passes/stdlib/timesleepcallexpr/timesleepfcallexpr.go diff --git a/go.mod b/go.mod index 7353ba2..cc2bd54 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( github.com/bflad/tfproviderdocs v0.7.0 - github.com/bflad/tfproviderlint v0.18.0 + github.com/bflad/tfproviderlint v0.21.0 github.com/client9/misspell v0.3.4 github.com/go-openapi/strfmt v0.19.5 github.com/golangci/golangci-lint v1.27.0 diff --git a/go.sum b/go.sum index 776a371..140e231 100644 --- a/go.sum +++ b/go.sum @@ -88,8 +88,8 @@ github.com/bflad/gopaniccheck v0.1.0 h1:tJftp+bv42ouERmUMWLoUn/5bi/iQZjHPznM00cP github.com/bflad/gopaniccheck v0.1.0/go.mod h1:ZCj2vSr7EqVeDaqVsWN4n2MwdROx1YL+LFo47TSWtsA= github.com/bflad/tfproviderdocs v0.7.0 h1:5cb+zUYLqvC4ZePLWqUE/oCmOl2D2nhJTOFfcWWN0ac= github.com/bflad/tfproviderdocs v0.7.0/go.mod h1:W6wVZPtBa6V5bpjaK1eJAoVCL/7B4Amfrld0dro+fHU= -github.com/bflad/tfproviderlint v0.18.0 h1:E4EWq051fp2zjxdUj9x6gNG27AcdyRkxip5XP03N840= -github.com/bflad/tfproviderlint v0.18.0/go.mod h1:0fdh7JywihC58Io8AZ+gpcmQtJggse0MCOXF2tMmnAQ= +github.com/bflad/tfproviderlint v0.21.0 h1:iSNU4khz+55oYA+5aXXMrz5Max4Mytb0JwPGhOwTIJo= +github.com/bflad/tfproviderlint v0.21.0/go.mod h1:0fdh7JywihC58Io8AZ+gpcmQtJggse0MCOXF2tMmnAQ= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= diff --git a/vendor/github.com/bflad/tfproviderlint/helper/astutils/package.go b/vendor/github.com/bflad/tfproviderlint/helper/astutils/package.go index e0de1b2..1ce1d7f 100644 --- a/vendor/github.com/bflad/tfproviderlint/helper/astutils/package.go +++ b/vendor/github.com/bflad/tfproviderlint/helper/astutils/package.go @@ -38,7 +38,10 @@ func IsModulePackageFunc(e ast.Expr, info *types.Info, module string, packageSuf switch x := e.X.(type) { case *ast.Ident: - return isModulePackagePath(module, packageSuffix, info.ObjectOf(x).(*types.PkgName).Imported().Path()) + switch xObj := info.ObjectOf(x).(type) { + case *types.PkgName: + return isModulePackagePath(module, packageSuffix, xObj.Imported().Path()) + } } case *ast.StarExpr: return IsModulePackageFunc(e.X, info, module, packageSuffix, funcName) @@ -60,7 +63,10 @@ func IsModulePackageFunctionFieldListType(e ast.Expr, info *types.Info, module s switch x := e.X.(type) { case *ast.Ident: - return isModulePackagePath(module, packageSuffix, info.ObjectOf(x).(*types.PkgName).Imported().Path()) + switch xObj := info.ObjectOf(x).(type) { + case *types.PkgName: + return isModulePackagePath(module, packageSuffix, xObj.Imported().Path()) + } } case *ast.StarExpr: return IsModulePackageFunctionFieldListType(e.X, info, module, packageSuffix, typeName) @@ -126,7 +132,10 @@ func IsPackageFunc(e ast.Expr, info *types.Info, packageSuffix string, funcName switch x := e.X.(type) { case *ast.Ident: - return strings.HasSuffix(info.ObjectOf(x).(*types.PkgName).Imported().Path(), packageSuffix) + switch xObj := info.ObjectOf(x).(type) { + case *types.PkgName: + return strings.HasSuffix(xObj.Imported().Path(), packageSuffix) + } } case *ast.StarExpr: return IsPackageFunc(e.X, info, packageSuffix, funcName) @@ -148,7 +157,10 @@ func IsPackageFunctionFieldListType(e ast.Expr, info *types.Info, packageSuffix switch x := e.X.(type) { case *ast.Ident: - return strings.HasSuffix(info.ObjectOf(x).(*types.PkgName).Imported().Path(), packageSuffix) + switch xObj := info.ObjectOf(x).(type) { + case *types.PkgName: + return strings.HasSuffix(xObj.Imported().Path(), packageSuffix) + } } case *ast.StarExpr: return IsPackageFunctionFieldListType(e.X, info, packageSuffix, typeName) @@ -215,7 +227,10 @@ func IsStdlibPackageFunc(e ast.Expr, info *types.Info, packagePath string, funcN switch x := e.X.(type) { case *ast.Ident: - return info.ObjectOf(x).(*types.PkgName).Imported().Path() == packagePath + switch xObj := info.ObjectOf(x).(type) { + case *types.PkgName: + return xObj.Imported().Path() == packagePath + } } case *ast.StarExpr: return IsStdlibPackageFunc(e.X, info, packagePath, funcName) @@ -237,7 +252,10 @@ func IsStdlibPackageFunctionFieldListType(e ast.Expr, info *types.Info, packageP switch x := e.X.(type) { case *ast.Ident: - return info.ObjectOf(x).(*types.PkgName).Imported().Path() == packagePath + switch xObj := info.ObjectOf(x).(type) { + case *types.PkgName: + return xObj.Imported().Path() == packagePath + } } case *ast.StarExpr: return IsStdlibPackageFunctionFieldListType(e.X, info, packagePath, typeName) diff --git a/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/consts.go b/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/consts.go new file mode 100644 index 0000000..14410de --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/consts.go @@ -0,0 +1,6 @@ +package acctest + +const ( + ConstNameCharSetAlpha = "CharSetAlpha" + ConstNameCharSetAlphaNum = "CharSetAlphaNum" +) diff --git a/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/funcs.go b/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/funcs.go new file mode 100644 index 0000000..adddbf2 --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/funcs.go @@ -0,0 +1,12 @@ +package acctest + +const ( + FuncNameRandInt = `RandInt` + FuncNameRandIntRange = `RandIntRange` + FuncNameRandIpAddress = `RandIpAddress` + FuncNameRandSSHKeyPair = `RandSSHKeyPair` + FuncNameRandString = `RandString` + FuncNameRandStringFromCharSet = `RandStringFromCharSet` + FuncNameRandTLSCert = `RandTLSCert` + FuncNameRandomWithPrefix = `RandomWithPrefix` +) diff --git a/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/package.go b/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/package.go new file mode 100644 index 0000000..05d223f --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest/package.go @@ -0,0 +1,43 @@ +package acctest + +import ( + "fmt" + "go/ast" + "go/types" + + "github.com/bflad/tfproviderlint/helper/astutils" + "github.com/bflad/tfproviderlint/helper/terraformtype" +) + +const ( + PackageModule = terraformtype.ModuleTerraformPluginSdk + PackageModulePath = `helper/acctest` + PackageName = `acctest` + PackagePath = PackageModule + `/` + PackageModulePath +) + +// IsConst returns if the expr is a constant in the acctest package +func IsConst(e ast.Expr, info *types.Info, constName string) bool { + // IsModulePackageFunc can handle any SelectorExpr name + return astutils.IsModulePackageFunc(e, info, PackageModule, PackageModulePath, constName) +} + +// IsFunc returns if the function call is in the acctest package +func IsFunc(e ast.Expr, info *types.Info, funcName string) bool { + return astutils.IsModulePackageFunc(e, info, PackageModule, PackageModulePath, funcName) +} + +// IsNamedType returns if the type name matches and is from the helper/acctest package +func IsNamedType(t *types.Named, typeName string) bool { + return astutils.IsModulePackageNamedType(t, PackageModule, PackageModulePath, typeName) +} + +// PackagePathVersion returns the import path for a module version +func PackagePathVersion(moduleVersion int) string { + switch moduleVersion { + case 0, 1: + return PackagePath + default: + return fmt.Sprintf("%s/v%d/%s", PackageModule, moduleVersion, PackageModulePath) + } +} diff --git a/vendor/github.com/bflad/tfproviderlint/passes/AT001/AT001.go b/vendor/github.com/bflad/tfproviderlint/passes/AT001/AT001.go index 277e482..21f8a0e 100644 --- a/vendor/github.com/bflad/tfproviderlint/passes/AT001/AT001.go +++ b/vendor/github.com/bflad/tfproviderlint/passes/AT001/AT001.go @@ -3,6 +3,7 @@ package AT001 import ( + "flag" "go/ast" "path/filepath" "strings" @@ -18,16 +19,33 @@ const Doc = `check for TestCase missing CheckDestroy The AT001 analyzer reports likely incorrect uses of TestCase which do not define a CheckDestroy function. CheckDestroy is used to verify that test infrastructure has been removed at the end of an acceptance test. -Ignores file names beginning with data_source_. + +Optional parameters: + - ignored-filename-prefixes Comma-separated list of filename prefixes to ignore, defaults to 'data_source_'. + - ignored-filename-suffixes Comma-separated list of filename suffixes to ignore, defaults to none. More information can be found at: https://www.terraform.io/docs/extend/testing/acceptance-tests/testcase.html#checkdestroy` const analyzerName = "AT001" +var ( + ignoredSuffixes string + ignoredPrefixes string +) + +func parseFlags() flag.FlagSet { + var flags = flag.NewFlagSet(analyzerName, flag.ExitOnError) + flags.StringVar(&ignoredPrefixes, "ignored-filename-prefixes", "data_source_", "Comma-separated list of file name prefixes to ignore") + flags.StringVar(&ignoredSuffixes, "ignored-filename-suffixes", "", "Comma-separated list of file name suffixes to ignore") + return *flags +} + + var Analyzer = &analysis.Analyzer{ Name: analyzerName, Doc: Doc, + Flags: parseFlags(), Requires: []*analysis.Analyzer{ commentignore.Analyzer, testcaseinfo.Analyzer, @@ -35,13 +53,40 @@ var Analyzer = &analysis.Analyzer{ Run: run, } +func isSuffixIgnored(fileName string, suffixesList string) bool { + suffixes := strings.Split(suffixesList, ",") + + for _, suffix := range suffixes { + if strings.HasSuffix(fileName, suffix) { + return true + } + } + return false +} + +func isPrefixIgnored(fileName string, prefixesList string) bool { + prefixes := strings.Split(prefixesList, ",") + + for _, prefix := range prefixes { + if strings.HasPrefix(fileName, prefix) { + return true + } + } + return false +} + func run(pass *analysis.Pass) (interface{}, error) { ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer) testCases := pass.ResultOf[testcaseinfo.Analyzer].([]*resource.TestCaseInfo) + for _, testCase := range testCases { fileName := filepath.Base(pass.Fset.File(testCase.AstCompositeLit.Pos()).Name()) - if strings.HasPrefix(fileName, "data_source_") { + if ignoredPrefixes != "" && isPrefixIgnored(fileName, ignoredPrefixes) { + continue + } + + if ignoredSuffixes != "" && isSuffixIgnored(fileName, ignoredSuffixes) { continue } diff --git a/vendor/github.com/bflad/tfproviderlint/passes/AT001/README.md b/vendor/github.com/bflad/tfproviderlint/passes/AT001/README.md index 64a50bd..93c8fde 100644 --- a/vendor/github.com/bflad/tfproviderlint/passes/AT001/README.md +++ b/vendor/github.com/bflad/tfproviderlint/passes/AT001/README.md @@ -3,7 +3,11 @@ The AT001 analyzer reports likely incorrect uses of `TestCase` which do not define a `CheckDestroy` function. `CheckDestroy` is used to verify that test infrastructure has been removed at the end of an acceptance test. -Ignores file names that begin with `data_source_`. + +Optional parameters: + +`-ignored-filename-prefixes` Comma-separated list of filename prefixes to ignore, defaults to `data_source_`. +`-ignored-filename-suffixes` Comma-separated list of filename suffixes to ignore, defaults to none. More information can be found at: https://www.terraform.io/docs/extend/testing/acceptance-tests/testcase.html#checkdestroy diff --git a/vendor/github.com/bflad/tfproviderlint/passes/AT009/AT009.go b/vendor/github.com/bflad/tfproviderlint/passes/AT009/AT009.go new file mode 100644 index 0000000..97501b8 --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/AT009/AT009.go @@ -0,0 +1,50 @@ +package AT009 + +import ( + "go/ast" + + "github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest" + "github.com/bflad/tfproviderlint/passes/commentignore" + "github.com/bflad/tfproviderlint/passes/helper/acctest/randstringfromcharsetcallexpr" + "golang.org/x/tools/go/analysis" +) + +const Doc = `check for acctest.RandStringFromCharSet() calls that can be acctest.RandString() + +The AT009 analyzer reports where the second parameter of a +RandStringFromCharSet call is acctest.CharSetAlpha, which is equivalent to +calling RandString.` + +const analyzerName = "AT009" + +var Analyzer = &analysis.Analyzer{ + Name: analyzerName, + Doc: Doc, + Requires: []*analysis.Analyzer{ + commentignore.Analyzer, + randstringfromcharsetcallexpr.Analyzer, + }, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer) + callExprs := pass.ResultOf[randstringfromcharsetcallexpr.Analyzer].([]*ast.CallExpr) + for _, callExpr := range callExprs { + if ignorer.ShouldIgnore(analyzerName, callExpr) { + continue + } + + if len(callExpr.Args) < 2 { + continue + } + + if !acctest.IsConst(callExpr.Args[1], pass.TypesInfo, acctest.ConstNameCharSetAlphaNum) { + continue + } + + pass.Reportf(callExpr.Pos(), "%s: should use RandString call instead", analyzerName) + } + + return nil, nil +} diff --git a/vendor/github.com/bflad/tfproviderlint/passes/AT009/README.md b/vendor/github.com/bflad/tfproviderlint/passes/AT009/README.md new file mode 100644 index 0000000..c010f55 --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/AT009/README.md @@ -0,0 +1,24 @@ +# AT009 + +The AT009 analyzer reports where `acctest.RandStringFromCharSet()` calls can be simplified to `acctest.RandString()`. + +## Flagged Code + +```go +rString := acctest.RandStringFromCharSet(8, acctest.CharSetAlphaNum) +``` + +## Passing Code + +```go +rString := acctest.RandString(8) +``` + +## Ignoring Reports + +Singular reports can be ignored by adding the a `//lintignore:AT009` Go code comment at the end of the offending line or on the line immediately proceding, e.g. + +```go +//lintignore:AT009 +rString := acctest.RandStringFromCharSet(8, acctest.CharSetAlphaNum) +``` diff --git a/vendor/github.com/bflad/tfproviderlint/passes/R018/R018.go b/vendor/github.com/bflad/tfproviderlint/passes/R018/R018.go new file mode 100644 index 0000000..09502b8 --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/R018/R018.go @@ -0,0 +1,40 @@ +package R018 + +import ( + "go/ast" + + "golang.org/x/tools/go/analysis" + + "github.com/bflad/tfproviderlint/passes/commentignore" + "github.com/bflad/tfproviderlint/passes/stdlib/timesleepcallexpr" +) + +const Doc = `check for time.Sleep() function usage + +Terraform Providers should generally avoid this function when waiting for API operations and prefer polling methods such as resource.Retry() or (resource.StateChangeConf).WaitForState().` + +const analyzerName = "R018" + +var Analyzer = &analysis.Analyzer{ + Name: analyzerName, + Doc: Doc, + Requires: []*analysis.Analyzer{ + commentignore.Analyzer, + timesleepcallexpr.Analyzer, + }, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer) + callExprs := pass.ResultOf[timesleepcallexpr.Analyzer].([]*ast.CallExpr) + for _, callExpr := range callExprs { + if ignorer.ShouldIgnore(analyzerName, callExpr) { + continue + } + + pass.Reportf(callExpr.Pos(), "%s: prefer resource.Retry() or (resource.StateChangeConf).WaitForState() over time.Sleep()", analyzerName) + } + + return nil, nil +} diff --git a/vendor/github.com/bflad/tfproviderlint/passes/R018/README.md b/vendor/github.com/bflad/tfproviderlint/passes/R018/README.md new file mode 100644 index 0000000..633911d --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/R018/README.md @@ -0,0 +1,31 @@ +# R018 + +The R018 analyzer reports [`time.Sleep()`](https://pkg.go.dev/time?tab=doc#Sleep) function usage. Terraform Providers should generally avoid this function when waiting for API operations and prefer polling methods such as [`resource.Retry()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/helper/resource?tab=doc#Retry) or [`(resource.StateChangeConf).WaitForState()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/helper/resource?tab=doc#StateChangeConf.WaitForState). + +## Flagged Code + +```go +time.Sleep(10) +``` + +## Passing Code + +```go +err := resource.Retry(/* ... */) +``` + +Or + +```go +stateConf := resource.StateChangeConf{/* ... */} +_, err := stateConf.WaitForState() +``` + +## Ignoring Reports + +Singular reports can be ignored by adding the a `//lintignore:R018` Go code comment at the end of the offending line or on the line immediately proceding, e.g. + +```go +//lintignore:R018 +time.Sleep(10) +``` diff --git a/vendor/github.com/bflad/tfproviderlint/passes/R019/R019.go b/vendor/github.com/bflad/tfproviderlint/passes/R019/R019.go new file mode 100644 index 0000000..82f8732 --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/R019/R019.go @@ -0,0 +1,62 @@ +package R019 + +import ( + "flag" + "go/ast" + + "golang.org/x/tools/go/analysis" + + "github.com/bflad/tfproviderlint/passes/commentignore" + "github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatahaschangescallexpr" +) + +const Doc = `check for (*schema.ResourceData).HasChanges() calls with many arguments + +The R019 analyzer reports when there are a large number of arguments being +passed to (*schema.ResourceData).HasChanges(), which it may be preferable to +use (*schema.ResourceData).HasChangesExcept() instead. + +Optional parameters: + -threshold=5 Number of arguments for reporting +` + +const analyzerName = "R019" + +var ( + threshold int +) + +var Analyzer = &analysis.Analyzer{ + Name: analyzerName, + Doc: Doc, + Flags: parseFlags(), + Requires: []*analysis.Analyzer{ + commentignore.Analyzer, + resourcedatahaschangescallexpr.Analyzer, + }, + Run: run, +} + +func parseFlags() flag.FlagSet { + var flags = flag.NewFlagSet(analyzerName, flag.ExitOnError) + flags.IntVar(&threshold, "threshold", 5, "Number of arguments for reporting") + return *flags +} + +func run(pass *analysis.Pass) (interface{}, error) { + ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer) + callExprs := pass.ResultOf[resourcedatahaschangescallexpr.Analyzer].([]*ast.CallExpr) + for _, callExpr := range callExprs { + if ignorer.ShouldIgnore(analyzerName, callExpr) { + continue + } + + if len(callExpr.Args) < threshold { + continue + } + + pass.Reportf(callExpr.Pos(), "%s: d.HasChanges() has many arguments, consider d.HasChangesExcept()", analyzerName) + } + + return nil, nil +} diff --git a/vendor/github.com/bflad/tfproviderlint/passes/R019/README.md b/vendor/github.com/bflad/tfproviderlint/passes/R019/README.md new file mode 100644 index 0000000..c47870a --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/R019/README.md @@ -0,0 +1,28 @@ +# R019 + +The R019 analyzer reports when there are a large number of arguments being passed to [`(*schema.ResourceData).HasChanges()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#ResourceData.HasChanges), which it may be preferable to use [`(*schema.ResourceData).HasChangesExcept()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#ResourceData.HasChangesExcept) instead. + +## Optional Arguments + +- `-threshold=5` Number of arguments before reporting + +## Flagged Code + +```go +d.HasChanges("attr1", "attr2", "attr3", "attr4", "attr5") +``` + +## Passing Code + +```go +d.HasChangesExcept("metadata_attr") +``` + +## Ignoring Reports + +Singular reports can be ignored by adding the a `//lintignore:R019` Go code comment at the end of the offending line or on the line immediately proceding, e.g. + +```go +//lintignore:R019 +d.HasChanges("attr1", "attr2", "attr3", "attr4", "attr5") +``` diff --git a/vendor/github.com/bflad/tfproviderlint/passes/V009/README.md b/vendor/github.com/bflad/tfproviderlint/passes/V009/README.md new file mode 100644 index 0000000..bd247bd --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/V009/README.md @@ -0,0 +1,23 @@ +# V009 + +The V009 analyzer reports when the second argument for a [`validation.StringMatch()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation#StringMatch) call is an empty string. It is preferred to provide a friendly validation message, rather than allowing the function to return the raw regular expression as the message, since not all practitioners may be familiar with regular expression syntax. + +## Flagged Code + +```go +validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9.-]+$`), "") +``` + +## Passing Code + +```go +validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9.-]+$`), "must contain only alphanumeric characters, periods, or hyphens") +``` + +## Ignoring Reports + +Singular reports can be ignored by adding the a `//lintignore:V009` Go code comment at the end of the offending line or on the line immediately proceding, e.g. + +```go +validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9.-]+$`), "") //lintignore:V009 +``` diff --git a/vendor/github.com/bflad/tfproviderlint/passes/V009/V009.go b/vendor/github.com/bflad/tfproviderlint/passes/V009/V009.go new file mode 100644 index 0000000..5f648eb --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/V009/V009.go @@ -0,0 +1,56 @@ +package V009 + +import ( + "go/ast" + + "golang.org/x/tools/go/analysis" + + "github.com/bflad/tfproviderlint/helper/astutils" + "github.com/bflad/tfproviderlint/passes/commentignore" + "github.com/bflad/tfproviderlint/passes/helper/validation/stringmatchcallexpr" +) + +const Doc = `check for validation.StringMatch() calls with empty message argument + +The V009 analyzer reports when the second argument for a validation.StringMatch() +call is an empty string. It is preferred to provide a friendly validation +message, rather than allowing the function to return the raw regular expression +as the message, since not all practitioners may be familiar with regular +expression syntax.` + +const analyzerName = "V009" + +var Analyzer = &analysis.Analyzer{ + Name: analyzerName, + Doc: Doc, + Requires: []*analysis.Analyzer{ + commentignore.Analyzer, + stringmatchcallexpr.Analyzer, + }, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer) + sets := pass.ResultOf[stringmatchcallexpr.Analyzer].([]*ast.CallExpr) + for _, set := range sets { + if ignorer.ShouldIgnore(analyzerName, set) { + continue + } + + if len(set.Args) < 2 { + continue + } + + switch v := set.Args[1].(type) { + default: + continue + case *ast.BasicLit: + if value := astutils.ExprStringValue(v); value != nil && *value == "" { + pass.Reportf(v.Pos(), "%s: validation.StringMatch() message argument should be non-empty", analyzerName) + } + } + } + + return nil, nil +} diff --git a/vendor/github.com/bflad/tfproviderlint/passes/V010/README.md b/vendor/github.com/bflad/tfproviderlint/passes/V010/README.md new file mode 100644 index 0000000..becee73 --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/V010/README.md @@ -0,0 +1,23 @@ +# V010 + +The V010 analyzer reports when the second argument for a [`validation.StringDoesNotMatch()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation#StringDoesNotMatch) call is an empty string. It is preferred to provide a friendly validation message, rather than allowing the function to return the raw regular expression as the message, since not all practitioners may be familiar with regular expression syntax. + +## Flagged Code + +```go +validation.StringDoesNotMatch(regexp.MustCompile(`^[!@#$%^&*()]+$`), "") +``` + +## Passing Code + +```go +validation.StringDoesNotMatch(regexp.MustCompile(`^[!@#$%^&*()]+$`), "must not contain exclamation, at, octothorp, US dollar, percentage, carat, ampersand, star, or parenthesis symbols") +``` + +## Ignoring Reports + +Singular reports can be ignored by adding the a `//lintignore:V010` Go code comment at the end of the offending line or on the line immediately proceding, e.g. + +```go +validation.StringDoesNotMatch(regexp.MustCompile(`^[!@#$%^&*()]+$`), "") //lintignore:V010 +``` diff --git a/vendor/github.com/bflad/tfproviderlint/passes/V010/V010.go b/vendor/github.com/bflad/tfproviderlint/passes/V010/V010.go new file mode 100644 index 0000000..7cf6beb --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/V010/V010.go @@ -0,0 +1,56 @@ +package V010 + +import ( + "go/ast" + + "golang.org/x/tools/go/analysis" + + "github.com/bflad/tfproviderlint/helper/astutils" + "github.com/bflad/tfproviderlint/passes/commentignore" + "github.com/bflad/tfproviderlint/passes/helper/validation/stringdoesnotmatchcallexpr" +) + +const Doc = `check for validation.StringDoesNotMatch() calls with empty message argument + +The V010 analyzer reports when the second argument for a validation.StringDoesNotMatch() +call is an empty string. It is preferred to provide a friendly validation +message, rather than allowing the function to return the raw regular expression +as the message, since not all practitioners may be familiar with regular +expression syntax.` + +const analyzerName = "V010" + +var Analyzer = &analysis.Analyzer{ + Name: analyzerName, + Doc: Doc, + Requires: []*analysis.Analyzer{ + commentignore.Analyzer, + stringdoesnotmatchcallexpr.Analyzer, + }, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer) + sets := pass.ResultOf[stringdoesnotmatchcallexpr.Analyzer].([]*ast.CallExpr) + for _, set := range sets { + if ignorer.ShouldIgnore(analyzerName, set) { + continue + } + + if len(set.Args) < 2 { + continue + } + + switch v := set.Args[1].(type) { + default: + continue + case *ast.BasicLit: + if value := astutils.ExprStringValue(v); value != nil && *value == "" { + pass.Reportf(v.Pos(), "%s: validation.StringDoesNotMatch() message argument should be non-empty", analyzerName) + } + } + } + + return nil, nil +} diff --git a/vendor/github.com/bflad/tfproviderlint/passes/checks.go b/vendor/github.com/bflad/tfproviderlint/passes/checks.go index 847e4ca..92cd064 100644 --- a/vendor/github.com/bflad/tfproviderlint/passes/checks.go +++ b/vendor/github.com/bflad/tfproviderlint/passes/checks.go @@ -9,6 +9,7 @@ import ( "github.com/bflad/tfproviderlint/passes/AT006" "github.com/bflad/tfproviderlint/passes/AT007" "github.com/bflad/tfproviderlint/passes/AT008" + "github.com/bflad/tfproviderlint/passes/AT009" "github.com/bflad/tfproviderlint/passes/R001" "github.com/bflad/tfproviderlint/passes/R002" "github.com/bflad/tfproviderlint/passes/R003" @@ -26,6 +27,8 @@ import ( "github.com/bflad/tfproviderlint/passes/R015" "github.com/bflad/tfproviderlint/passes/R016" "github.com/bflad/tfproviderlint/passes/R017" + "github.com/bflad/tfproviderlint/passes/R018" + "github.com/bflad/tfproviderlint/passes/R019" "github.com/bflad/tfproviderlint/passes/S001" "github.com/bflad/tfproviderlint/passes/S002" "github.com/bflad/tfproviderlint/passes/S003" @@ -71,6 +74,8 @@ import ( "github.com/bflad/tfproviderlint/passes/V006" "github.com/bflad/tfproviderlint/passes/V007" "github.com/bflad/tfproviderlint/passes/V008" + "github.com/bflad/tfproviderlint/passes/V009" + "github.com/bflad/tfproviderlint/passes/V010" "golang.org/x/tools/go/analysis" ) @@ -86,6 +91,7 @@ var AllChecks = []*analysis.Analyzer{ AT006.Analyzer, AT007.Analyzer, AT008.Analyzer, + AT009.Analyzer, R001.Analyzer, R002.Analyzer, R003.Analyzer, @@ -103,6 +109,8 @@ var AllChecks = []*analysis.Analyzer{ R015.Analyzer, R016.Analyzer, R017.Analyzer, + R018.Analyzer, + R019.Analyzer, S001.Analyzer, S002.Analyzer, S003.Analyzer, @@ -148,4 +156,6 @@ var AllChecks = []*analysis.Analyzer{ V006.Analyzer, V007.Analyzer, V008.Analyzer, + V009.Analyzer, + V010.Analyzer, } diff --git a/vendor/github.com/bflad/tfproviderlint/passes/commentignore/ignore.go b/vendor/github.com/bflad/tfproviderlint/passes/commentignore/ignore.go index ba4778d..c934eae 100644 --- a/vendor/github.com/bflad/tfproviderlint/passes/commentignore/ignore.go +++ b/vendor/github.com/bflad/tfproviderlint/passes/commentignore/ignore.go @@ -44,11 +44,16 @@ func run(pass *analysis.Pass) (interface{}, error) { for n, cgs := range cmap { for _, cg := range cgs { if strings.HasPrefix(cg.Text(), commentIgnorePrefix) { - key := strings.TrimPrefix(cg.Text(), commentIgnorePrefix) - key = strings.TrimSpace(key) + commentIgnore := strings.TrimPrefix(cg.Text(), commentIgnorePrefix) + // Allow extra // comment after keys + commentIgnoreParts := strings.Split(commentIgnore, "//") + keys := strings.TrimSpace(commentIgnoreParts[0]) - // is it possible for nested pos/end to be outside the largest nodes? - ignores[key] = append(ignores[key], ignore{n.Pos(), n.End()}) + // Allow multiple comma separated ignores + for _, key := range strings.Split(keys, ",") { + // is it possible for nested pos/end to be outside the largest nodes? + ignores[key] = append(ignores[key], ignore{n.Pos(), n.End()}) + } } } } diff --git a/vendor/github.com/bflad/tfproviderlint/passes/helper/acctest/randstringfromcharsetcallexpr/randstringfromcharsetcallexpr.go b/vendor/github.com/bflad/tfproviderlint/passes/helper/acctest/randstringfromcharsetcallexpr/randstringfromcharsetcallexpr.go new file mode 100644 index 0000000..a9d7b9a --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/helper/acctest/randstringfromcharsetcallexpr/randstringfromcharsetcallexpr.go @@ -0,0 +1,13 @@ +package randstringfromcharsetcallexpr + +import ( + "github.com/bflad/tfproviderlint/helper/analysisutils" + "github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest" +) + +var Analyzer = analysisutils.FunctionCallExprAnalyzer( + "randstringfromcharsetcallexpr", + acctest.IsFunc, + acctest.PackagePath, + acctest.FuncNameRandStringFromCharSet, +) diff --git a/vendor/github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatahaschangescallexpr/resourcedatahaschangescallexpr.go b/vendor/github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatahaschangescallexpr/resourcedatahaschangescallexpr.go new file mode 100644 index 0000000..b31b46d --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatahaschangescallexpr/resourcedatahaschangescallexpr.go @@ -0,0 +1,14 @@ +package resourcedatahaschangescallexpr + +import ( + "github.com/bflad/tfproviderlint/helper/analysisutils" + "github.com/bflad/tfproviderlint/helper/terraformtype/helper/schema" +) + +var Analyzer = analysisutils.ReceiverMethodCallExprAnalyzer( + "resourcedatahaschangescallexpr", + schema.IsReceiverMethod, + schema.PackagePath, + schema.TypeNameResourceData, + "HasChanges", +) diff --git a/vendor/github.com/bflad/tfproviderlint/passes/helper/validation/stringdoesnotmatchcallexpr/stringdoesnotmatchcallexpr.go b/vendor/github.com/bflad/tfproviderlint/passes/helper/validation/stringdoesnotmatchcallexpr/stringdoesnotmatchcallexpr.go new file mode 100644 index 0000000..ba3681e --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/helper/validation/stringdoesnotmatchcallexpr/stringdoesnotmatchcallexpr.go @@ -0,0 +1,13 @@ +package stringdoesnotmatchcallexpr + +import ( + "github.com/bflad/tfproviderlint/helper/analysisutils" + "github.com/bflad/tfproviderlint/helper/terraformtype/helper/validation" +) + +var Analyzer = analysisutils.FunctionCallExprAnalyzer( + "stringdoesnotmatchcallexpr", + validation.IsFunc, + validation.PackagePath, + validation.FuncNameStringDoesNotMatch, +) diff --git a/vendor/github.com/bflad/tfproviderlint/passes/helper/validation/stringmatchcallexpr/stringmatchcallexpr.go b/vendor/github.com/bflad/tfproviderlint/passes/helper/validation/stringmatchcallexpr/stringmatchcallexpr.go new file mode 100644 index 0000000..77a0d32 --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/helper/validation/stringmatchcallexpr/stringmatchcallexpr.go @@ -0,0 +1,13 @@ +package stringmatchcallexpr + +import ( + "github.com/bflad/tfproviderlint/helper/analysisutils" + "github.com/bflad/tfproviderlint/helper/terraformtype/helper/validation" +) + +var Analyzer = analysisutils.FunctionCallExprAnalyzer( + "stringmatchcallexpr", + validation.IsFunc, + validation.PackagePath, + validation.FuncNameStringMatch, +) diff --git a/vendor/github.com/bflad/tfproviderlint/passes/stdlib/timesleepcallexpr/timesleepfcallexpr.go b/vendor/github.com/bflad/tfproviderlint/passes/stdlib/timesleepcallexpr/timesleepfcallexpr.go new file mode 100644 index 0000000..b4a7072 --- /dev/null +++ b/vendor/github.com/bflad/tfproviderlint/passes/stdlib/timesleepcallexpr/timesleepfcallexpr.go @@ -0,0 +1,11 @@ +package timesleepcallexpr + +import ( + "github.com/bflad/tfproviderlint/helper/analysisutils" +) + +var Analyzer = analysisutils.StdlibFunctionCallExprAnalyzer( + "timesleepcallexpr", + "time", + "Sleep", +) diff --git a/vendor/modules.txt b/vendor/modules.txt index 4bb5eeb..8ea9fef 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -82,12 +82,13 @@ github.com/bflad/tfproviderdocs/check github.com/bflad/tfproviderdocs/check/sidenavigation github.com/bflad/tfproviderdocs/command github.com/bflad/tfproviderdocs/version -# github.com/bflad/tfproviderlint v0.18.0 +# github.com/bflad/tfproviderlint v0.21.0 github.com/bflad/tfproviderlint/cmd/tfproviderlint github.com/bflad/tfproviderlint/helper/analysisutils github.com/bflad/tfproviderlint/helper/astutils github.com/bflad/tfproviderlint/helper/cmdflags github.com/bflad/tfproviderlint/helper/terraformtype +github.com/bflad/tfproviderlint/helper/terraformtype/helper/acctest github.com/bflad/tfproviderlint/helper/terraformtype/helper/resource github.com/bflad/tfproviderlint/helper/terraformtype/helper/schema github.com/bflad/tfproviderlint/helper/terraformtype/helper/validation @@ -100,6 +101,7 @@ github.com/bflad/tfproviderlint/passes/AT005 github.com/bflad/tfproviderlint/passes/AT006 github.com/bflad/tfproviderlint/passes/AT007 github.com/bflad/tfproviderlint/passes/AT008 +github.com/bflad/tfproviderlint/passes/AT009 github.com/bflad/tfproviderlint/passes/R001 github.com/bflad/tfproviderlint/passes/R002 github.com/bflad/tfproviderlint/passes/R003 @@ -117,6 +119,8 @@ github.com/bflad/tfproviderlint/passes/R014 github.com/bflad/tfproviderlint/passes/R015 github.com/bflad/tfproviderlint/passes/R016 github.com/bflad/tfproviderlint/passes/R017 +github.com/bflad/tfproviderlint/passes/R018 +github.com/bflad/tfproviderlint/passes/R019 github.com/bflad/tfproviderlint/passes/S001 github.com/bflad/tfproviderlint/passes/S002 github.com/bflad/tfproviderlint/passes/S003 @@ -162,11 +166,15 @@ github.com/bflad/tfproviderlint/passes/V005 github.com/bflad/tfproviderlint/passes/V006 github.com/bflad/tfproviderlint/passes/V007 github.com/bflad/tfproviderlint/passes/V008 +github.com/bflad/tfproviderlint/passes/V009 +github.com/bflad/tfproviderlint/passes/V010 github.com/bflad/tfproviderlint/passes/commentignore +github.com/bflad/tfproviderlint/passes/helper/acctest/randstringfromcharsetcallexpr github.com/bflad/tfproviderlint/passes/helper/resource/retryfuncinfo github.com/bflad/tfproviderlint/passes/helper/resource/testcaseinfo github.com/bflad/tfproviderlint/passes/helper/schema/crudfuncinfo github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatagetchangeassignstmt +github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatahaschangescallexpr github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatapartialcallexpr github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatapartialselectorexpr github.com/bflad/tfproviderlint/passes/helper/schema/resourcedatasetcallexpr @@ -185,10 +193,13 @@ github.com/bflad/tfproviderlint/passes/helper/validation/iprangecallexpr github.com/bflad/tfproviderlint/passes/helper/validation/iprangeselectorexpr github.com/bflad/tfproviderlint/passes/helper/validation/singleipcallexpr github.com/bflad/tfproviderlint/passes/helper/validation/singleipselectorexpr +github.com/bflad/tfproviderlint/passes/helper/validation/stringdoesnotmatchcallexpr +github.com/bflad/tfproviderlint/passes/helper/validation/stringmatchcallexpr github.com/bflad/tfproviderlint/passes/helper/validation/validatejsonstringselectorexpr github.com/bflad/tfproviderlint/passes/helper/validation/validatelistuniquestringsselectorexpr github.com/bflad/tfproviderlint/passes/helper/validation/validateregexpselectorexpr github.com/bflad/tfproviderlint/passes/helper/validation/validaterfc3339timestringselectorexpr +github.com/bflad/tfproviderlint/passes/stdlib/timesleepcallexpr github.com/bflad/tfproviderlint/passes/testaccfuncdecl github.com/bflad/tfproviderlint/passes/testfuncdecl github.com/bflad/tfproviderlint/version