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

Exit with an error if the explicitly passed .tflint.hcl does not exist #1940

Merged
merged 1 commit into from
Dec 16, 2023
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 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
Loading