diff --git a/pkg/parser/terraform/comment/comment.go b/pkg/parser/terraform/comment/comment.go index 6bd995acbda..60a10d8293c 100644 --- a/pkg/parser/terraform/comment/comment.go +++ b/pkg/parser/terraform/comment/comment.go @@ -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) } diff --git a/pkg/parser/terraform/comment/comment_test.go b/pkg/parser/terraform/comment/comment_test.go index d9e5fc80fa9..65d2f144e16 100644 --- a/pkg/parser/terraform/comment/comment_test.go +++ b/pkg/parser/terraform/comment/comment_test.go @@ -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 */ + }`), } ) @@ -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 {