Skip to content

Commit 992fddb

Browse files
committed
refactor: restrict spell check to word bounded tokens
1 parent 7edac53 commit 992fddb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

internal/check/spelling.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ func addExceptions(s *Spelling, generic baseCheck, cfg *core.Config) error { //n
7272
}
7373

7474
for _, term := range cfg.AcceptedTokens {
75+
// NOTE: This is used to ensure that we are excluding whole words
76+
// rather than substrings.
77+
//
78+
// The assumption is that, for spell checking, we don't want to
79+
// flag words that are part of a larger word.
80+
if !strings.HasPrefix(term, "\b") && !strings.HasSuffix(term, "\b") {
81+
term = `\b` + term + `\b`
82+
}
7583
s.Exceptions = append(s.Exceptions, term)
7684
s.exceptRe = regexp2.MustCompileStd(
7785
ignoreCase + strings.Join(s.Exceptions, "|"))

testdata/features/fragments.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Feature: Fragments
55
"""
66
test.cc:6:14:Vale.Spelling:Did you really mean 'objectmodel'?
77
test.cc:14:17:Vale.Repetition:'the' is repeated!
8+
test.cc:20:5:Vale.Spelling:Did you really mean 'QObjects'?
89
test.cc:47:12:Vale.Repetition:'the' is repeated!
910
test.go:2:14:Vale.Spelling:Did you really mean 'implments'?
1011
test.go:10:4:Vale.Spelling:Did you really mean 'Println'?
@@ -13,6 +14,7 @@ Feature: Fragments
1314
test.js:28:4:Vale.Spelling:Did you really mean 'getCases'?
1415
test.py:3:13:Vale.Spelling:Did you really mean 'parap'?
1516
test.py:13:35:Vale.Spelling:Did you really mean 'vaiable'?
17+
test.py:13:58:Vale.Spelling:Did you really mean 'docstrings'?
1618
test.py:18:29:Vale.Spelling:Did you really mean 'docmentation'?
1719
test.py:20:20:Vale.Spelling:Did you really mean 'ducmenation'?
1820
test.py:24:13:Vale.Spelling:Did you really mean 'parapp'?
@@ -41,7 +43,11 @@ Feature: Fragments
4143
test2.py:216:38:Vale.Spelling:Did you really mean 'pragma'?
4244
test2.py:219:35:Vale.Spelling:Did you really mean 'noqa'?
4345
test2.py:246:39:Vale.Spelling:Did you really mean 'vaiable'?
46+
test2.py:246:62:Vale.Spelling:Did you really mean 'docstrings'?
4447
test2.py:252:36:Vale.Spelling:Did you really mean 'vaiable'?
4548
test2.rs:47:42:Vale.Spelling:Did you really mean 'vrsion'?
49+
test2.rs:154:5:Vale.Spelling:Did you really mean 'RGArg'?
50+
test2.rs:165:26:Vale.Spelling:Did you really mean 'argumet'?
51+
test2.rs:409:38:Vale.Spelling:Did you really mean 'RGArg'?
4652
test2.rs:2860:34:Vale.Spelling:Did you really mean 'conlicts'?
4753
"""

0 commit comments

Comments
 (0)