Skip to content

Commit

Permalink
refactor: error on misplaced core-level settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Jun 27, 2024
1 parent 3b6c8db commit f7cbb57
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/core/ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 _, option := coreOpts[k]; option {
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)
Expand All @@ -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 _, option := coreOpts[k]; option {
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
}
Expand Down

0 comments on commit f7cbb57

Please sign in to comment.