Skip to content

Commit 0798941

Browse files
build(deps): bump github.com/alecthomas/go-check-sumtype from 0.1.4 to 0.2.0 (#5038)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent aa669e2 commit 0798941

12 files changed

+89
-9
lines changed

.golangci.next.reference.yml

+5
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ linters-settings:
516516
# Default: false
517517
forbid-spec-pollution: true
518518

519+
gochecksumtype:
520+
# Presence of `default` case in switch statements satisfies exhaustiveness, if all members are not listed.
521+
# Default: true
522+
default-signifies-exhaustive: false
523+
519524
gocognit:
520525
# Minimal code complexity to report.
521526
# Default: 30 (but we recommend 10-20)

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
1616
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0
1717
github.com/OpenPeeDeeP/depguard/v2 v2.2.0
18-
github.com/alecthomas/go-check-sumtype v0.1.4
18+
github.com/alecthomas/go-check-sumtype v0.2.0
1919
github.com/alexkohler/nakedret/v2 v2.0.4
2020
github.com/alexkohler/prealloc v1.0.0
2121
github.com/alingse/asasalint v0.0.11

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonschema/golangci.next.jsonschema.json

+11
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,17 @@
11741174
}
11751175
}
11761176
},
1177+
"gochecksumtype": {
1178+
"type": "object",
1179+
"additionalProperties": false,
1180+
"properties": {
1181+
"default-signifies-exhaustive": {
1182+
"description": "Presence of `default` case in switch statements satisfies exhaustiveness, if all members are not listed.",
1183+
"type": "boolean",
1184+
"default": true
1185+
}
1186+
}
1187+
},
11771188
"gocognit": {
11781189
"type": "object",
11791190
"additionalProperties": false,

pkg/config/linters_settings.go

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ var defaultLintersSettings = LintersSettings{
4747
Sections: []string{"standard", "default"},
4848
SkipGenerated: true,
4949
},
50+
GoChecksumType: GoChecksumTypeSettings{
51+
DefaultSignifiesExhaustive: true,
52+
},
5053
Gocognit: GocognitSettings{
5154
MinComplexity: 30,
5255
},
@@ -216,6 +219,7 @@ type LintersSettings struct {
216219
Gci GciSettings
217220
GinkgoLinter GinkgoLinterSettings
218221
Gocognit GocognitSettings
222+
GoChecksumType GoChecksumTypeSettings
219223
Goconst GoConstSettings
220224
Gocritic GoCriticSettings
221225
Gocyclo GoCycloSettings
@@ -485,6 +489,10 @@ type GinkgoLinterSettings struct {
485489
ForbidSpecPollution bool `mapstructure:"forbid-spec-pollution"`
486490
}
487491

492+
type GoChecksumTypeSettings struct {
493+
DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"`
494+
}
495+
488496
type GocognitSettings struct {
489497
MinComplexity int `mapstructure:"min-complexity"`
490498
}

pkg/golinters/exhaustruct/testdata/exhaustruct_custom.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Eexhaustruct
2-
//golangcitest:config_path testdata/exhaustruct.yml
2+
//golangcitest:config_path testdata/exhaustruct_custom.yml
33
package testdata
44

55
import "time"

pkg/golinters/gochecksumtype/gochecksumtype.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ import (
88
"golang.org/x/tools/go/analysis"
99
"golang.org/x/tools/go/packages"
1010

11+
"github.com/golangci/golangci-lint/pkg/config"
1112
"github.com/golangci/golangci-lint/pkg/goanalysis"
1213
"github.com/golangci/golangci-lint/pkg/lint/linter"
1314
"github.com/golangci/golangci-lint/pkg/result"
1415
)
1516

1617
const linterName = "gochecksumtype"
1718

18-
func New() *goanalysis.Linter {
19+
func New(settings *config.GoChecksumTypeSettings) *goanalysis.Linter {
1920
var mu sync.Mutex
2021
var resIssues []goanalysis.Issue
2122

2223
analyzer := &analysis.Analyzer{
2324
Name: linterName,
2425
Doc: goanalysis.TheOnlyanalyzerDoc,
2526
Run: func(pass *analysis.Pass) (any, error) {
26-
issues, err := runGoCheckSumType(pass)
27+
issues, err := runGoCheckSumType(pass, settings)
2728
if err != nil {
2829
return nil, err
2930
}
@@ -50,7 +51,7 @@ func New() *goanalysis.Linter {
5051
}).WithLoadMode(goanalysis.LoadModeTypesInfo)
5152
}
5253

53-
func runGoCheckSumType(pass *analysis.Pass) ([]goanalysis.Issue, error) {
54+
func runGoCheckSumType(pass *analysis.Pass, settings *config.GoChecksumTypeSettings) ([]goanalysis.Issue, error) {
5455
var resIssues []goanalysis.Issue
5556

5657
pkg := &packages.Package{
@@ -61,7 +62,8 @@ func runGoCheckSumType(pass *analysis.Pass) ([]goanalysis.Issue, error) {
6162
}
6263

6364
var unknownError error
64-
errors := gochecksumtype.Run([]*packages.Package{pkg})
65+
errors := gochecksumtype.Run([]*packages.Package{pkg},
66+
gochecksumtype.Config{DefaultSignifiesExhaustive: settings.DefaultSignifiesExhaustive})
6567
for _, err := range errors {
6668
err, ok := err.(gochecksumtype.Error)
6769
if !ok {

pkg/golinters/gochecksumtype/testdata/gochecksumtype.go

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ func sumTypeTest() {
2929
panic("??")
3030
}
3131

32+
switch sum.(type) {
33+
case *One:
34+
default:
35+
log.Println("legit catch all goes here")
36+
}
37+
3238
log.Println("??")
3339

3440
switch sum.(type) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//golangcitest:args -Egochecksumtype
2+
//golangcitest:config_path testdata/gochecksumtype_custom.yml
3+
package testdata
4+
5+
import (
6+
"log"
7+
)
8+
9+
//sumtype:decl
10+
type SumType interface{ isSumType() }
11+
12+
//sumtype:decl
13+
type One struct{} // want "type 'One' is not an interface"
14+
15+
func (One) isSumType() {}
16+
17+
type Two struct{}
18+
19+
func (Two) isSumType() {}
20+
21+
func sumTypeTest() {
22+
var sum SumType = One{}
23+
switch sum.(type) { // want "exhaustiveness check failed for sum type.*SumType.*missing cases for Two"
24+
case One:
25+
}
26+
27+
switch sum.(type) { // want "exhaustiveness check failed for sum type.*SumType.*missing cases for Two"
28+
case One:
29+
default:
30+
panic("??")
31+
}
32+
33+
switch sum.(type) { // want "exhaustiveness check failed for sum type.*SumType.*missing cases for Two"
34+
case *One:
35+
default:
36+
log.Println("legit catch all goes here")
37+
}
38+
39+
log.Println("??")
40+
41+
switch sum.(type) {
42+
case One:
43+
case Two:
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
gochecksumtype:
3+
default-signifies-exhaustive: false

pkg/lint/lintersdb/builder_linter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
335335
WithSince("v1.12.0").
336336
WithPresets(linter.PresetStyle),
337337

338-
linter.NewConfig(gochecksumtype.New()).
338+
linter.NewConfig(gochecksumtype.New(&cfg.LintersSettings.GoChecksumType)).
339339
WithSince("v1.55.0").
340340
WithPresets(linter.PresetBugs).
341341
WithLoadForGoAnalysis().

0 commit comments

Comments
 (0)