Skip to content

Commit 71da4da

Browse files
committed
Fix pattern anchor completion for partial Smithy patterns
The Smithy models contain many incomplete patterns that are missing anchors. The Ruby SDK generator added both ^ and $ anchors to ensure patterns match entire strings, but used different strategies: 1. Patterns ending with quantifiers (* + ? {}) just need $ Example: "^[a-z]*" → "^[a-z]*$" 2. Patterns ending with delimiters (: /) or literals need .*$ Example: "^arn:" → "^arn:.*$" (matches "arn:aws:...") Example: "^s3://" → "^s3://.*$" (matches "s3://bucket/key") 3. Bare modifier patterns need .*$ Example: "^(?s)" → "^(?s).*$" (matches any content in dotall mode) This commit implements these heuristics to maintain backward compatibility with the Ruby SDK generator, affecting ~20 patterns across various AWS services.
1 parent 507885e commit 71da4da

22 files changed

+105
-47
lines changed

rules/models/aws_amplify_app_invalid_basic_auth_credentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewAwsAmplifyAppInvalidBasicAuthCredentialsRule() *AwsAmplifyAppInvalidBasi
2626
resourceType: "aws_amplify_app",
2727
attributeName: "basic_auth_credentials",
2828
max: 2000,
29-
pattern: regexp.MustCompile(`^(?s)`),
29+
pattern: regexp.MustCompile(`^(?s).*$`),
3030
}
3131
}
3232

@@ -80,7 +80,7 @@ func (r *AwsAmplifyAppInvalidBasicAuthCredentialsRule) Check(runner tflint.Runne
8080
if !r.pattern.MatchString(val) {
8181
runner.EmitIssue(
8282
r,
83-
`basic_auth_credentials does not match valid pattern ^(?s)`,
83+
`basic_auth_credentials does not match valid pattern ^(?s).*$`,
8484
attribute.Expr.Range(),
8585
)
8686
}

rules/models/aws_amplify_app_invalid_description.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewAwsAmplifyAppInvalidDescriptionRule() *AwsAmplifyAppInvalidDescriptionRu
2727
resourceType: "aws_amplify_app",
2828
attributeName: "description",
2929
max: 1000,
30-
pattern: regexp.MustCompile(`^(?s)`),
30+
pattern: regexp.MustCompile(`^(?s).*$`),
3131
}
3232
}
3333

@@ -81,7 +81,7 @@ func (r *AwsAmplifyAppInvalidDescriptionRule) Check(runner tflint.Runner) error
8181
if !r.pattern.MatchString(val) {
8282
runner.EmitIssue(
8383
r,
84-
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s)`),
84+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s).*$`),
8585
attribute.Expr.Range(),
8686
)
8787
}

rules/models/aws_amplify_app_invalid_iam_service_role_arn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewAwsAmplifyAppInvalidIAMServiceRoleArnRule() *AwsAmplifyAppInvalidIAMServ
2727
resourceType: "aws_amplify_app",
2828
attributeName: "iam_service_role_arn",
2929
max: 1000,
30-
pattern: regexp.MustCompile(`^(?s)`),
30+
pattern: regexp.MustCompile(`^(?s).*$`),
3131
}
3232
}
3333

@@ -81,7 +81,7 @@ func (r *AwsAmplifyAppInvalidIAMServiceRoleArnRule) Check(runner tflint.Runner)
8181
if !r.pattern.MatchString(val) {
8282
runner.EmitIssue(
8383
r,
84-
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s)`),
84+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s).*$`),
8585
attribute.Expr.Range(),
8686
)
8787
}

rules/models/aws_amplify_app_invalid_oauth_token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewAwsAmplifyAppInvalidOAuthTokenRule() *AwsAmplifyAppInvalidOAuthTokenRule
2626
resourceType: "aws_amplify_app",
2727
attributeName: "oauth_token",
2828
max: 1000,
29-
pattern: regexp.MustCompile(`^(?s)`),
29+
pattern: regexp.MustCompile(`^(?s).*$`),
3030
}
3131
}
3232

@@ -80,7 +80,7 @@ func (r *AwsAmplifyAppInvalidOAuthTokenRule) Check(runner tflint.Runner) error {
8080
if !r.pattern.MatchString(val) {
8181
runner.EmitIssue(
8282
r,
83-
`oauth_token does not match valid pattern ^(?s)`,
83+
`oauth_token does not match valid pattern ^(?s).*$`,
8484
attribute.Expr.Range(),
8585
)
8686
}

rules/models/aws_amplify_app_invalid_repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewAwsAmplifyAppInvalidRepositoryRule() *AwsAmplifyAppInvalidRepositoryRule
2727
resourceType: "aws_amplify_app",
2828
attributeName: "repository",
2929
max: 1000,
30-
pattern: regexp.MustCompile(`^(?s)`),
30+
pattern: regexp.MustCompile(`^(?s).*$`),
3131
}
3232
}
3333

