Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform_deprecated_index: Emit issues based on expression types #90

Merged
merged 1 commit into from
Apr 22, 2023

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Apr 19, 2023

Fixes #84

The current deprecated index detection is based on lexical analysis. Since the rule lexes every expression walked by WalkExpressions, it has the problem of emitting multiple issues for the same expression when walking on nested expressions.

This PR switches deprecated index detection from lexical analysis-based to syntax analysis-based. Instead of lexing the walked expression, depending on the expression type, check if it has deprecated indexes.

hcl-parse tells us that the types of expressions we should be dealing with in this rule are ScopeTraversalExpr, RelativeTraversalExpr, and SplatExpr.

$ hcl-parse -e "list.0"
(*hclsyntax.ScopeTraversalExpr "list.0")

$ hcl-parse -e "map.*"
(*hclsyntax.SplatExpr
  (*hclsyntax.ScopeTraversalExpr "map")
  (*hclsyntax.AnonSymbolExpr)
)

$ hcl-parse -e "nested_list.*.0"
(*hclsyntax.SplatExpr
  (*hclsyntax.ScopeTraversalExpr "nested_list")
  (*hclsyntax.RelativeTraversalExpr ".0"
    (*hclsyntax.AnonSymbolExpr)
  )
)

This allows the rule to emit only one issue for nested expressions. Additionally, issues can be reported against a more precise range.

@wata727 wata727 requested a review from bendrucker April 19, 2023 17:20
Copy link
Member

@bendrucker bendrucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, much better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

terraform_deprecated_index emits multiple issues for same attribute
2 participants