github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_resourcegroups_group_invalid_description.go (about) 1 // This file generated by `tools/model-rule-gen/main.go`. DO NOT EDIT 2 3 package models 4 5 import ( 6 "log" 7 "regexp" 8 9 hcl "github.com/hashicorp/hcl/v2" 10 "github.com/wata727/tflint/tflint" 11 ) 12 13 // AwsResourcegroupsGroupInvalidDescriptionRule checks the pattern is valid 14 type AwsResourcegroupsGroupInvalidDescriptionRule struct { 15 resourceType string 16 attributeName string 17 max int 18 pattern *regexp.Regexp 19 } 20 21 // NewAwsResourcegroupsGroupInvalidDescriptionRule returns new rule with default attributes 22 func NewAwsResourcegroupsGroupInvalidDescriptionRule() *AwsResourcegroupsGroupInvalidDescriptionRule { 23 return &AwsResourcegroupsGroupInvalidDescriptionRule{ 24 resourceType: "aws_resourcegroups_group", 25 attributeName: "description", 26 max: 512, 27 pattern: regexp.MustCompile(`^[\sa-zA-Z0-9_\.-]*$`), 28 } 29 } 30 31 // Name returns the rule name 32 func (r *AwsResourcegroupsGroupInvalidDescriptionRule) Name() string { 33 return "aws_resourcegroups_group_invalid_description" 34 } 35 36 // Enabled returns whether the rule is enabled by default 37 func (r *AwsResourcegroupsGroupInvalidDescriptionRule) Enabled() bool { 38 return true 39 } 40 41 // Severity returns the rule severity 42 func (r *AwsResourcegroupsGroupInvalidDescriptionRule) Severity() string { 43 return tflint.ERROR 44 } 45 46 // Link returns the rule reference link 47 func (r *AwsResourcegroupsGroupInvalidDescriptionRule) Link() string { 48 return "" 49 } 50 51 // Check checks the pattern is valid 52 func (r *AwsResourcegroupsGroupInvalidDescriptionRule) Check(runner *tflint.Runner) error { 53 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 54 55 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 56 var val string 57 err := runner.EvaluateExpr(attribute.Expr, &val) 58 59 return runner.EnsureNoError(err, func() error { 60 if len(val) > r.max { 61 runner.EmitIssue( 62 r, 63 "description must be 512 characters or less", 64 attribute.Expr.Range(), 65 ) 66 } 67 if !r.pattern.MatchString(val) { 68 runner.EmitIssue( 69 r, 70 `description does not match valid pattern ^[\sa-zA-Z0-9_\.-]*$`, 71 attribute.Expr.Range(), 72 ) 73 } 74 return nil 75 }) 76 }) 77 }