@@ -81,7 +81,7 @@ func (r *AwsAmplifyAppInvalidRepositoryRule) Check(runner tflint.Runner) error {
8181
if !r.pattern.MatchString(val) {
8282
runner.EmitIssue(
8383
r,
84-
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s)`),
84+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s).*$`),
8585
attribute.Expr.Range(),
8686
)
8787
}

rules/models/aws_amplify_branch_invalid_backend_environment_arn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewAwsAmplifyBranchInvalidBackendEnvironmentArnRule() *AwsAmplifyBranchInva
2727
resourceType: "aws_amplify_branch",
2828
attributeName: "backend_environment_arn",
2929
max: 1000,
30-
pattern: regexp.MustCompile(`^(?s)`),
30+
pattern: regexp.MustCompile(`^(?s).*$`),
3131
}
3232
}
3333

@@ -81,7 +81,7 @@ func (r *AwsAmplifyBranchInvalidBackendEnvironmentArnRule) Check(runner tflint.R
8181
if !r.pattern.MatchString(val) {
8282
runner.EmitIssue(
8383
r,
84-
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s)`),
84+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s).*$`),
8585
attribute.Expr.Range(),
8686
)
8787
}

rules/models/aws_amplify_branch_invalid_basic_auth_credentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewAwsAmplifyBranchInvalidBasicAuthCredentialsRule() *AwsAmplifyBranchInval
2626
resourceType: "aws_amplify_branch",
2727
attributeName: "basic_auth_credentials",
2828
max: 2000,
29-
pattern: regexp.MustCompile(`^(?s)`),
29+
pattern: regexp.MustCompile(`^(?s).*$`),
3030
}
3131
}
3232

@@ -80,7 +80,7 @@ func (r *AwsAmplifyBranchInvalidBasicAuthCredentialsRule) Check(runner tflint.Ru
8080
if !r.pattern.MatchString(val) {
8181
runner.EmitIssue(
8282
r,
83-
`basic_auth_credentials does not match valid pattern ^(?s)`,
83+
`basic_auth_credentials does not match valid pattern ^(?s).*$`,
8484
attribute.Expr.Range(),
8585
)
8686
}

rules/models/aws_amplify_branch_invalid_description.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewAwsAmplifyBranchInvalidDescriptionRule() *AwsAmplifyBranchInvalidDescrip
2727
resourceType: "aws_amplify_branch",
2828
attributeName: "description",
2929
max: 1000,
30-
pattern: regexp.MustCompile(`^(?s)`),
30+
pattern: regexp.MustCompile(`^(?s).*$`),
3131
}
3232
}
3333

@@ -81,7 +81,7 @@ func (r *AwsAmplifyBranchInvalidDescriptionRule) Check(runner tflint.Runner) err
8181
if !r.pattern.MatchString(val) {
8282
runner.EmitIssue(
8383
r,
84-
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s)`),
84+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s).*$`),
8585
attribute.Expr.Range(),
8686
)
8787
}

rules/models/aws_amplify_branch_invalid_display_name.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewAwsAmplifyBranchInvalidDisplayNameRule() *AwsAmplifyBranchInvalidDisplay
2727
resourceType: "aws_amplify_branch",
2828
attributeName: "display_name",
2929
max: 255,
30-
pattern: regexp.MustCompile(`^(?s)`),
30+
pattern: regexp.MustCompile(`^(?s).*$`),
3131
}
3232
}
3333

@@ -81,7 +81,7 @@ func (r *AwsAmplifyBranchInvalidDisplayNameRule) Check(runner tflint.Runner) err
8181
if !r.pattern.MatchString(val) {
8282
runner.EmitIssue(
8383
r,
84-
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s)`),
84+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s).*$`),
8585
attribute.Expr.Range(),
8686
)
8787
}

rules/models/aws_amplify_branch_invalid_framework.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewAwsAmplifyBranchInvalidFrameworkRule() *AwsAmplifyBranchInvalidFramework
2727
resourceType: "aws_amplify_branch",
2828
attributeName: "framework",
2929
max: 255,
30-
pattern: regexp.MustCompile(`^(?s)`),
30+
pattern: regexp.MustCompile(`^(?s).*$`),
3131
}
3232
}
3333

@@ -81,7 +81,7 @@ func (r *AwsAmplifyBranchInvalidFrameworkRule) Check(runner tflint.Runner) error
8181
if !r.pattern.MatchString(val) {
8282
runner.EmitIssue(
8383
r,
84-
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s)`),
84+
fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?s).*$`),
8585
attribute.Expr.Range(),
8686
)
8787
}

0 commit comments

Comments
 (0)