-
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 Analyzer: helper/passes/schema/schemainfocomputedonly Returns all Schema that are Computed: true only. Refactors existing checks to using it. * New Checks: S025 through S033 Reference: #65 * **New Check:** `S025`: check for `Schema` of only `Computed` enabled with `AtLeastOneOf` configured * **New Check:** `S026`: check for `Schema` of only `Computed` enabled with `ConflictsWith` configured * **New Check:** `S027`: check for `Schema` of only `Computed` enabled with `Default` configured * **New Check:** `S028`: check for `Schema` of only `Computed` enabled with `DefaultFunc` configured * **New Check:** `S029`: check for `Schema` of only `Computed` enabled with `ExactlyOneOf` configured * **New Check:** `S030`: check for `Schema` of only `Computed` enabled with `InputDefault` configured * **New Check:** `S031`: check for `Schema` of only `Computed` enabled with `MaxItems` configured * **New Check:** `S032`: check for `Schema` of only `Computed` enabled with `MinItems` configured * **New Check:** `S033`: check for `Schema` of only `Computed` enabled with `StateFunc` configured
- Loading branch information
Showing
89 changed files
with
1,779 additions
and
23 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
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
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
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,33 @@ | ||
# S025 | ||
|
||
The S025 analyzer reports cases of schemas which enables only `Computed` | ||
and configures `AtLeastOneOf`, which is not valid. | ||
|
||
## Flagged Code | ||
|
||
```go | ||
&schema.Schema{ | ||
AtLeastOneOf: []string{"example"}, | ||
Computed: true, | ||
} | ||
``` | ||
|
||
## Passing Code | ||
|
||
```go | ||
&schema.Schema{ | ||
Computed: true, | ||
} | ||
``` | ||
|
||
## Ignoring Reports | ||
|
||
Singular reports can be ignored by adding the a `//lintignore:S025` Go code comment at the end of the offending line or on the line immediately proceding, e.g. | ||
|
||
```go | ||
//lintignore:S025 | ||
&schema.Schema{ | ||
AtLeastOneOf: []string{"example"}, | ||
Computed: true, | ||
} | ||
``` |
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,50 @@ | ||
package S025 | ||
|
||
import ( | ||
"go/ast" | ||
|
||
"github.com/bflad/tfproviderlint/helper/terraformtype/helper/schema" | ||
"github.com/bflad/tfproviderlint/passes/commentignore" | ||
"github.com/bflad/tfproviderlint/passes/helper/schema/schemainfocomputedonly" | ||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
const Doc = `check for Schema with only Computed enabled and AtLeastOneOf configured | ||
The S025 analyzer reports cases of schemas which only enables Computed | ||
and configures AtLeastOneOf, which is not valid.` | ||
|
||
const analyzerName = "S025" | ||
|
||
var Analyzer = &analysis.Analyzer{ | ||
Name: analyzerName, | ||
Doc: Doc, | ||
Requires: []*analysis.Analyzer{ | ||
commentignore.Analyzer, | ||
schemainfocomputedonly.Analyzer, | ||
}, | ||
Run: run, | ||
} | ||
|
||
func run(pass *analysis.Pass) (interface{}, error) { | ||
ignorer := pass.ResultOf[commentignore.Analyzer].(*commentignore.Ignorer) | ||
schemaInfos := pass.ResultOf[schemainfocomputedonly.Analyzer].([]*schema.SchemaInfo) | ||
for _, schemaInfo := range schemaInfos { | ||
if ignorer.ShouldIgnore(analyzerName, schemaInfo.AstCompositeLit) { | ||
continue | ||
} | ||
|
||
if schemaInfo.Schema.AtLeastOneOf == nil { | ||
continue | ||
} | ||
|
||
switch t := schemaInfo.AstCompositeLit.Type.(type) { | ||
default: | ||
pass.Reportf(schemaInfo.AstCompositeLit.Lbrace, "%s: schema should not only enable Computed and configure AtLeastOneOf", analyzerName) | ||
case *ast.SelectorExpr: | ||
pass.Reportf(t.Sel.Pos(), "%s: schema should not only enable Computed and configure AtLeastOneOf", analyzerName) | ||
} | ||
} | ||
|
||
return nil, 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,13 @@ | ||
package S025_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/bflad/tfproviderlint/passes/S025" | ||
"golang.org/x/tools/go/analysis/analysistest" | ||
) | ||
|
||
func TestS025(t *testing.T) { | ||
testdata := analysistest.TestData() | ||
analysistest.Run(t, testdata, S025.Analyzer, "a") | ||
} |
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,19 @@ | ||
package a | ||
|
||
import ( | ||
s "github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func falias() { | ||
_ = s.Schema{ // want "schema should not only enable Computed and configure AtLeastOneOf" | ||
AtLeastOneOf: []string{"test"}, | ||
Computed: true, | ||
} | ||
|
||
_ = map[string]*s.Schema{ | ||
"name": { // want "schema should not only enable Computed and configure AtLeastOneOf" | ||
AtLeastOneOf: []string{"test"}, | ||
Computed: true, | ||
}, | ||
} | ||
} |
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,13 @@ | ||
package a | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func fcommentignore() { | ||
//lintignore:S025 | ||
_ = schema.Schema{ | ||
AtLeastOneOf: []string{"test"}, | ||
Computed: true, | ||
} | ||
} |
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,33 @@ | ||
package a | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func f() { | ||
_ = schema.Schema{ // want "schema should not only enable Computed and configure AtLeastOneOf" | ||
AtLeastOneOf: []string{"test"}, | ||
Computed: true, | ||
} | ||
|
||
_ = schema.Schema{ | ||
AtLeastOneOf: nil, | ||
Computed: true, | ||
} | ||
|
||
_ = schema.Schema{ | ||
Computed: true, | ||
} | ||
|
||
_ = schema.Schema{ | ||
AtLeastOneOf: []string{"test"}, | ||
Optional: true, | ||
} | ||
|
||
_ = map[string]*schema.Schema{ | ||
"name": { // want "schema should not only enable Computed and configure AtLeastOneOf" | ||
AtLeastOneOf: []string{"test"}, | ||
Computed: true, | ||
}, | ||
} | ||
} |
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,19 @@ | ||
package a | ||
|
||
import ( | ||
"a/schema" | ||
) | ||
|
||
func foutside() { | ||
_ = schema.Schema{ | ||
AtLeastOneOf: []string{"test"}, | ||
Computed: true, | ||
} | ||
|
||
_ = map[string]*schema.Schema{ | ||
"name": { | ||
AtLeastOneOf: []string{"test"}, | ||
Computed: true, | ||
}, | ||
} | ||
} |
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,6 @@ | ||
package schema | ||
|
||
type Schema struct { | ||
AtLeastOneOf []string | ||
Computed bool | ||
} |
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 @@ | ||
../../../../../vendor |
Oops, something went wrong.