Skip to content

Commit

Permalink
Merge pull request #454 from wata727/remove_ignore_rule
Browse files Browse the repository at this point in the history
Remove deprecated `ignore-rule` option
  • Loading branch information
wata727 authored Sep 28, 2019
2 parents 2e57061 + f46c91d commit 88ad43d
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 126 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ Application Options:
-f, --format=[default|json|checkstyle] Output format (default: default)
-c, --config=FILE Config file name (default: .tflint.hcl)
--ignore-module=SOURCE1,SOURCE2... Ignore module sources
--ignore-rule=RULE1,RULE2... Ignore rule names
--var-file=FILE1,FILE2... Terraform variable file names
--var='foo=bar' Set a Terraform variable
--module Inspect modules
Expand Down
3 changes: 3 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func (cli *CLI) Run(args []string) int {
if option == "quiet" || option == "q" {
return []string{}, errors.New("`quiet` option was removed in v0.11.0. The behavior is now default")
}
if option == "ignore-rule" {
return []string{}, errors.New("`ignore-rule` option was removed in v0.12.0")
}
return []string{}, fmt.Errorf("`%s` is unknown option. Please run `tflint --help`", option)
}
// Parse commandline flag
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func TestCLIRun__noIssuesFound(t *testing.T) {
Status: ExitCodeError,
Stderr: "`quiet` option was removed in v0.11.0. The behavior is now default",
},
{
Name: "removed `--ignore-rule` option",
Command: "./tflint --ignore-rule aws_instance_invalid_type",
Status: ExitCodeError,
Stderr: "`ignore-rule` option was removed in v0.12.0",
},
{
Name: "invalid options",
Command: "./tflint --unknown",
Expand Down
10 changes: 0 additions & 10 deletions cmd/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Options struct {
Format string `short:"f" long:"format" description:"Output format" choice:"default" choice:"json" choice:"checkstyle" default:"default"`
Config string `short:"c" long:"config" description:"Config file name" value-name:"FILE" default:".tflint.hcl"`
IgnoreModule string `long:"ignore-module" description:"Ignore module sources" value-name:"SOURCE1,SOURCE2..."`
IgnoreRule string `long:"ignore-rule" description:"Ignore rule names" value-name:"RULE1,RULE2..."`
Varfile string `long:"var-file" description:"Terraform variable file names" value-name:"FILE1,FILE2..."`
Variables []string `long:"var" description:"Set a Terraform variable" value-name:"'foo=bar'"`
Module bool `long:"module" description:"Inspect modules"`
Expand All @@ -37,13 +36,6 @@ func (opts *Options) toConfig() *tflint.Config {
}
}

ignoreRule := map[string]bool{}
if opts.IgnoreRule != "" {
for _, r := range strings.Split(opts.IgnoreRule, ",") {
ignoreRule[r] = true
}
}

varfile := []string{}
if opts.Varfile != "" {
varfile = strings.Split(opts.Varfile, ",")
Expand All @@ -57,7 +49,6 @@ func (opts *Options) toConfig() *tflint.Config {
log.Printf("[DEBUG] DeepCheck: %t", opts.Deep)
log.Printf("[DEBUG] Force: %t", opts.Force)
log.Printf("[DEBUG] IgnoreModule: %#v", ignoreModule)
log.Printf("[DEBUG] IgnoreRule: %#v", ignoreRule)
log.Printf("[DEBUG] Varfile: %#v", varfile)
log.Printf("[DEBUG] Variables: %#v", opts.Variables)

Expand All @@ -73,7 +64,6 @@ func (opts *Options) toConfig() *tflint.Config {
Region: opts.AwsRegion,
},
IgnoreModule: ignoreModule,
IgnoreRule: ignoreRule,
Varfile: varfile,
Variables: opts.Variables,
Rules: map[string]*tflint.RuleConfig{},
Expand Down
24 changes: 0 additions & 24 deletions cmd/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func Test_toConfig(t *testing.T) {
Force: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
Expand All @@ -45,7 +44,6 @@ func Test_toConfig(t *testing.T) {
Force: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
Expand All @@ -60,7 +58,6 @@ func Test_toConfig(t *testing.T) {
Force: true,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
Expand All @@ -79,7 +76,6 @@ func Test_toConfig(t *testing.T) {
Region: "us-east-1",
},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
Expand All @@ -97,7 +93,6 @@ func Test_toConfig(t *testing.T) {
Region: "us-east-1",
},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
Expand All @@ -116,7 +111,6 @@ func Test_toConfig(t *testing.T) {
Region: "us-east-1",
},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
Expand All @@ -131,22 +125,6 @@ func Test_toConfig(t *testing.T) {
Force: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{"module1": true, "module2": true},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
},
},
{
Name: "--ignore-rule",
Command: "./tflint --ignore-rule rule1,rule2",
Expected: &tflint.Config{
Module: false,
DeepCheck: false,
Force: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{"rule1": true, "rule2": true},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
Expand All @@ -161,7 +139,6 @@ func Test_toConfig(t *testing.T) {
Force: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{"example1.tfvars", "example2.tfvars"},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
Expand All @@ -176,7 +153,6 @@ func Test_toConfig(t *testing.T) {
Force: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{"foo=bar", "bar=baz"},
Rules: map[string]*tflint.RuleConfig{},
Expand Down
8 changes: 0 additions & 8 deletions docs/guides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,10 @@ Set a Terraform variable from a passed value. This flag can be set multiple time

## `rule` blocks

CLI flag: `--ignore-rule`

You can make settings for each rule in the `rule` block. Currently, it can set only `enabled` option. If you set `enabled = false`, TFLint doesn't inspect configuration files by this rule.

```hcl
rule "aws_instance_previous_type" {
enabled = false
}
```

You can also disable rules with the `--ignore-rule` option.

```
$ tflint --ignore-rule=aws_instance_invalid_type,aws_instance_previous_type
```
14 changes: 6 additions & 8 deletions rules/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,18 @@ func NewRules(c *tflint.Config) []Rule {
}

for _, rule := range allRules {
enabled := rule.Enabled()
if r := c.Rules[rule.Name()]; r != nil {
if r.Enabled {
log.Printf("[DEBUG] `%s` is enabled", rule.Name())
ret = append(ret, rule)
} else {
log.Printf("[DEBUG] `%s` is disabled", rule.Name())
}
} else {
if !c.IgnoreRule[rule.Name()] && rule.Enabled() {
log.Printf("[DEBUG] `%s` is enabled", rule.Name())
ret = append(ret, rule)
} else {
log.Printf("[DEBUG] `%s` is disabled", rule.Name())
}
enabled = r.Enabled
}

if enabled {
ret = append(ret, rule)
}
}

Expand Down
19 changes: 5 additions & 14 deletions rules/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"testing"

"github.com/wata727/tflint/rules/awsrules"
"github.com/wata727/tflint/rules/terraformrules"
"github.com/wata727/tflint/tflint"
)

func Test_NewRules(t *testing.T) {
// Mock rules in test
DefaultRules = []Rule{
awsrules.NewAwsRouteNotSpecifiedTargetRule(),
terraformrules.NewTerraformDashInResourceNameRule(),
}
deepCheckRules = []Rule{
awsrules.NewAwsInstanceInvalidAMIRule(),
Expand Down Expand Up @@ -39,15 +41,6 @@ func Test_NewRules(t *testing.T) {
awsrules.NewAwsInstanceInvalidAMIRule(),
},
},
{
Name: "ignore_rule",
Config: &tflint.Config{
IgnoreRule: map[string]bool{
"aws_route_not_specified_target": true,
},
},
Expected: []Rule{},
},
{
Name: "enabled = false",
Config: &tflint.Config{
Expand All @@ -60,19 +53,17 @@ func Test_NewRules(t *testing.T) {
Expected: []Rule{},
},
{
Name: "`enabled = true` and `ignore_rule`",
Name: "enabled = true",
Config: &tflint.Config{
IgnoreRule: map[string]bool{
"aws_route_not_specified_target": true,
},
Rules: map[string]*tflint.RuleConfig{
"aws_route_not_specified_target": {
"terraform_dash_in_resource_name": {
Enabled: true,
},
},
},
Expected: []Rule{
awsrules.NewAwsRouteNotSpecifiedTargetRule(),
terraformrules.NewTerraformDashInResourceNameRule(),
},
},
}
Expand Down
42 changes: 18 additions & 24 deletions tflint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ var fallbackConfigFile = "~/.tflint.hcl"

type rawConfig struct {
Config *struct {
Module *bool `hcl:"module"`
DeepCheck *bool `hcl:"deep_check"`
Force *bool `hcl:"force"`
AwsCredentials *map[string]string `hcl:"aws_credentials"`
IgnoreModule *map[string]bool `hcl:"ignore_module"`
IgnoreRule *map[string]bool `hcl:"ignore_rule"`
Varfile *[]string `hcl:"varfile"`
Variables *[]string `hcl:"variables"`
TerraformVersion *string `hcl:"terraform_version"`
Module *bool `hcl:"module"`
DeepCheck *bool `hcl:"deep_check"`
Force *bool `hcl:"force"`
AwsCredentials *map[string]string `hcl:"aws_credentials"`
IgnoreModule *map[string]bool `hcl:"ignore_module"`
Varfile *[]string `hcl:"varfile"`
Variables *[]string `hcl:"variables"`
// Removed options
TerraformVersion *string `hcl:"terraform_version"`
IgnoreRule *map[string]bool `hcl:"ignore_rule"`
} `hcl:"config,block"`
Rules []RuleConfig `hcl:"rule,block"`
}
Expand All @@ -37,7 +38,6 @@ type Config struct {
Force bool
AwsCredentials client.AwsCredentials
IgnoreModule map[string]bool
IgnoreRule map[string]bool
Varfile []string
Variables []string
Rules map[string]*RuleConfig
Expand All @@ -58,7 +58,6 @@ func EmptyConfig() *Config {
Force: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*RuleConfig{},
Expand Down Expand Up @@ -121,7 +120,6 @@ func (c *Config) Merge(other *Config) *Config {

ret.AwsCredentials = ret.AwsCredentials.Merge(other.AwsCredentials)
ret.IgnoreModule = mergeBoolMap(ret.IgnoreModule, other.IgnoreModule)
ret.IgnoreRule = mergeBoolMap(ret.IgnoreRule, other.IgnoreRule)
ret.Varfile = append(ret.Varfile, other.Varfile...)
ret.Variables = append(ret.Variables, other.Variables...)

Expand All @@ -136,11 +134,6 @@ func (c *Config) copy() *Config {
ignoreModule[k] = v
}

ignoreRule := make(map[string]bool)
for k, v := range c.IgnoreRule {
ignoreRule[k] = v
}

varfile := make([]string, len(c.Varfile))
copy(varfile, c.Varfile)

Expand All @@ -159,7 +152,6 @@ func (c *Config) copy() *Config {
Force: c.Force,
AwsCredentials: c.AwsCredentials,
IgnoreModule: ignoreModule,
IgnoreRule: ignoreRule,
Varfile: varfile,
Variables: variables,
Rules: rules,
Expand All @@ -180,8 +172,14 @@ func loadConfigFromFile(file string) (*Config, error) {
return nil, diags
}

if raw.Config != nil && raw.Config.TerraformVersion != nil {
return nil, errors.New("`terraform_version` was removed in v0.9.0 because the option is no longer used")
if raw.Config != nil {
if raw.Config.TerraformVersion != nil {
return nil, errors.New("`terraform_version` was removed in v0.9.0 because the option is no longer used")
}

if raw.Config.IgnoreRule != nil {
return nil, errors.New("`ignore_rule` was removed in v0.12.0. Please define `rule` block with `enabled = false` instead")
}
}

cfg := raw.toConfig()
Expand All @@ -190,7 +188,6 @@ func loadConfigFromFile(file string) (*Config, error) {
log.Printf("[DEBUG] DeepCheck: %t", cfg.DeepCheck)
log.Printf("[DEBUG] Force: %t", cfg.Force)
log.Printf("[DEBUG] IgnoreModule: %#v", cfg.IgnoreModule)
log.Printf("[DEBUG] IgnoreRule: %#v", cfg.IgnoreRule)
log.Printf("[DEBUG] Varfile: %#v", cfg.Varfile)
log.Printf("[DEBUG] Variables: %#v", cfg.Variables)
log.Printf("[DEBUG] Rules: %#v", cfg.Rules)
Expand Down Expand Up @@ -245,9 +242,6 @@ func (raw *rawConfig) toConfig() *Config {
if rc.IgnoreModule != nil {
ret.IgnoreModule = *rc.IgnoreModule
}
if rc.IgnoreRule != nil {
ret.IgnoreRule = *rc.IgnoreRule
}
if rc.Varfile != nil {
ret.Varfile = *rc.Varfile
}
Expand Down
Loading

0 comments on commit 88ad43d

Please sign in to comment.