diff --git a/pkg/commands/internal/migrate/migrate_linter_names.go b/pkg/commands/internal/migrate/migrate_linter_names.go index da003e9af77d..bbb178ab3846 100644 --- a/pkg/commands/internal/migrate/migrate_linter_names.go +++ b/pkg/commands/internal/migrate/migrate_linter_names.go @@ -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) } } diff --git a/pkg/goformatters/internal/diff.go b/pkg/goformatters/internal/diff.go index 7b9f80bc4228..fcec87bb8bbd 100644 --- a/pkg/goformatters/internal/diff.go +++ b/pkg/goformatters/internal/diff.go @@ -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) diff --git a/pkg/golinters/govet/govet_test.go b/pkg/golinters/govet/govet_test.go index ec7072795f74..794ef6ece9db 100644 --- a/pkg/golinters/govet/govet_test.go +++ b/pkg/golinters/govet/govet_test.go @@ -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 { diff --git a/pkg/golinters/tagliatelle/tagliatelle.go b/pkg/golinters/tagliatelle/tagliatelle.go index 89ebf6c2f4df..e12cc9e82062 100644 --- a/pkg/golinters/tagliatelle/tagliatelle.go +++ b/pkg/golinters/tagliatelle/tagliatelle.go @@ -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 diff --git a/pkg/report/log.go b/pkg/report/log.go index ad096415123f..c964af559379 100644 --- a/pkg/report/log.go +++ b/pkg/report/log.go @@ -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 } diff --git a/pkg/result/processors/base_rule.go b/pkg/result/processors/base_rule.go index 607886ef1f39..46886624848a 100644 --- a/pkg/result/processors/base_rule.go +++ b/pkg/result/processors/base_rule.go @@ -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 { diff --git a/pkg/result/processors/nolint_filter.go b/pkg/result/processors/nolint_filter.go index 96fd6403ec45..e17fd7ad2521 100644 --- a/pkg/result/processors/nolint_filter.go +++ b/pkg/result/processors/nolint_filter.go @@ -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 } diff --git a/test/testshared/integration/run.go b/test/testshared/integration/run.go index cd0b4ca97076..f1add865fb54 100644 --- a/test/testshared/integration/run.go +++ b/test/testshared/integration/run.go @@ -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) diff --git a/test/testshared/runner.go b/test/testshared/runner.go index c516ad9a181a..69bb8bac80a7 100644 --- a/test/testshared/runner.go +++ b/test/testshared/runner.go @@ -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)