Skip to content

Commit a335cfa

Browse files
committed
refactor: Warn on unrecognized core options
Signed-off-by: Joseph Kato <joseph@jdkato.io>
1 parent 529d382 commit a335cfa

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

internal/core/error.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ func NewError(code, title, msg string) error {
8181
)
8282
}
8383

84+
// Warn reports something the user should know about but that doesn't stop the
85+
// run -- a key we don't recognize, say.
86+
//
87+
// It goes to stderr to stay clear of `--output=JSON` and the other formats a
88+
// caller parses, which are written to stdout.
89+
func Warn(msg string) {
90+
fmt.Fprintf(os.Stderr, "%s %s\n", pterm.BgYellow.Sprint("W101"), msg)
91+
}
92+
8493
// NewE100 creates a new, formatted "unexpected" error.
8594
//
8695
// Since E100 errors can occur anywhere, we include a "context" that makes it

internal/core/ini.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ var pathKeys = []string{
1717
"StylesPath",
1818
}
1919

20+
// nonOptKeys are core keys that something other than `coreOpts` reads.
21+
//
22+
// They belong at the top level, so they're not a mistake -- they just aren't
23+
// resolved here. See `GetPackages`.
24+
var nonOptKeys = []string{
25+
"Packages",
26+
}
27+
2028
// noChildSections disables the ini library's child-section feature.
2129
//
2230
// That feature reads a `.` in a section's name as nesting, so `[*.md]` is
@@ -375,6 +383,19 @@ func processConfig(uCfg *ini.File, cfg *Config, dry bool) (*ini.File, error) {
375383
} else if _, found = syntaxOpts[k]; found {
376384
msg := fmt.Sprintf("'%s' is a syntax-specific option", k)
377385
return nil, NewE201FromTarget(msg, k, cfg.RootINI)
386+
} else if !StringInSlice(k, nonOptKeys) {
387+
// Nothing reads a key we don't recognize here, so leaving it be
388+
// quietly means the user's config says something Vale never hears.
389+
//
390+
// The delimiters include `:`, which is what makes this worth
391+
// saying out loud: a URL left on a line of its own parses as the
392+
// key `https` with the rest of itself for a value, and the package
393+
// it was meant to name is never installed.
394+
//
395+
// It's a warning rather than an error because a config that has
396+
// carried a stale key for years still lints exactly as it did.
397+
Warn(fmt.Sprintf(
398+
"'%s' isn't a core option; Vale is ignoring it.", k))
378399
}
379400
}
380401

0 commit comments

Comments
 (0)