Skip to content

Commit 7cb16fb

Browse files
authored
Exit with an error if the explicitly passed .tflint.hcl does not exist (#1940)
1 parent 9259d0e commit 7cb16fb

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

cmd/option.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Options struct {
1414
Init bool `long:"init" description:"Install plugins"`
1515
Langserver bool `long:"langserver" description:"Start language server"`
1616
Format string `short:"f" long:"format" description:"Output format" choice:"default" choice:"json" choice:"checkstyle" choice:"junit" choice:"compact" choice:"sarif"`
17-
Config string `short:"c" long:"config" description:"Config file name" value-name:"FILE" default:".tflint.hcl"`
17+
Config string `short:"c" long:"config" description:"Config file name (default: .tflint.hcl)" value-name:"FILE"`
1818
IgnoreModules []string `long:"ignore-module" description:"Ignore module sources" value-name:"SOURCE"`
1919
EnableRules []string `long:"enable-rule" description:"Enable rules from the command line" value-name:"RULE_NAME"`
2020
DisableRules []string `long:"disable-rule" description:"Disable rules from the command line" value-name:"RULE_NAME"`

tflint/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func EmptyConfig() *Config {
139139
// plugin block is not explicitly declared.
140140
func LoadConfig(fs afero.Afero, file string) (*Config, error) {
141141
// Load the file passed by the --config option
142-
if file != defaultConfigFile {
142+
if file != "" {
143143
log.Printf("[INFO] Load config: %s", file)
144144
f, err := fs.Open(file)
145145
if err != nil {
@@ -168,8 +168,8 @@ func LoadConfig(fs afero.Afero, file string) (*Config, error) {
168168
}
169169

170170
// Load the default config file
171-
log.Printf("[INFO] Load config: %s", file)
172-
if f, err := fs.Open(file); err == nil {
171+
log.Printf("[INFO] Load config: %s", defaultConfigFile)
172+
if f, err := fs.Open(defaultConfigFile); err == nil {
173173
cfg, err := loadConfig(f)
174174
if err != nil {
175175
return nil, err

tflint/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ plugin "baz" {
134134
},
135135
{
136136
name: "TFLINT_CONFIG_FILE",
137-
file: ".tflint.hcl",
137+
file: "",
138138
files: map[string]string{
139139
"env.hcl": `
140140
config {
@@ -166,7 +166,7 @@ config {
166166
},
167167
{
168168
name: "default home config",
169-
file: ".tflint.hcl",
169+
file: "",
170170
files: map[string]string{
171171
"/root/.tflint.hcl": `
172172
config {
@@ -195,7 +195,7 @@ config {
195195
},
196196
{
197197
name: "no config",
198-
file: ".tflint.hcl",
198+
file: "",
199199
want: EmptyConfig().enableBundledPlugin(),
200200
errCheck: neverHappend,
201201
},
@@ -234,7 +234,7 @@ plugin "terraform" {
234234
},
235235
{
236236
name: "file not found with TFLINT_CONFIG_FILE",
237-
file: ".tflint.hcl",
237+
file: "",
238238
envs: map[string]string{
239239
"TFLINT_CONFIG_FILE": "not_found.hcl",
240240
},

0 commit comments

Comments
 (0)