diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 4fc6e5f7ecf2..29a3cc755796 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -1873,6 +1873,11 @@ linters: # Default: false skip-single-param: true + ineffassign: + # Check escaping variables of type error, may cause false positives. + # Default: false + check-escaping-errors: true + interfacebloat: # The maximum number of methods allowed for an interface. # Default: 10 diff --git a/go.mod b/go.mod index bff63c082247..4a65337ba115 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,7 @@ require ( github.com/golangci/revgrep v0.8.0 github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e - github.com/gordonklaus/ineffassign v0.1.0 + github.com/gordonklaus/ineffassign v0.2.0 github.com/gostaticanalysis/forcetypeassert v0.2.0 github.com/gostaticanalysis/nilerr v0.1.1 github.com/hashicorp/go-version v1.7.0 diff --git a/go.sum b/go.sum index 91fcc37ad71e..88fae7c32578 100644 --- a/go.sum +++ b/go.sum @@ -306,8 +306,8 @@ github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a/go.mod h1:5hDyRhoBCxV github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gordonklaus/ineffassign v0.1.0 h1:y2Gd/9I7MdY1oEIt+n+rowjBNDcLQq3RsH5hwJd0f9s= -github.com/gordonklaus/ineffassign v0.1.0/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it82ghYcEXIAk+QT0= +github.com/gordonklaus/ineffassign v0.2.0 h1:Uths4KnmwxNJNzq87fwQQDDnbNb7De00VOk9Nu0TySs= +github.com/gordonklaus/ineffassign v0.2.0/go.mod h1:TIpymnagPSexySzs7F9FnO1XFTy8IT3a59vmZp5Y9Lw= github.com/gostaticanalysis/analysisutil v0.7.1 h1:ZMCjoue3DtDWQ5WyU16YbjbQEQ3VuzwxALrpYd+HeKk= github.com/gostaticanalysis/analysisutil v0.7.1/go.mod h1:v21E3hY37WKMGSnbsw2S/ojApNWb6C1//mXO48CXbVc= github.com/gostaticanalysis/comment v1.4.1/go.mod h1:ih6ZxzTHLdadaiSnF5WY3dxUoXfXAlTaRzuaNDlSado= @@ -887,7 +887,6 @@ golang.org/x/tools v0.0.0-20201023174141-c8cfbd0f21e6/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.1-0.20210205202024-ef80cdb6ec6d/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU= golang.org/x/tools v0.1.1-0.20210302220138-2ac05c832e1a/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 475ab5bcd920..adc836282896 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -2410,6 +2410,17 @@ } } }, + "ineffassignSettings": { + "type": "object", + "additionalProperties": false, + "properties": { + "check-escaping-errors": { + "description": "Check escaping variables of type error, may cause false positives.", + "type": "boolean", + "default": false + } + } + }, "ireturnSettings": { "type": "object", "additionalProperties": false, @@ -4567,6 +4578,9 @@ "inamedparam": { "$ref": "#/definitions/settings/definitions/inamedparamSettings" }, + "ineffassign": { + "$ref": "#/definitions/settings/definitions/ineffassignSettings" + }, "ireturn": { "$ref": "#/definitions/settings/definitions/ireturnSettings" }, diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index d0833f15b41b..567416d977de 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -254,6 +254,7 @@ type LintersSettings struct { Iface IfaceSettings `mapstructure:"iface"` ImportAs ImportAsSettings `mapstructure:"importas"` Inamedparam INamedParamSettings `mapstructure:"inamedparam"` + Ineffassign IneffassignSettings `mapstructure:"ineffassign"` InterfaceBloat InterfaceBloatSettings `mapstructure:"interfacebloat"` Ireturn IreturnSettings `mapstructure:"ireturn"` Lll LllSettings `mapstructure:"lll"` @@ -644,6 +645,10 @@ type INamedParamSettings struct { SkipSingleParam bool `mapstructure:"skip-single-param"` } +type IneffassignSettings struct { + CheckEscapingErrors bool `mapstructure:"check-escaping-errors"` +} + type InterfaceBloatSettings struct { Max int `mapstructure:"max"` } diff --git a/pkg/golinters/ineffassign/ineffassign.go b/pkg/golinters/ineffassign/ineffassign.go index 2c0119f1032f..1df737cbf5ab 100644 --- a/pkg/golinters/ineffassign/ineffassign.go +++ b/pkg/golinters/ineffassign/ineffassign.go @@ -3,12 +3,21 @@ package ineffassign import ( "github.com/gordonklaus/ineffassign/pkg/ineffassign" + "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -func New() *goanalysis.Linter { +func New(settings *config.IneffassignSettings) *goanalysis.Linter { + var cfg map[string]any + + if settings != nil { + cfg = map[string]any{ + "check-escaping-errors": settings.CheckEscapingErrors, + } + } + return goanalysis. NewLinterFromAnalyzer(ineffassign.Analyzer). - WithDesc("Detects when assignments to existing variables are not used"). + WithConfig(cfg). WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index cc6f502a7860..9c7b2500a4e1 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -424,7 +424,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithSince("v1.55.0"). WithURL("https://github.com/macabu/inamedparam"), - linter.NewConfig(ineffassign.New()). + linter.NewConfig(ineffassign.New(&cfg.Linters.Settings.Ineffassign)). WithGroups(config.GroupStandard). WithSince("v1.0.0"). WithURL("https://github.com/gordonklaus/ineffassign"), diff --git a/scripts/website/expand_templates/configuration.go b/scripts/website/expand_templates/configuration.go index f7571023441d..25bd10bf53b4 100644 --- a/scripts/website/expand_templates/configuration.go +++ b/scripts/website/expand_templates/configuration.go @@ -3,6 +3,7 @@ package main import ( "bytes" "fmt" + "log" "os" "path/filepath" "reflect" @@ -248,7 +249,7 @@ func (e *ExampleSnippetsExtractor) getSettingSections(node, nextNode *yaml.Node) settings, ok := allNodes[lc.Name] if !ok { if hasSettings(lc.Name) { - return nil, fmt.Errorf("can't find %s settings in .golangci.reference.yml", lc.Name) + log.Printf("can't find %s settings in .golangci.reference.yml", lc.Name) } continue