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

Fix crash when passed --enable-rule with a configured rule #1105

Merged
merged 1 commit into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions integrationtest/bundled/bundled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func TestBundledPlugin(t *testing.T) {
Command: "tflint --format json --force",
Dir: "map-attribute",
},
{
// Regression: https://github.com/terraform-linters/tflint/issues/1103
Name: "rule config with --enable-rule",
Command: "tflint --enable-rule aws_s3_bucket_name --format json --force",
Dir: "rule-config",
},
}

dir, _ := os.Getwd()
Expand Down
3 changes: 2 additions & 1 deletion tflint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ func mergeRuleMap(a, b map[string]*RuleConfig, bDisabledByDefault bool) map[stri
// @see https://github.com/hashicorp/hcl/blob/v2.5.0/merged.go#L132-L135
if prevConfig, exists := ret[k]; exists && v.Body.MissingItemRange().Filename == "<empty>" {
ret[k] = v
// Do not override body
// Do not override body and file
ret[k].Body = prevConfig.Body
ret[k].file = prevConfig.file
} else {
ret[k] = v
}
Expand Down