From 3afda293cd25a0797e71c95a3c469db49713a408 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 14 May 2025 17:27:44 +0200 Subject: [PATCH] chore: remove dead code --- pkg/golinters/dupl/dupl.go | 2 +- pkg/golinters/errcheck/errcheck.go | 6 +++--- pkg/golinters/gochecknoinits/gochecknoinits.go | 2 +- pkg/golinters/gocognit/gocognit.go | 2 +- pkg/golinters/goconst/goconst.go | 6 +++--- pkg/golinters/gocyclo/gocyclo.go | 2 +- pkg/golinters/internal/util.go | 3 +-- pkg/golinters/prealloc/prealloc.go | 2 +- 8 files changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/golinters/dupl/dupl.go b/pkg/golinters/dupl/dupl.go index 654c795ff696..6d5323a8bad4 100644 --- a/pkg/golinters/dupl/dupl.go +++ b/pkg/golinters/dupl/dupl.go @@ -70,7 +70,7 @@ func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.I dupl := fmt.Sprintf("%s:%d-%d", toFilename, i.To.LineStart(), i.To.LineEnd()) text := fmt.Sprintf("%d-%d lines are duplicate of %s", i.From.LineStart(), i.From.LineEnd(), - internal.FormatCode(dupl, nil)) + internal.FormatCode(dupl)) res = append(res, goanalysis.NewIssue(&result.Issue{ Pos: token.Position{ diff --git a/pkg/golinters/errcheck/errcheck.go b/pkg/golinters/errcheck/errcheck.go index c3c813d4f828..2e2136caa2ea 100644 --- a/pkg/golinters/errcheck/errcheck.go +++ b/pkg/golinters/errcheck/errcheck.go @@ -37,7 +37,7 @@ func New(settings *config.ErrcheckSettings) *goanalysis.Linter { checker.Tags = lintCtx.Cfg.Run.BuildTags analyzer.Run = func(pass *analysis.Pass) (any, error) { - issues := runErrCheck(lintCtx, pass, checker) + issues := runErrCheck(pass, checker) if len(issues) == 0 { return nil, nil @@ -56,7 +56,7 @@ func New(settings *config.ErrcheckSettings) *goanalysis.Linter { WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck.Checker) []goanalysis.Issue { +func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker) []goanalysis.Issue { pkg := &packages.Package{ Fset: pass.Fset, Syntax: pass.Files, @@ -77,7 +77,7 @@ func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck if err.FuncName != "" { code := cmp.Or(err.SelectorName, err.FuncName) - text = fmt.Sprintf("Error return value of %s is not checked", internal.FormatCode(code, lintCtx.Cfg)) + text = fmt.Sprintf("Error return value of %s is not checked", internal.FormatCode(code)) } issues[i] = goanalysis.NewIssue( diff --git a/pkg/golinters/gochecknoinits/gochecknoinits.go b/pkg/golinters/gochecknoinits/gochecknoinits.go index c027aa8ab928..9158ee07da55 100644 --- a/pkg/golinters/gochecknoinits/gochecknoinits.go +++ b/pkg/golinters/gochecknoinits/gochecknoinits.go @@ -40,7 +40,7 @@ func run(pass *analysis.Pass) (any, error) { fnName := funcDecl.Name.Name if fnName == "init" && funcDecl.Recv.NumFields() == 0 { - pass.Reportf(funcDecl.Pos(), "don't use %s function", internal.FormatCode(fnName, nil)) + pass.Reportf(funcDecl.Pos(), "don't use %s function", internal.FormatCode(fnName)) } }) diff --git a/pkg/golinters/gocognit/gocognit.go b/pkg/golinters/gocognit/gocognit.go index e60bcfb17080..e72a9bdfe67a 100644 --- a/pkg/golinters/gocognit/gocognit.go +++ b/pkg/golinters/gocognit/gocognit.go @@ -67,7 +67,7 @@ func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goana issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: s.Pos, Text: fmt.Sprintf("cognitive complexity %d of func %s is high (> %d)", - s.Complexity, internal.FormatCode(s.FuncName, nil), settings.MinComplexity), + s.Complexity, internal.FormatCode(s.FuncName), settings.MinComplexity), FromLinter: linterName, }, pass)) } diff --git a/pkg/golinters/goconst/goconst.go b/pkg/golinters/goconst/goconst.go index f32a4c6575e2..5a44d4a5ce3a 100644 --- a/pkg/golinters/goconst/goconst.go +++ b/pkg/golinters/goconst/goconst.go @@ -85,17 +85,17 @@ func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanal switch { case issue.OccurrencesCount > 0: - text = fmt.Sprintf("string %s has %d occurrences", internal.FormatCode(issue.Str, nil), issue.OccurrencesCount) + text = fmt.Sprintf("string %s has %d occurrences", internal.FormatCode(issue.Str), issue.OccurrencesCount) if issue.MatchingConst == "" { text += ", make it a constant" } else { - text += fmt.Sprintf(", but such constant %s already exists", internal.FormatCode(issue.MatchingConst, nil)) + text += fmt.Sprintf(", but such constant %s already exists", internal.FormatCode(issue.MatchingConst)) } case issue.DuplicateConst != "": text = fmt.Sprintf("This constant is a duplicate of %s at %s", - internal.FormatCode(issue.DuplicateConst, nil), + internal.FormatCode(issue.DuplicateConst), issue.DuplicatePos.String()) default: diff --git a/pkg/golinters/gocyclo/gocyclo.go b/pkg/golinters/gocyclo/gocyclo.go index 514194709385..17b868d4972a 100644 --- a/pkg/golinters/gocyclo/gocyclo.go +++ b/pkg/golinters/gocyclo/gocyclo.go @@ -59,7 +59,7 @@ func runGoCyclo(pass *analysis.Pass, settings *config.GoCycloSettings) []goanaly for _, s := range stats { text := fmt.Sprintf("cyclomatic complexity %d of func %s is high (> %d)", - s.Complexity, internal.FormatCode(s.FuncName, nil), settings.MinComplexity) + s.Complexity, internal.FormatCode(s.FuncName), settings.MinComplexity) issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: s.Pos, diff --git a/pkg/golinters/internal/util.go b/pkg/golinters/internal/util.go index 2e5fb29f91c9..86137cf66081 100644 --- a/pkg/golinters/internal/util.go +++ b/pkg/golinters/internal/util.go @@ -6,11 +6,10 @@ import ( "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -func FormatCode(code string, _ *config.Config) string { +func FormatCode(code string) string { if strings.Contains(code, "`") { return code // TODO: properly escape or remove } diff --git a/pkg/golinters/prealloc/prealloc.go b/pkg/golinters/prealloc/prealloc.go index 66890ad5bc61..c750df990459 100644 --- a/pkg/golinters/prealloc/prealloc.go +++ b/pkg/golinters/prealloc/prealloc.go @@ -31,7 +31,7 @@ func runPreAlloc(pass *analysis.Pass, settings *config.PreallocSettings) { for _, hint := range hints { pass.Report(analysis.Diagnostic{ Pos: hint.Pos, - Message: fmt.Sprintf("Consider pre-allocating %s", internal.FormatCode(hint.DeclaredSliceName, nil)), + Message: fmt.Sprintf("Consider pre-allocating %s", internal.FormatCode(hint.DeclaredSliceName)), }) } }