Skip to content

Commit

Permalink
refactor: restrict spell check to word bounded tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Jan 20, 2025
1 parent 7edac53 commit 992fddb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/check/spelling.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func addExceptions(s *Spelling, generic baseCheck, cfg *core.Config) error { //n
}

for _, term := range cfg.AcceptedTokens {
// NOTE: This is used to ensure that we are excluding whole words
// rather than substrings.
//
// The assumption is that, for spell checking, we don't want to
// flag words that are part of a larger word.
if !strings.HasPrefix(term, "\b") && !strings.HasSuffix(term, "\b") {
term = `\b` + term + `\b`
}
s.Exceptions = append(s.Exceptions, term)
s.exceptRe = regexp2.MustCompileStd(
ignoreCase + strings.Join(s.Exceptions, "|"))
Expand Down
6 changes: 6 additions & 0 deletions testdata/features/fragments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Feature: Fragments
"""
test.cc:6:14:Vale.Spelling:Did you really mean 'objectmodel'?
test.cc:14:17:Vale.Repetition:'the' is repeated!
test.cc:20:5:Vale.Spelling:Did you really mean 'QObjects'?
test.cc:47:12:Vale.Repetition:'the' is repeated!
test.go:2:14:Vale.Spelling:Did you really mean 'implments'?
test.go:10:4:Vale.Spelling:Did you really mean 'Println'?
Expand All @@ -13,6 +14,7 @@ Feature: Fragments
test.js:28:4:Vale.Spelling:Did you really mean 'getCases'?
test.py:3:13:Vale.Spelling:Did you really mean 'parap'?
test.py:13:35:Vale.Spelling:Did you really mean 'vaiable'?
test.py:13:58:Vale.Spelling:Did you really mean 'docstrings'?
test.py:18:29:Vale.Spelling:Did you really mean 'docmentation'?
test.py:20:20:Vale.Spelling:Did you really mean 'ducmenation'?
test.py:24:13:Vale.Spelling:Did you really mean 'parapp'?
Expand Down Expand Up @@ -41,7 +43,11 @@ Feature: Fragments
test2.py:216:38:Vale.Spelling:Did you really mean 'pragma'?
test2.py:219:35:Vale.Spelling:Did you really mean 'noqa'?
test2.py:246:39:Vale.Spelling:Did you really mean 'vaiable'?
test2.py:246:62:Vale.Spelling:Did you really mean 'docstrings'?
test2.py:252:36:Vale.Spelling:Did you really mean 'vaiable'?
test2.rs:47:42:Vale.Spelling:Did you really mean 'vrsion'?
test2.rs:154:5:Vale.Spelling:Did you really mean 'RGArg'?
test2.rs:165:26:Vale.Spelling:Did you really mean 'argumet'?
test2.rs:409:38:Vale.Spelling:Did you really mean 'RGArg'?
test2.rs:2860:34:Vale.Spelling:Did you really mean 'conlicts'?
"""

0 comments on commit 992fddb

Please sign in to comment.