From 469695fdb108b916f0538d9f1cce8d8888c6a96c Mon Sep 17 00:00:00 2001 From: Kazuma Watanabe Date: Mon, 4 Sep 2023 00:27:21 +0900 Subject: [PATCH] Allow commas with spaces in annotations (#1834) --- tflint/annotation.go | 2 +- tflint/annotation_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tflint/annotation.go b/tflint/annotation.go index 96be03ff8..201e6d72f 100644 --- a/tflint/annotation.go +++ b/tflint/annotation.go @@ -10,7 +10,7 @@ import ( "golang.org/x/exp/slices" ) -var annotationPattern = regexp.MustCompile(`tflint-ignore: (\S+)`) +var annotationPattern = regexp.MustCompile(`tflint-ignore: ([^\n*/]+)`) // Annotation represents comments with special meaning in TFLint type Annotation struct { diff --git a/tflint/annotation_test.go b/tflint/annotation_test.go index b17f5d0ae..9b0352707 100644 --- a/tflint/annotation_test.go +++ b/tflint/annotation_test.go @@ -12,9 +12,9 @@ import ( func Test_NewAnnotations(t *testing.T) { src := ` resource "aws_instance" "foo" { - /* tflint-ignore: aws_instance_invalid_type */ + /* tflint-ignore: aws_instance_invalid_type, terraform_deprecated_syntax */ instance_type = "t2.micro" // tflint-ignore: aws_instance_invalid_type - # tflint-ignore: aws_instance_invalid_type This is also comment + # tflint-ignore: aws_instance_invalid_type iam_instance_profile = "foo" # This is also comment // This is also comment }` @@ -30,14 +30,14 @@ resource "aws_instance" "foo" { expected := Annotations{ { - Content: "aws_instance_invalid_type", + Content: "aws_instance_invalid_type, terraform_deprecated_syntax ", Token: hclsyntax.Token{ Type: hclsyntax.TokenComment, - Bytes: []byte("/* tflint-ignore: aws_instance_invalid_type */"), + Bytes: []byte("/* tflint-ignore: aws_instance_invalid_type, terraform_deprecated_syntax */"), Range: hcl.Range{ Filename: "resource.tf", Start: hcl.Pos{Line: 3, Column: 3}, - End: hcl.Pos{Line: 3, Column: 49}, + End: hcl.Pos{Line: 3, Column: 78}, }, }, }, @@ -57,7 +57,7 @@ resource "aws_instance" "foo" { Content: "aws_instance_invalid_type", Token: hclsyntax.Token{ Type: hclsyntax.TokenComment, - Bytes: []byte("# tflint-ignore: aws_instance_invalid_type This is also comment\n"), + Bytes: []byte("# tflint-ignore: aws_instance_invalid_type\n"), Range: hcl.Range{ Filename: "resource.tf", Start: hcl.Pos{Line: 5, Column: 3},