Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump github.com/alecthomas/go-check-sumtype from 0.1.4 to 0.2.0 #5038

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ linters-settings:
# Default: false
forbid-spec-pollution: true

gochecksumtype:
# Presence of `default` case in switch statements satisfies exhaustiveness, if all members are not listed.
# Default: true
default-signifies-exhaustive: false

gocognit:
# Minimal code complexity to report.
# Default: 30 (but we recommend 10-20)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0
github.com/OpenPeeDeeP/depguard/v2 v2.2.0
github.com/alecthomas/go-check-sumtype v0.1.4
github.com/alecthomas/go-check-sumtype v0.2.0
github.com/alexkohler/nakedret/v2 v2.0.4
github.com/alexkohler/prealloc v1.0.0
github.com/alingse/asasalint v0.0.11
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,17 @@
}
}
},
"gochecksumtype": {
"type": "object",
"additionalProperties": false,
"properties": {
"default-signifies-exhaustive": {
"description": "Presence of `default` case in switch statements satisfies exhaustiveness, if all members are not listed.",
"type": "boolean",
"default": true
}
}
},
"gocognit": {
"type": "object",
"additionalProperties": false,
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ var defaultLintersSettings = LintersSettings{
Sections: []string{"standard", "default"},
SkipGenerated: true,
},
GoChecksumType: GoChecksumTypeSettings{
DefaultSignifiesExhaustive: true,
},
Gocognit: GocognitSettings{
MinComplexity: 30,
},
Expand Down Expand Up @@ -216,6 +219,7 @@ type LintersSettings struct {
Gci GciSettings
GinkgoLinter GinkgoLinterSettings
Gocognit GocognitSettings
GoChecksumType GoChecksumTypeSettings
Goconst GoConstSettings
Gocritic GoCriticSettings
Gocyclo GoCycloSettings
Expand Down Expand Up @@ -485,6 +489,10 @@ type GinkgoLinterSettings struct {
ForbidSpecPollution bool `mapstructure:"forbid-spec-pollution"`
}

type GoChecksumTypeSettings struct {
DefaultSignifiesExhaustive bool `mapstructure:"default-signifies-exhaustive"`
}

type GocognitSettings struct {
MinComplexity int `mapstructure:"min-complexity"`
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/exhaustruct/testdata/exhaustruct_custom.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//golangcitest:args -Eexhaustruct
//golangcitest:config_path testdata/exhaustruct.yml
//golangcitest:config_path testdata/exhaustruct_custom.yml
package testdata

import "time"
Expand Down
10 changes: 6 additions & 4 deletions pkg/golinters/gochecksumtype/gochecksumtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/packages"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
)

const linterName = "gochecksumtype"

func New() *goanalysis.Linter {
func New(settings *config.GoChecksumTypeSettings) *goanalysis.Linter {
var mu sync.Mutex
var resIssues []goanalysis.Issue

analyzer := &analysis.Analyzer{
Name: linterName,
Doc: goanalysis.TheOnlyanalyzerDoc,
Run: func(pass *analysis.Pass) (any, error) {
issues, err := runGoCheckSumType(pass)
issues, err := runGoCheckSumType(pass, settings)
if err != nil {
return nil, err
}
Expand All @@ -50,7 +51,7 @@ func New() *goanalysis.Linter {
}).WithLoadMode(goanalysis.LoadModeTypesInfo)
}

func runGoCheckSumType(pass *analysis.Pass) ([]goanalysis.Issue, error) {
func runGoCheckSumType(pass *analysis.Pass, settings *config.GoChecksumTypeSettings) ([]goanalysis.Issue, error) {
var resIssues []goanalysis.Issue

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

var unknownError error
errors := gochecksumtype.Run([]*packages.Package{pkg})
errors := gochecksumtype.Run([]*packages.Package{pkg},
gochecksumtype.Config{DefaultSignifiesExhaustive: settings.DefaultSignifiesExhaustive})
for _, err := range errors {
err, ok := err.(gochecksumtype.Error)
if !ok {
Expand Down
6 changes: 6 additions & 0 deletions pkg/golinters/gochecksumtype/testdata/gochecksumtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func sumTypeTest() {
panic("??")
}

switch sum.(type) {
case *One:
default:
log.Println("legit catch all goes here")
}

log.Println("??")

switch sum.(type) {
Expand Down
45 changes: 45 additions & 0 deletions pkg/golinters/gochecksumtype/testdata/gochecksumtype_custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//golangcitest:args -Egochecksumtype
//golangcitest:config_path testdata/gochecksumtype_custom.yml
package testdata

import (
"log"
)

//sumtype:decl
type SumType interface{ isSumType() }

//sumtype:decl
type One struct{} // want "type 'One' is not an interface"

func (One) isSumType() {}

type Two struct{}

func (Two) isSumType() {}

func sumTypeTest() {
var sum SumType = One{}
switch sum.(type) { // want "exhaustiveness check failed for sum type.*SumType.*missing cases for Two"
case One:
}

switch sum.(type) { // want "exhaustiveness check failed for sum type.*SumType.*missing cases for Two"
case One:
default:
panic("??")
}

switch sum.(type) { // want "exhaustiveness check failed for sum type.*SumType.*missing cases for Two"
case *One:
default:
log.Println("legit catch all goes here")
}

log.Println("??")

switch sum.(type) {
case One:
case Two:
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters-settings:
gochecksumtype:
default-signifies-exhaustive: false
2 changes: 1 addition & 1 deletion pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithSince("v1.12.0").
WithPresets(linter.PresetStyle),

linter.NewConfig(gochecksumtype.New()).
linter.NewConfig(gochecksumtype.New(&cfg.LintersSettings.GoChecksumType)).
WithSince("v1.55.0").
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
Expand Down
Loading