boolnames: make default whitelist include 'ok'

This commit is contained in:
2026-10-14 20:53:41 -07:00
parent 5da0c76be2
commit 94fdf5e5ae
15 changed files with 14 additions and 10 deletions

View File

@@ -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$

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -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"
)