Fix #384: support ignore-words option for misspell

This commit is contained in:
Denis Isaev 2019-02-17 23:26:44 +03:00 committed by Isaev Denis
parent 193a751f80
commit ebadb7a679
6 changed files with 19 additions and 2 deletions

View File

@ -115,6 +115,8 @@ linters-settings:
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: US
ignore-words:
- someword
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option

View File

@ -645,6 +645,8 @@ linters-settings:
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: US
ignore-words:
- someword
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option

View File

@ -159,6 +159,7 @@ type LintersSettings struct {
}
Misspell struct {
Locale string
IgnoreWords []string `mapstructure:"ignore-words"`
}
Unused struct {
CheckExported bool `mapstructure:"check-exported"`

View File

@ -29,7 +29,8 @@ func (lint Misspell) Run(ctx context.Context, lintCtx *linter.Context) ([]result
}
// Figure out regional variations
locale := lintCtx.Settings().Misspell.Locale
settings := lintCtx.Settings().Misspell
locale := settings.Locale
switch strings.ToUpper(locale) {
case "":
// nothing
@ -41,6 +42,10 @@ func (lint Misspell) Run(ctx context.Context, lintCtx *linter.Context) ([]result
return nil, fmt.Errorf("unknown locale: %q", locale)
}
if len(settings.IgnoreWords) != 0 {
r.RemoveRule(settings.IgnoreWords)
}
r.Compile()
var res []result.Issue

4
test/testdata/configs/misspell.yml vendored Normal file
View File

@ -0,0 +1,4 @@
linters-settings:
misspell:
ignore-words:
- langauge

View File

@ -1,6 +1,9 @@
//args: -Emisspell
//config_path: testdata/configs/misspell.yml
package testdata
func Misspell() {
// comment with incorrect spelling: occured // ERROR "`occured` is a misspelling of `occurred`"
}
// the word langauge should be ignored here: it's set in config