Skip to content

Commit

Permalink
chore: update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Sep 26, 2024
1 parent 9ca3219 commit a5053db
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
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
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
9 changes: 5 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,7 @@ 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
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

0 comments on commit a5053db

Please sign in to comment.