Skip to content

dev: some simplifications #5843

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 30, 2025
Merged
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
14 changes: 4 additions & 10 deletions pkg/commands/internal/migrate/migrate_linter_names.go
Original file line number Diff line number Diff line change
@@ -749,11 +749,8 @@ func allEnabled(old versionone.Linters, linters []LinterInfo) []LinterInfo {
var results []LinterInfo

for _, linter := range linters {
for _, name := range old.Enable {
if linter.isName(name) {
results = append(results, linter)
break
}
if slices.ContainsFunc(old.Enable, linter.isName) {
results = append(results, linter)
}
}

@@ -764,11 +761,8 @@ func allDisabled(old versionone.Linters, linters []LinterInfo) []LinterInfo {
var results []LinterInfo

for _, linter := range linters {
for _, name := range old.Disable {
if linter.isName(name) {
results = append(results, linter)
break
}
if slices.ContainsFunc(old.Disable, linter.isName) {
results = append(results, linter)
}
}

5 changes: 1 addition & 4 deletions pkg/goformatters/internal/diff.go
Original file line number Diff line number Diff line change
@@ -250,10 +250,7 @@ func ExtractDiagnosticFromPatch(
}

func toDiagnostic(ft *token.File, change Change, adjLine int) analysis.Diagnostic {
from := change.From + adjLine
if from > ft.LineCount() {
from = ft.LineCount()
}
from := min(change.From+adjLine, ft.LineCount())

start := ft.LineStart(from)

2 changes: 1 addition & 1 deletion pkg/golinters/govet/govet_test.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import (

func TestGovet(t *testing.T) {
// Checking that every default analyzer is in "all analyzers" list.
checkList := append([]*analysis.Analyzer{}, defaultAnalyzers...)
checkList := slices.Clone(defaultAnalyzers)
checkList = append(checkList, shadow.Analyzer) // special case, used in analyzersFromConfig

for _, defaultAnalyzer := range checkList {
6 changes: 3 additions & 3 deletions pkg/golinters/tagliatelle/tagliatelle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tagliatelle

import (
"maps"

"github.com/ldez/tagliatelle"

"github.com/golangci/golangci-lint/v2/pkg/config"
@@ -19,9 +21,7 @@ func New(settings *config.TagliatelleSettings) *goanalysis.Linter {
}

if settings != nil {
for k, v := range settings.Case.Rules {
cfg.Rules[k] = v
}
maps.Copy(cfg.Rules, settings.Case.Rules)

cfg.ExtendedRules = toExtendedRules(settings.Case.ExtendedRules)
cfg.UseFieldName = settings.Case.UseFieldName
3 changes: 2 additions & 1 deletion pkg/report/log.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package report

import (
"fmt"
"slices"
"strings"

"github.com/golangci/golangci-lint/v2/pkg/logutils"
@@ -50,7 +51,7 @@ func (lw LogWrapper) Infof(format string, args ...any) {
func (lw LogWrapper) Child(name string) logutils.Log {
c := lw
c.origLog = lw.origLog.Child(name)
c.tags = append([]string{}, lw.tags...)
c.tags = slices.Clone(lw.tags)
c.tags = append(c.tags, name)
return c
}
9 changes: 2 additions & 7 deletions pkg/result/processors/base_rule.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package processors

import (
"regexp"
"slices"

"github.com/golangci/golangci-lint/v2/pkg/config"
"github.com/golangci/golangci-lint/v2/pkg/fsutils"
@@ -73,13 +74,7 @@ func (r *baseRule) match(issue *result.Issue, lines *fsutils.LineCache, log logu
}

func (r *baseRule) matchLinter(issue *result.Issue) bool {
for _, linter := range r.linters {
if linter == issue.FromLinter {
return true
}
}

return false
return slices.Contains(r.linters, issue.FromLinter)
}

func (r *baseRule) matchSource(issue *result.Issue, lineCache *fsutils.LineCache, log logutils.Log) bool {
3 changes: 1 addition & 2 deletions pkg/result/processors/nolint_filter.go
Original file line number Diff line number Diff line change
@@ -185,8 +185,7 @@ func (p *NolintFilter) buildIgnoredRangesForFile(f *ast.File, fset *token.FileSe
ast.Walk(&e, f)

// TODO: merge all ranges: there are repeated ranges
allRanges := append([]ignoredRange{}, inlineRanges...)
allRanges = append(allRanges, e.expandedRanges...)
allRanges := slices.Concat(inlineRanges, e.expandedRanges)

return allRanges
}
3 changes: 2 additions & 1 deletion test/testshared/integration/run.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"testing"
"time"
@@ -70,7 +71,7 @@ func testOneSource(t *testing.T, log *logutils.StderrLog, binPath, sourcePath st
}

for _, addArg := range []string{"", "-Etypecheck"} {
caseArgs := append([]string{}, args...)
caseArgs := slices.Clone(args)

if addArg != "" {
caseArgs = append(caseArgs, addArg)
7 changes: 3 additions & 4 deletions test/testshared/runner.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"sync"
"syscall"
@@ -286,10 +287,8 @@ func (r *RunnerResult) ExpectNoIssues() {
func (r *RunnerResult) ExpectExitCode(possibleCodes ...int) *RunnerResult {
r.tb.Helper()

for _, pc := range possibleCodes {
if pc == r.exitCode {
return r
}
if slices.Contains(possibleCodes, r.exitCode) {
return r
}

assert.Fail(r.tb, "invalid exit code", "exit code (%d) must be one of %v: %s", r.exitCode, possibleCodes, r.output)