github.com/terraform-linters/tflint@v0.51.2-0.20240520175844-3750771571b6/plugin/stub-generator/sources/testing/rules/testing_assertions_example.go (about)

     1  package rules
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/terraform-linters/tflint-plugin-sdk/hclext"
     7  	"github.com/terraform-linters/tflint-plugin-sdk/tflint"
     8  )
     9  
    10  // TestingAssertionsExampleRule checks whether ...
    11  type TestingAssertionsExampleRule struct {
    12  	tflint.DefaultRule
    13  }
    14  
    15  // NewTestingAssertionsExampleRule returns a new rule
    16  func NewTestingAssertionsExampleRule() *TestingAssertionsExampleRule {
    17  	return &TestingAssertionsExampleRule{}
    18  }
    19  
    20  // Name returns the rule name
    21  func (r *TestingAssertionsExampleRule) Name() string {
    22  	return "testing_assertions_example"
    23  }
    24  
    25  // Enabled returns whether the rule is enabled by default
    26  func (r *TestingAssertionsExampleRule) Enabled() bool {
    27  	return true
    28  }
    29  
    30  // Severity returns the rule severity
    31  func (r *TestingAssertionsExampleRule) Severity() tflint.Severity {
    32  	return tflint.ERROR
    33  }
    34  
    35  // Link returns the rule reference link
    36  func (r *TestingAssertionsExampleRule) Link() string {
    37  	return ""
    38  }
    39  
    40  // Check checks whether ...
    41  func (r *TestingAssertionsExampleRule) Check(runner tflint.Runner) error {
    42  	resources, err := runner.GetResourceContent("testing_assertions", &hclext.BodySchema{
    43  		Blocks: []hclext.BlockSchema{
    44  			{
    45  				Type:       "equal",
    46  				LabelNames: []string{"name"},
    47  			},
    48  		},
    49  	}, nil)
    50  	if err != nil {
    51  		return err
    52  	}
    53  
    54  	for _, resource := range resources.Blocks {
    55  		for _, equal := range resource.Body.Blocks {
    56  			if err := runner.EmitIssue(r, fmt.Sprintf("equal block found: label=%s", equal.Labels[0]), equal.DefRange); err != nil {
    57  				return err
    58  			}
    59  		}
    60  	}
    61  
    62  	return nil
    63  }