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

Ignore default preset by disabled_by_default #1514

Merged
merged 1 commit into from
Sep 15, 2022
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install:
go install

e2e: prepare install
go test -timeout 5m ./integrationtest/inspection ./integrationtest/langserver ./integrationtest/init ./integrationtest/cli
go test -timeout 5m ./integrationtest/inspection ./integrationtest/langserver ./integrationtest/init ./integrationtest/cli ./integrationtest/bundled

lint:
golangci-lint run ./...
Expand Down
5 changes: 5 additions & 0 deletions integrationtest/bundled/bundled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func TestIntegration(t *testing.T) {
command: "tflint --format json --force",
dir: "with_config",
},
{
name: "disabled_by_default",
command: "tflint --format json --force",
dir: "disabled_by_default",
},
}

dir, _ := os.Getwd()
Expand Down
7 changes: 7 additions & 0 deletions integrationtest/bundled/disabled_by_default/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config {
disabled_by_default = true
}

rule "terraform_unused_declarations" {
enabled = true
}
6 changes: 6 additions & 0 deletions integrationtest/bundled/disabled_by_default/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
variable "unused" {}
variable "used" {}

resource "aws_instance" "main" {
instance_type = "${var.used}"
}
25 changes: 25 additions & 0 deletions integrationtest/bundled/disabled_by_default/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"issues": [
{
"rule": {
"name": "terraform_unused_declarations",
"severity": "warning",
"link": "https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.1.0/docs/rules/terraform_unused_declarations.md"
},
"message": "variable \"unused\" is declared but not used",
"range": {
"filename": "main.tf",
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 18
}
},
"callers": []
}
],
"errors": []
}
5 changes: 5 additions & 0 deletions tflint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ func (c *Config) enableBundledPlugin() *Config {
Enabled: true,
Body: f.Body,
}

// Implicit preset is ignored if you enable DisabledByDefault
if c.DisabledByDefault {
c.Plugins["terraform"].Body = nil
}
}
return c
}
Expand Down