-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 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,3 @@ | ||
plugin "testing" { | ||
enabled = 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,25 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"rule": { | ||
"name": "locals_just_attributes_example", | ||
"severity": "info", | ||
"link": "" | ||
}, | ||
"message": "found 3 local values", | ||
"range": { | ||
"filename": "template.tf", | ||
"start": { | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 7 | ||
} | ||
}, | ||
"callers": [] | ||
} | ||
], | ||
"errors": [] | ||
} |
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,5 @@ | ||
locals { | ||
foo = "foo" | ||
bar = "bar" | ||
just_attributes = "just_attributes" | ||
} |
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
61 changes: 61 additions & 0 deletions
61
plugin/stub-generator/sources/testing/rules/locals_just_attributes_example_rule.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,61 @@ | ||
package rules | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-linters/tflint-plugin-sdk/hclext" | ||
"github.com/terraform-linters/tflint-plugin-sdk/tflint" | ||
) | ||
|
||
// LocalsJustAttributesExampleRule checks whether ... | ||
type LocalsJustAttributesExampleRule struct { | ||
tflint.DefaultRule | ||
} | ||
|
||
// LocalsJustAttributesExampleRule returns a new rule | ||
func NewLocalsJustAttributesExampleRule() *LocalsJustAttributesExampleRule { | ||
return &LocalsJustAttributesExampleRule{} | ||
} | ||
|
||
// Name returns the rule name | ||
func (r *LocalsJustAttributesExampleRule) Name() string { | ||
return "locals_just_attributes_example" | ||
} | ||
|
||
// Enabled returns whether the rule is enabled by default | ||
func (r *LocalsJustAttributesExampleRule) Enabled() bool { | ||
return true | ||
} | ||
|
||
// Severity returns the rule severity | ||
func (r *LocalsJustAttributesExampleRule) Severity() tflint.Severity { | ||
return tflint.NOTICE | ||
} | ||
|
||
// Link returns the rule reference link | ||
func (r *LocalsJustAttributesExampleRule) Link() string { | ||
return "" | ||
} | ||
|
||
// Check checks whether ... | ||
func (r *LocalsJustAttributesExampleRule) Check(runner tflint.Runner) error { | ||
body, err := runner.GetModuleContent(&hclext.BodySchema{ | ||
Blocks: []hclext.BlockSchema{ | ||
{ | ||
Type: "locals", | ||
Body: &hclext.BodySchema{Mode: hclext.SchemaJustAttributesMode}, | ||
}, | ||
}, | ||
}, nil) | ||
if err != nil || len(body.Blocks) == 0 { | ||
return err | ||
} | ||
|
||
locals := body.Blocks[0] | ||
|
||
if _, exists := locals.Body.Attributes["just_attributes"]; !exists { | ||
return nil | ||
} | ||
|
||
return runner.EmitIssue(r, fmt.Sprintf("found %d local values", len(locals.Body.Attributes)), locals.DefRange) | ||
} |
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