Skip to content

Commit

Permalink
terraform_deprecated_index: improve perf for files with many expres…
Browse files Browse the repository at this point in the history
…sions (#49)
  • Loading branch information
bendrucker authored Dec 18, 2022
1 parent d0162dd commit 002ad8d
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions rules/terraform_deprecated_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,16 @@ func (r *TerraformDeprecatedIndexRule) Check(runner tflint.Runner) error {
return nil
}

diags := runner.WalkExpressions(tflint.ExprWalkFunc(func(expr hcl.Expression) hcl.Diagnostics {
filename := expr.Range().Filename
file, err := runner.GetFile(filename)
if err != nil {
return hcl.Diagnostics{
{
Severity: hcl.DiagError,
Summary: "failed to call GetFile()",
Detail: err.Error(),
},
}
}
files, err := runner.GetFiles()
if err != nil {
return err
}

diags := runner.WalkExpressions(tflint.ExprWalkFunc(func(expr hcl.Expression) hcl.Diagnostics {
for _, variable := range expr.Variables() {
filename := expr.Range().Filename
file := files[filename]

bytes := expr.Range().SliceBytes(file.Bytes)

tokens, diags := hclsyntax.LexExpression(bytes, filename, variable.SourceRange().Start)
Expand Down

0 comments on commit 002ad8d

Please sign in to comment.