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