Skip to content

Commit c8c3e78

Browse files
feat: boolset linter
Signed-off-by: Artur Melanchyk <[email protected]>
1 parent 30c7cf2 commit c8c3e78

File tree

8 files changed

+98
-0
lines changed

8 files changed

+98
-0
lines changed

.golangci.next.reference.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ linters:
2525
- asciicheck
2626
- bidichk
2727
- bodyclose
28+
- boolset
2829
- canonicalheader
2930
- containedctx
3031
- contextcheck
@@ -139,6 +140,7 @@ linters:
139140
- asciicheck
140141
- bidichk
141142
- bodyclose
143+
- boolset
142144
- canonicalheader
143145
- containedctx
144146
- contextcheck

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/alexkohler/prealloc v1.0.0
2424
github.com/alingse/asasalint v0.0.11
2525
github.com/alingse/nilnesserr v0.2.0
26+
github.com/arturmelanchyk/boolset v0.1.0
2627
github.com/ashanbrown/forbidigo/v2 v2.1.0
2728
github.com/ashanbrown/makezero/v2 v2.0.1
2829
github.com/bkielbasa/cyclop v1.2.3

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/boolset/boolset.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package boolset
2+
3+
import (
4+
"github.com/arturmelanchyk/boolset/boolset"
5+
6+
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
7+
)
8+
9+
func New() *goanalysis.Linter {
10+
return goanalysis.
11+
NewLinterFromAnalyzer(boolset.NewAnalyzer()).
12+
WithLoadMode(goanalysis.LoadModeTypesInfo)
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package boolset
2+
3+
import (
4+
"testing"
5+
6+
"github.com/golangci/golangci-lint/v2/test/testshared/integration"
7+
)
8+
9+
func TestFromTestdata(t *testing.T) {
10+
integration.RunTestdata(t)
11+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//golangcitest:args -Eboolset
2+
package testdata
3+
4+
import (
5+
"log"
6+
)
7+
8+
var allNames = []string{"a", "a", "b", "c", "c", "d"}
9+
10+
func findDuplicates() []string {
11+
var duplicates []string
12+
uniqueNames := make(map[string]bool) // want "map\\[string\\]bool only stores \"true\" values; consider map\\[string\\]struct\\{\\}"
13+
for _, name := range allNames {
14+
if _, ok := uniqueNames[name]; ok {
15+
duplicates = append(duplicates, name)
16+
log.Println("Duplicate found: ", name)
17+
} else {
18+
uniqueNames[name] = true
19+
}
20+
}
21+
22+
return duplicates
23+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//golangcitest:args -Eboolset
2+
package testdata
3+
4+
/*
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
8+
void myprint(char* s) {
9+
printf("%d\n", s);
10+
}
11+
*/
12+
import "C"
13+
14+
import (
15+
"log"
16+
"unsafe"
17+
)
18+
19+
func _() {
20+
cs := C.CString("Hello from stdio\n")
21+
C.myprint(cs)
22+
C.free(unsafe.Pointer(cs))
23+
}
24+
25+
var allNamesCgo = []string{"a", "a", "b", "c", "c", "d"}
26+
27+
func findDuplicatesCgo() []string {
28+
var duplicates []string
29+
uniqueNames := make(map[string]bool) // want "map\\[string\\]bool only stores \"true\" values; consider map\\[string\\]struct\\{\\}"
30+
for _, name := range allNamesCgo {
31+
if _, ok := uniqueNames[name]; ok {
32+
duplicates = append(duplicates, name)
33+
log.Println("Duplicate found: ", name)
34+
} else {
35+
uniqueNames[name] = true
36+
}
37+
}
38+
39+
return duplicates
40+
}

pkg/lint/lintersdb/builder_linter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/golangci/golangci-lint/v2/pkg/golinters/asciicheck"
99
"github.com/golangci/golangci-lint/v2/pkg/golinters/bidichk"
1010
"github.com/golangci/golangci-lint/v2/pkg/golinters/bodyclose"
11+
"github.com/golangci/golangci-lint/v2/pkg/golinters/boolset"
1112
"github.com/golangci/golangci-lint/v2/pkg/golinters/canonicalheader"
1213
"github.com/golangci/golangci-lint/v2/pkg/golinters/containedctx"
1314
"github.com/golangci/golangci-lint/v2/pkg/golinters/contextcheck"
@@ -165,6 +166,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
165166
WithLoadForGoAnalysis().
166167
WithURL("https://github.com/timakin/bodyclose"),
167168

169+
linter.NewConfig(boolset.New()).
170+
WithSince("v2.6.0").
171+
WithLoadForGoAnalysis().
172+
WithURL("https://github.com/arturmelanchyk/boolset"),
173+
168174
linter.NewConfig(canonicalheader.New()).
169175
WithSince("v1.58.0").
170176
WithLoadForGoAnalysis().

0 commit comments

Comments
 (0)