boolnames: make default whitelist include 'ok'
This commit is contained in:
@@ -37,9 +37,6 @@ linters:
|
||||
boolnames:
|
||||
type: module
|
||||
description: boolean variables and functions should use "is", "has", "was" etc
|
||||
settings:
|
||||
whitelist:
|
||||
- ok
|
||||
forbidigo:
|
||||
forbid:
|
||||
- pattern: ^sync\.Map$
|
||||
|
||||
@@ -13,11 +13,18 @@ import (
|
||||
"golang.org/x/tools/go/ast/inspector"
|
||||
)
|
||||
|
||||
var defaultBoolNamePrefixes = []string{"is", "has", "can", "was"}
|
||||
var (
|
||||
defaultBoolNamePrefixes = []string{"is", "has", "can", "was"}
|
||||
defaultBoolNameWhitelist = []string{"ok"}
|
||||
)
|
||||
|
||||
var Analyzer = NewAnalyzer(Settings{})
|
||||
|
||||
func NewAnalyzer(settings Settings) *analysis.Analyzer {
|
||||
if len(settings.Whitelist) == 0 {
|
||||
settings.Whitelist = defaultBoolNameWhitelist
|
||||
}
|
||||
|
||||
if len(settings.AllowedPrefixes) == 0 {
|
||||
settings.AllowedPrefixes = defaultBoolNamePrefixes
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/go/analysis/analysistest"
|
||||
|
||||
"git.offline-twitter.com/offline-labs/go-lint/boolnames"
|
||||
"git.offline-twitter.com/offline-labs/go-lint/pkg/boolnames"
|
||||
)
|
||||
|
||||
func TestAnalyzer(t *testing.T) {
|
||||
@@ -28,7 +28,7 @@ func ready() bool { return true } // want `boolean name "ready" must`
|
||||
func Find() (int, bool) { return 0, true }
|
||||
func FindPair() (bool, bool) { return true, false }
|
||||
|
||||
func consume(active bool, hasActive bool, predicate func() bool, canCheck func() bool) (ok bool) { // want `boolean name "consume" must` `boolean name "active" must` `boolean name "predicate" must` `boolean name "ok" must`
|
||||
func consume(active bool, hasActive bool, predicate func() bool, canCheck func() bool) (ok bool) { // want `boolean name "consume" must` `boolean name "active" must` `boolean name "predicate" must`
|
||||
ready := true // want `boolean name "ready" must`
|
||||
isReady := true
|
||||
|
||||
@@ -41,7 +41,7 @@ func consume(active bool, hasActive bool, predicate func() bool, canCheck func()
|
||||
checker := func() bool { return true } // want `boolean name "checker" must`
|
||||
hasChecker := func() bool { return true }
|
||||
|
||||
_ = func(active bool) (ok bool) { // want `boolean name "active" must` `boolean name "ok" must`
|
||||
_ = func(active bool) (ok bool) { // want `boolean name "active" must`
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/go/analysis/analysistest"
|
||||
|
||||
"git.offline-twitter.com/offline-labs/go-lint/ifinit"
|
||||
"git.offline-twitter.com/offline-labs/go-lint/pkg/ifinit"
|
||||
)
|
||||
|
||||
func TestAnalyzer(t *testing.T) {
|
||||
4
root.go
4
root.go
@@ -1,6 +1,6 @@
|
||||
package customlint
|
||||
|
||||
import (
|
||||
_ "git.offline-twitter.com/offline-labs/go-lint/boolnames"
|
||||
_ "git.offline-twitter.com/offline-labs/go-lint/ifinit"
|
||||
_ "git.offline-twitter.com/offline-labs/go-lint/pkg/boolnames"
|
||||
_ "git.offline-twitter.com/offline-labs/go-lint/pkg/ifinit"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user