From 57e91253a0eba5df523e005cc4429ca58fa28a66 Mon Sep 17 00:00:00 2001 From: jdkato Date: Sat, 6 Jan 2024 23:48:47 -0800 Subject: [PATCH] fix: add `--no-global` --- cmd/vale/flag.go | 1 + cmd/vale/info.go | 1 + internal/check/manager.go | 11 ++++++++--- internal/core/config.go | 37 +++++++++++++++++++------------------ internal/core/ini.go | 2 +- testdata/features/steps.rb | 2 +- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/cmd/vale/flag.go b/cmd/vale/flag.go index d3255d75..9cf53f34 100644 --- a/cmd/vale/flag.go +++ b/cmd/vale/flag.go @@ -40,4 +40,5 @@ func init() { pflag.BoolVar(&Flags.Sorted, "sort", false, "sort files by their name in output") pflag.BoolVar(&Flags.Normalize, "normalize", false, "replace each path separator with a slash ('/')") pflag.BoolVar(&Flags.Relative, "relative", false, "return relative paths") + pflag.BoolVar(&Flags.IgnoreGlobal, "no-global", false, "ignore global configuration") } diff --git a/cmd/vale/info.go b/cmd/vale/info.go index 491905b0..7b94e5c5 100644 --- a/cmd/vale/info.go +++ b/cmd/vale/info.go @@ -68,6 +68,7 @@ var hidden = []string{ "sources", "built", "minAlertLevel", + "no-global", // API stuff "tag", diff --git a/internal/check/manager.go b/internal/check/manager.go index a0cab8d3..f2fa7eb5 100755 --- a/internal/check/manager.go +++ b/internal/check/manager.go @@ -58,9 +58,14 @@ func NewManager(config *core.Config) (*Manager, error) { // If this rule isn't part of an already-loaded style, we load it // individually. fName := parts[1] + ".yml" - path = filepath.Join(mgr.Config.StylesPath, parts[0], fName) - if err = mgr.addRuleFromSource(fName, path); err != nil { - return &mgr, err + for _, p := range mgr.Config.Paths { + path = filepath.Join(p, parts[0], fName) + if !core.FileExists(path) { + continue + } + if err = mgr.addRuleFromSource(fName, path); err != nil { + return &mgr, err + } } } } diff --git a/internal/core/config.go b/internal/core/config.go index 70d353af..97fc41a9 100644 --- a/internal/core/config.go +++ b/internal/core/config.go @@ -47,24 +47,25 @@ func IgnoreFiles(stylesPath string) ([]string, error) { // // For example, `vale --minAlertLevel=error`. type CLIFlags struct { - AlertLevel string - Built string - Glob string - InExt string - Output string - Path string - Sources string - Filter string - Local bool - NoExit bool - Normalize bool - Relative bool - Remote bool - Simple bool - Sorted bool - Wrap bool - Version bool - Help bool + AlertLevel string + Built string + Glob string + InExt string + Output string + Path string + Sources string + Filter string + Local bool + NoExit bool + Normalize bool + Relative bool + Remote bool + Simple bool + Sorted bool + Wrap bool + Version bool + Help bool + IgnoreGlobal bool } // Config holds the configuration values from both the CLI and `.vale.ini`. diff --git a/internal/core/ini.go b/internal/core/ini.go index 41daa8d1..d340a195 100644 --- a/internal/core/ini.go +++ b/internal/core/ini.go @@ -248,7 +248,7 @@ func loadINI(cfg *Config, dry bool) (*ini.File, error) { } defaultCfg := path.Join(configDir, "vale", ".vale.ini") - if FileExists(defaultCfg) { + if FileExists(defaultCfg) && !cfg.Flags.IgnoreGlobal { err = uCfg.Append(defaultCfg) if err != nil { return nil, NewE100("default/ini", err) diff --git a/testdata/features/steps.rb b/testdata/features/steps.rb index 8e68c734..2380d9e7 100755 --- a/testdata/features/steps.rb +++ b/testdata/features/steps.rb @@ -4,7 +4,7 @@ if OS.windows? exe += '.exe' end -cmd = (exe + ' --output=line --sort --normalize --relative') +cmd = (exe + ' --output=line --sort --normalize --relative --no-global') Given(/^on Unix$/) do pending unless OS.posix?