Skip to content

Commit

Permalink
Exit with an error if the explicitly passed .tflint.hcl does not ex…
Browse files Browse the repository at this point in the history
…ist (#1940)
  • Loading branch information
wata727 authored Dec 16, 2023
1 parent 9259d0e commit 7cb16fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Options struct {
Init bool `long:"init" description:"Install plugins"`
Langserver bool `long:"langserver" description:"Start language server"`
Format string `short:"f" long:"format" description:"Output format" choice:"default" choice:"json" choice:"checkstyle" choice:"junit" choice:"compact" choice:"sarif"`
Config string `short:"c" long:"config" description:"Config file name" value-name:"FILE" default:".tflint.hcl"`
Config string `short:"c" long:"config" description:"Config file name (default: .tflint.hcl)" value-name:"FILE"`
IgnoreModules []string `long:"ignore-module" description:"Ignore module sources" value-name:"SOURCE"`
EnableRules []string `long:"enable-rule" description:"Enable rules from the command line" value-name:"RULE_NAME"`
DisableRules []string `long:"disable-rule" description:"Disable rules from the command line" value-name:"RULE_NAME"`
Expand Down
6 changes: 3 additions & 3 deletions tflint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func EmptyConfig() *Config {
// plugin block is not explicitly declared.
func LoadConfig(fs afero.Afero, file string) (*Config, error) {
// Load the file passed by the --config option
if file != defaultConfigFile {
if file != "" {
log.Printf("[INFO] Load config: %s", file)
f, err := fs.Open(file)
if err != nil {
Expand Down Expand Up @@ -168,8 +168,8 @@ func LoadConfig(fs afero.Afero, file string) (*Config, error) {
}

// Load the default config file
log.Printf("[INFO] Load config: %s", file)
if f, err := fs.Open(file); err == nil {
log.Printf("[INFO] Load config: %s", defaultConfigFile)
if f, err := fs.Open(defaultConfigFile); err == nil {
cfg, err := loadConfig(f)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions tflint/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ plugin "baz" {
},
{
name: "TFLINT_CONFIG_FILE",
file: ".tflint.hcl",
file: "",
files: map[string]string{
"env.hcl": `
config {
Expand Down Expand Up @@ -166,7 +166,7 @@ config {
},
{
name: "default home config",
file: ".tflint.hcl",
file: "",
files: map[string]string{
"/root/.tflint.hcl": `
config {
Expand Down Expand Up @@ -195,7 +195,7 @@ config {
},
{
name: "no config",
file: ".tflint.hcl",
file: "",
want: EmptyConfig().enableBundledPlugin(),
errCheck: neverHappend,
},
Expand Down Expand Up @@ -234,7 +234,7 @@ plugin "terraform" {
},
{
name: "file not found with TFLINT_CONFIG_FILE",
file: ".tflint.hcl",
file: "",
envs: map[string]string{
"TFLINT_CONFIG_FILE": "not_found.hcl",
},
Expand Down

0 comments on commit 7cb16fb

Please sign in to comment.