Fix #384: support ignore-words option for misspell
This commit is contained in:
parent
193a751f80
commit
ebadb7a679
@ -115,6 +115,8 @@ linters-settings:
|
|||||||
# Default is to use a neutral variety of English.
|
# Default is to use a neutral variety of English.
|
||||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||||
locale: US
|
locale: US
|
||||||
|
ignore-words:
|
||||||
|
- someword
|
||||||
lll:
|
lll:
|
||||||
# max line length, lines longer will be reported. Default is 120.
|
# 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
|
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||||
|
@ -645,6 +645,8 @@ linters-settings:
|
|||||||
# Default is to use a neutral variety of English.
|
# Default is to use a neutral variety of English.
|
||||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||||
locale: US
|
locale: US
|
||||||
|
ignore-words:
|
||||||
|
- someword
|
||||||
lll:
|
lll:
|
||||||
# max line length, lines longer will be reported. Default is 120.
|
# 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
|
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||||
|
@ -159,6 +159,7 @@ type LintersSettings struct {
|
|||||||
}
|
}
|
||||||
Misspell struct {
|
Misspell struct {
|
||||||
Locale string
|
Locale string
|
||||||
|
IgnoreWords []string `mapstructure:"ignore-words"`
|
||||||
}
|
}
|
||||||
Unused struct {
|
Unused struct {
|
||||||
CheckExported bool `mapstructure:"check-exported"`
|
CheckExported bool `mapstructure:"check-exported"`
|
||||||
|
@ -29,7 +29,8 @@ func (lint Misspell) Run(ctx context.Context, lintCtx *linter.Context) ([]result
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Figure out regional variations
|
// Figure out regional variations
|
||||||
locale := lintCtx.Settings().Misspell.Locale
|
settings := lintCtx.Settings().Misspell
|
||||||
|
locale := settings.Locale
|
||||||
switch strings.ToUpper(locale) {
|
switch strings.ToUpper(locale) {
|
||||||
case "":
|
case "":
|
||||||
// nothing
|
// nothing
|
||||||
@ -41,6 +42,10 @@ func (lint Misspell) Run(ctx context.Context, lintCtx *linter.Context) ([]result
|
|||||||
return nil, fmt.Errorf("unknown locale: %q", locale)
|
return nil, fmt.Errorf("unknown locale: %q", locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(settings.IgnoreWords) != 0 {
|
||||||
|
r.RemoveRule(settings.IgnoreWords)
|
||||||
|
}
|
||||||
|
|
||||||
r.Compile()
|
r.Compile()
|
||||||
|
|
||||||
var res []result.Issue
|
var res []result.Issue
|
||||||
|
4
test/testdata/configs/misspell.yml
vendored
Normal file
4
test/testdata/configs/misspell.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
linters-settings:
|
||||||
|
misspell:
|
||||||
|
ignore-words:
|
||||||
|
- langauge
|
3
test/testdata/misspell.go
vendored
3
test/testdata/misspell.go
vendored
@ -1,6 +1,9 @@
|
|||||||
//args: -Emisspell
|
//args: -Emisspell
|
||||||
|
//config_path: testdata/configs/misspell.yml
|
||||||
package testdata
|
package testdata
|
||||||
|
|
||||||
func Misspell() {
|
func Misspell() {
|
||||||
// comment with incorrect spelling: occured // ERROR "`occured` is a misspelling of `occurred`"
|
// comment with incorrect spelling: occured // ERROR "`occured` is a misspelling of `occurred`"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the word langauge should be ignored here: it's set in config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user