@@ -100,11 +100,25 @@ func loadStdin(src string, cfg *Config, dry bool) (*ini.File, error) {
100100}
101101
102102func loadINI (cfg * Config , dry bool ) (* ini.File , error ) {
103- uCfg := ini .Empty (ini.LoadOptions {
104- AllowShadows : true ,
105- Loose : true ,
106- SpaceBeforeInlineComment : true ,
107- })
103+ var sources []string
104+ var uCfg * ini.File
105+
106+ // NOTE: In v3.0, we now use the user's config directory as the default
107+ // location.
108+ //
109+ // This is different from the other config-defining options (`--config`,
110+ // `VALE_CONFIG_PATH`, etc.) in that it's loaded in addition to, rather
111+ // than instead of, any other configuration sources.
112+ //
113+ // In other words, this config file is *always* loaded and is read after
114+ // any other sources to allow for project-agnostic customization.
115+ defaultCfg , _ := DefaultConfig ()
116+
117+ if system .FileExists (defaultCfg ) && ! cfg .Flags .IgnoreGlobal && ! dry {
118+ sources = append (sources , defaultCfg )
119+ cfg .Flags .Local = true
120+ cfg .AddConfigFile (defaultCfg )
121+ }
108122
109123 base , err := loadConfig (configNames )
110124 if err != nil {
@@ -115,71 +129,37 @@ func loadINI(cfg *Config, dry bool) (*ini.File, error) {
115129 if cfg .Flags .Sources != "" {
116130 // NOTE: This case shouldn't be accessible from the CLI, but it can
117131 // still be triggered by packages that include config files.
118- var sources []string
119132
120133 for _ , source := range strings .Split (cfg .Flags .Sources , "," ) {
121134 abs , _ := filepath .Abs (source )
122135 sources = append (sources , abs )
123136 }
124-
125- // We have multiple sources -- e.g., local config + remote package(s).
126- //
127- // See fixtures/config.feature#451 for an explanation of how this has
128- // changed since Vale Server was deprecated.
129- uCfg , err = processSources (cfg , sources )
130- if err != nil {
131- return nil , NewE100 ("config pipeline failed" , err )
132- }
133137 } else if cfg .Flags .Path != "" {
134138 // We've been given a value through `--config`.
135- err = uCfg .Append (cfg .Flags .Path )
136- if err != nil {
137- return nil , NewE100 ("invalid --config" , err )
138- }
139+ sources = append (sources , cfg .Flags .Path )
139140 cfg .AddConfigFile (cfg .Flags .Path )
140141 } else if fromEnv , hasEnv := os .LookupEnv ("VALE_CONFIG_PATH" ); hasEnv {
141142 // We've been given a value through `VALE_CONFIG_PATH`.
142- err = uCfg .Append (fromEnv )
143- if err != nil {
144- return nil , NewE100 ("invalid VALE_CONFIG_PATH" , err )
145- }
143+ sources = append (sources , fromEnv )
146144 cfg .AddConfigFile (fromEnv )
147145 } else if base != "" {
148146 // We're using a config file found using a local search process.
149- err = uCfg .Append (base )
150- if err != nil {
151- return nil , NewE100 (".vale.ini not found" , err )
152- }
147+ sources = append (sources , base )
153148 cfg .AddConfigFile (base )
154149 }
155150
156151 if StringInSlice (cfg .Flags .AlertLevel , AlertLevels ) {
157152 cfg .MinAlertLevel = LevelToInt [cfg .Flags .AlertLevel ]
158153 }
159154
160- // NOTE: In v3.0, we now use the user's config directory as the default
161- // location.
162- //
163- // This is different from the other config-defining options (`--config`,
164- // `VALE_CONFIG_PATH`, etc.) in that it's loaded in addition to, rather
165- // than instead of, any other configuration sources.
166- //
167- // In other words, this config file is *always* loaded and is read after
168- // any other sources to allow for project-agnostic customization.
169- defaultCfg , _ := DefaultConfig ()
170-
171- if system .FileExists (defaultCfg ) && ! cfg .Flags .IgnoreGlobal && ! dry {
172- err = uCfg .Append (defaultCfg )
173- if err != nil {
174- return nil , NewE100 ("default/ini" , err )
175- }
176- cfg .Flags .Local = true
177- cfg .AddConfigFile (defaultCfg )
178- } else if base == "" && len (cfg .ConfigFiles ) == 0 && ! dry {
155+ if base == "" && len (cfg .ConfigFiles ) == 0 && ! dry {
179156 return nil , NewE100 (".vale.ini not found" , errors .New ("no config file found" ))
180157 }
181158
182- uCfg .BlockMode = false
159+ uCfg , err = processSources (cfg , sources )
160+ if err != nil {
161+ return nil , NewE100 ("config pipeline failed" , err )
162+ }
183163 return processConfig (uCfg , cfg , dry )
184164}
185165
0 commit comments