Skip to content

Commit

Permalink
refactor: load default config last
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Jan 7, 2024
1 parent c5e8345 commit 4e7d95c
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions internal/core/ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,28 +177,6 @@ func loadINI(cfg *Config, dry bool) (*ini.File, error) {
SpaceBeforeInlineComment: true,
})

// NOTE: In v3.0, we now use the user's config directory as the default
// location.
//
// This is different from the other config-defining options (`--config`,
// `VALE_CONFIG_PATH`, etc.) in that it's loaded in addition to, rather
// than instead of, any other configuration sources.
//
// In other words, this config file is *always* loaded and then any other
// sources are loaded on top of it.
configDir, err := os.UserConfigDir()
if err != nil {
return nil, err
}

defaultCfg := path.Join(configDir, "vale", ".vale.ini")
if FileExists(defaultCfg) {
err = uCfg.Append(defaultCfg)
if err != nil {
return nil, NewE100("default/ini", err)
}
}

base, err := loadConfig(configNames)
if err != nil {
return nil, NewE100("loadINI/homedir", err)
Expand Down Expand Up @@ -248,6 +226,28 @@ func loadINI(cfg *Config, dry bool) (*ini.File, error) {
cfg.MinAlertLevel = LevelToInt[cfg.Flags.AlertLevel]
}

// NOTE: In v3.0, we now use the user's config directory as the default
// location.
//
// This is different from the other config-defining options (`--config`,
// `VALE_CONFIG_PATH`, etc.) in that it's loaded in addition to, rather
// than instead of, any other configuration sources.
//
// In other words, this config file is *always* loaded and is read after
// any other sources to allow for project-agnostic customization.
configDir, err := os.UserConfigDir()
if err != nil {
return nil, err
}

defaultCfg := path.Join(configDir, "vale", ".vale.ini")
if FileExists(defaultCfg) {
err = uCfg.Append(defaultCfg)
if err != nil {
return nil, NewE100("default/ini", err)
}
}

uCfg.BlockMode = false
return processConfig(uCfg, cfg, sources, dry)
}
Expand Down

0 comments on commit 4e7d95c

Please sign in to comment.