Skip to content

Commit

Permalink
Merge pull request Checkmarx#6321 from Checkmarx/Terraform/Line_with_…
Browse files Browse the repository at this point in the history
…comment

Terraform/line with comment
  • Loading branch information
YosefNaftali authored May 3, 2023
2 parents c73bbc5 + cdc19b9 commit c5aa128
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/parser/terraform/comment/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func processTokens(tokens hclsyntax.Tokens) (ig Ignore) {
if tokens[i].Type != hclsyntax.TokenComment || i+1 > len(tokens) {
continue
}
// case: CONFIGURATION = X # comment
if i > 0 && tokens[i-1].Range.Start.Line == tokens[i].Range.Start.Line {
continue
}
ignoreLines, ignoreBlocks, ignoreComments = processComment((*comment)(&tokens[i]),
(*comment)(&tokens[i+1]), ignoreLines, ignoreBlocks, ignoreComments)
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/parser/terraform/comment/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ var (
}
stage_name = "development"
}`),
"dont-ignore-lines-with-comment-at-the-end": []byte(`
resource "aws_api_gateway_stage" "positive2" {
deployment_id = "some deployment id"
rest_api_id = "some rest api id" # comment
stage_name = "development" // comment
description = "DEV" /* comment */
}`),
}
)

Expand Down Expand Up @@ -160,6 +167,12 @@ func TestComment_GetIgnoreLines(t *testing.T) {
filename: "",
want: []int{5, 6, 7, 8},
},
{
name: "TestComment_GetIgnoreLines: dont-ignore-lines-with-comment-at-the-end",
content: samples["dont-ignore-lines-with-comment-at-the-end"],
filename: "",
want: []int{},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit c5aa128

Please sign in to comment.