Skip to content

Commit ebadb7a

Browse files
committed
Fix #384: support ignore-words option for misspell
1 parent 193a751 commit ebadb7a

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

.golangci.example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ linters-settings:
115115
# Default is to use a neutral variety of English.
116116
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
117117
locale: US
118+
ignore-words:
119+
- someword
118120
lll:
119121
# max line length, lines longer will be reported. Default is 120.
120122
# '\t' is counted as 1 character by default, and can be changed with the tab-width option

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ linters-settings:
645645
# Default is to use a neutral variety of English.
646646
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
647647
locale: US
648+
ignore-words:
649+
- someword
648650
lll:
649651
# max line length, lines longer will be reported. Default is 120.
650652
# '\t' is counted as 1 character by default, and can be changed with the tab-width option

pkg/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ type LintersSettings struct {
158158
IncludeGoRoot bool `mapstructure:"include-go-root"`
159159
}
160160
Misspell struct {
161-
Locale string
161+
Locale string
162+
IgnoreWords []string `mapstructure:"ignore-words"`
162163
}
163164
Unused struct {
164165
CheckExported bool `mapstructure:"check-exported"`

pkg/golinters/misspell.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func (lint Misspell) Run(ctx context.Context, lintCtx *linter.Context) ([]result
2929
}
3030

3131
// Figure out regional variations
32-
locale := lintCtx.Settings().Misspell.Locale
32+
settings := lintCtx.Settings().Misspell
33+
locale := settings.Locale
3334
switch strings.ToUpper(locale) {
3435
case "":
3536
// nothing
@@ -41,6 +42,10 @@ func (lint Misspell) Run(ctx context.Context, lintCtx *linter.Context) ([]result
4142
return nil, fmt.Errorf("unknown locale: %q", locale)
4243
}
4344

45+
if len(settings.IgnoreWords) != 0 {
46+
r.RemoveRule(settings.IgnoreWords)
47+
}
48+
4449
r.Compile()
4550

4651
var res []result.Issue

test/testdata/configs/misspell.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
misspell:
3+
ignore-words:
4+
- langauge

test/testdata/misspell.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//args: -Emisspell
2+
//config_path: testdata/configs/misspell.yml
23
package testdata
34

45
func Misspell() {
56
// comment with incorrect spelling: occured // ERROR "`occured` is a misspelling of `occurred`"
67
}
8+
9+
// the word langauge should be ignored here: it's set in config

0 commit comments

Comments
 (0)