diff options
Diffstat (limited to 'vendor/github.com/Abirdcfly')
| -rw-r--r-- | vendor/github.com/Abirdcfly/dupword/README.md | 6 | ||||
| -rw-r--r-- | vendor/github.com/Abirdcfly/dupword/dupword.go | 33 |
2 files changed, 35 insertions, 4 deletions
diff --git a/vendor/github.com/Abirdcfly/dupword/README.md b/vendor/github.com/Abirdcfly/dupword/README.md index 6917acae2..e6c5b919f 100644 --- a/vendor/github.com/Abirdcfly/dupword/README.md +++ b/vendor/github.com/Abirdcfly/dupword/README.md @@ -109,10 +109,12 @@ Flags: apply all suggested fixes -flags print analyzer flags in JSON + -ignore value + ignore words -json emit JSON output -keyword value - key words for detecting duplicate words + keywords for detecting duplicate words -memprofile string write memory profile to this file -source @@ -128,7 +130,7 @@ Flags: ### 5. my advice -use `--keyword=the,and,a` and `-fix` together. I personally think that specifying only common repeated prepositions can effectively avoid false positives. +use `--keyword=the,and,a` and `-fix` together. I think that specifying only commonly repeated prepositions can effectively avoid false positives. see [dupword#4](https://github.com/Abirdcfly/dupword/issues/4) for real code example. diff --git a/vendor/github.com/Abirdcfly/dupword/dupword.go b/vendor/github.com/Abirdcfly/dupword/dupword.go index 508caca52..c291eab52 100644 --- a/vendor/github.com/Abirdcfly/dupword/dupword.go +++ b/vendor/github.com/Abirdcfly/dupword/dupword.go @@ -52,6 +52,7 @@ This analyzer checks miswritten duplicate words in comments or package doc or st var ( defaultWord = []string{} // defaultWord = []string{"the", "and", "a"} + ignoreWord = map[string]bool{} ) type analyzer struct { @@ -70,7 +71,31 @@ func (a *analyzer) Set(w string) error { return nil } +type ignore struct { +} + +func (a *ignore) String() string { + t := make([]string,0, len(ignoreWord)) + for k := range ignoreWord { + t = append(t, k) + } + return strings.Join(t, ",") +} + +func (a *ignore) Set(w string) error { + for _, k := range strings.Split(w, ","){ + ignoreWord[k] = true + } + return nil +} + +// for test only +func ClearIgnoreWord() { + ignoreWord = map[string]bool{} +} + func NewAnalyzer() *analysis.Analyzer { + ignore := &ignore{} analyzer := &analyzer{KeyWord: defaultWord} a := &analysis.Analyzer{ Name: Name, @@ -80,7 +105,8 @@ func NewAnalyzer() *analysis.Analyzer { RunDespiteErrors: true, } a.Flags.Init(Name, flag.ExitOnError) - a.Flags.Var(analyzer, "keyword", "key words for detecting duplicate words") + a.Flags.Var(analyzer, "keyword", "keywords for detecting duplicate words") + a.Flags.Var(ignore, "ignore", "ignore words") a.Flags.Var(version{}, "V", "print version and exit") return a } @@ -176,7 +202,7 @@ func (a *analyzer) fixDuplicateWordInString(pass *analysis.Pass, lit *ast.BasicL } } -// CheckOneKey use to check there is defined duplicate word in a string. +// CheckOneKey use to check there is a defined duplicate word in a string. // raw is checked line. key is the keyword to check. empty means just check duplicate word. func CheckOneKey(raw, key string) (new string, findWord string, find bool) { if key == "" { @@ -298,5 +324,8 @@ func ExcludeWords(word string) (exclude bool) { if unicode.IsSymbol(firstRune) { return true } + if _, exist := ignoreWord[word]; exist { + return true + } return false } |
