Skip to content

chore: remove dead code #5801

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

Merged
merged 1 commit into from
May 14, 2025
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
2 changes: 1 addition & 1 deletion pkg/golinters/dupl/dupl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions pkg/golinters/errcheck/errcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/gochecknoinits/gochecknoinits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/gocognit/gocognit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/golinters/goconst/goconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/gocyclo/gocyclo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions pkg/golinters/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/prealloc/prealloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
})
}
}
Loading