From ebadb7a6793aa01d984a702c3253232a979e3eb5 Mon Sep 17 00:00:00 2001 From: Denis Isaev Date: Sun, 17 Feb 2019 23:26:44 +0300 Subject: [PATCH] Fix #384: support ignore-words option for misspell --- .golangci.example.yml | 2 ++ README.md | 2 ++ pkg/config/config.go | 3 ++- pkg/golinters/misspell.go | 7 ++++++- test/testdata/configs/misspell.yml | 4 ++++ test/testdata/misspell.go | 3 +++ 6 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/testdata/configs/misspell.yml diff --git a/.golangci.example.yml b/.golangci.example.yml index 8722d3f8..0c133bde 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -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 diff --git a/README.md b/README.md index 7f791155..43ef503e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pkg/config/config.go b/pkg/config/config.go index 66a9a996..0b2dcdeb 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -158,7 +158,8 @@ type LintersSettings struct { IncludeGoRoot bool `mapstructure:"include-go-root"` } Misspell struct { - Locale string + Locale string + IgnoreWords []string `mapstructure:"ignore-words"` } Unused struct { CheckExported bool `mapstructure:"check-exported"` diff --git a/pkg/golinters/misspell.go b/pkg/golinters/misspell.go index 90aab384..3936966d 100644 --- a/pkg/golinters/misspell.go +++ b/pkg/golinters/misspell.go @@ -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 diff --git a/test/testdata/configs/misspell.yml b/test/testdata/configs/misspell.yml new file mode 100644 index 00000000..ccb7772c --- /dev/null +++ b/test/testdata/configs/misspell.yml @@ -0,0 +1,4 @@ +linters-settings: + misspell: + ignore-words: + - langauge diff --git a/test/testdata/misspell.go b/test/testdata/misspell.go index 795713cf..83afb5bb 100644 --- a/test/testdata/misspell.go +++ b/test/testdata/misspell.go @@ -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