From d3a8244b4e951e818b7cd6bbae081e14fc3edbab Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Wed, 26 Jun 2024 19:47:27 -0700 Subject: [PATCH] refactor: error on misplaced core-level settings --- internal/core/ini.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/core/ini.go b/internal/core/ini.go index 44eeb0cd..c1489a21 100644 --- a/internal/core/ini.go +++ b/internal/core/ini.go @@ -12,6 +12,8 @@ import ( "github.com/errata-ai/vale/v3/internal/glob" ) +var coreError = "'%s' is a core option; it should be defined above any syntax-specific options (`[...]`)." + func determinePath(configPath string, keyPath string) string { // expand tilde at this point as this is where user-provided paths are provided keyPath = normalizePath(keyPath) @@ -292,7 +294,9 @@ func processConfig(uCfg *ini.File, cfg *Config, dry bool) (*ini.File, error) { // Global settings for _, k := range global.KeyStrings() { - if f, found := globalOpts[k]; found { + if _, found := coreOpts[k]; found { + return nil, NewE201FromTarget(fmt.Sprintf(coreError, k), k, cfg.RootINI) + } else if f, found := globalOpts[k]; found { f(global, cfg) } else if _, found = syntaxOpts[k]; found { msg := fmt.Sprintf("'%s' is a syntax-specific option", k) @@ -317,7 +321,9 @@ func processConfig(uCfg *ini.File, cfg *Config, dry bool) (*ini.File, error) { syntaxMap := make(map[string]bool) for _, k := range uCfg.Section(sec).KeyStrings() { - if f, found := syntaxOpts[k]; found { + if _, found := coreOpts[k]; found { + return nil, NewE201FromTarget(fmt.Sprintf(coreError, k), k, cfg.RootINI) + } else if f, found := syntaxOpts[k]; found { if err = f(sec, uCfg.Section(sec), cfg); err != nil && !dry { return nil, err }