Skip to content
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

ci: upgrade golangci-lint to v1.64 #1622

Closed
wants to merge 3 commits into from
Closed
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 .github/workflows/lint-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ runs:
uses: golangci/golangci-lint-action@e60da84bfae8c7920a47be973d75e15710aa8bd7 # v6.3.0
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.62.2
version: v1.64.4
args: --timeout=5m
6 changes: 3 additions & 3 deletions cmd/osv-scanner/fix/noninteractive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"maps"
"slices"

"deps.dev/util/resolve"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/google/osv-scanner/v2/internal/resolution/manifest"
"github.com/google/osv-scanner/v2/internal/resolution/util"
"github.com/google/osv-scanner/v2/pkg/lockfile"
"golang.org/x/exp/maps"
)

func autoInPlace(ctx context.Context, r *outputReporter, opts osvFixOptions, maxUpgrades int) error {
Expand Down Expand Up @@ -423,7 +423,7 @@ func makeResultVuln(vuln resolution.Vulnerability) vulnOutput {
vk := sg.Nodes[sg.Dependency].Version
affected[packageOutput{Name: vk.Name, Version: vk.Version}] = struct{}{}
}
v.Packages = maps.Keys(affected)
v.Packages = slices.Collect(maps.Keys(affected))
slices.SortFunc(v.Packages, func(a, b packageOutput) int {
if c := cmp.Compare(a.Name, b.Name); c != 0 {
return c
Expand Down Expand Up @@ -471,7 +471,7 @@ func populateResultVulns(outputResult *fixOutput, res *resolution.Result, allPat
}
}

outputResult.Vulnerabilities = maps.Values(vulns)
outputResult.Vulnerabilities = slices.Collect(maps.Values(vulns))
sortVulns(outputResult.Vulnerabilities)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/osv-scanner/fix/state-choose-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fix

import (
"fmt"
"slices"
"strconv"
"strings"

Expand All @@ -11,7 +12,6 @@ import (
"github.com/google/osv-scanner/v2/internal/remediation"
"github.com/google/osv-scanner/v2/internal/resolution"
"github.com/google/osv-scanner/v2/internal/tui"
"golang.org/x/exp/slices"
)

type stateChooseStrategy struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/osv-scanner/fix/state-in-place-result.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fix

import (
"fmt"
"slices"
"strings"

"github.com/charmbracelet/bubbles/key"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/google/osv-scanner/v2/internal/resolution"
lockf "github.com/google/osv-scanner/v2/internal/resolution/lockfile"
"github.com/google/osv-scanner/v2/internal/tui"
"golang.org/x/exp/slices"
)

type stateInPlaceResult struct {
Expand Down
5 changes: 2 additions & 3 deletions cmd/osv-scanner/fix/state-relock-result.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/google/osv-scanner/v2/internal/resolution/client"
manif "github.com/google/osv-scanner/v2/internal/resolution/manifest"
"github.com/google/osv-scanner/v2/internal/tui"
"golang.org/x/exp/maps"
)

type stateRelockResult struct {
Expand Down Expand Up @@ -137,7 +136,7 @@ func (st *stateRelockResult) Update(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
return errorAndExit(m, msg.err)
}
st.patches = msg.patches
maps.Clear(st.selectedPatches)
clear(st.selectedPatches)
st.buildPatchInfoViews(m)
st.patchesDone = true
if len(st.patches) > 0 {
Expand All @@ -155,7 +154,7 @@ func (st *stateRelockResult) Update(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
m.writing = false
m.relockBaseRes = st.currRes // relockBaseRes must match what is in the package.json
m.relockBaseResErrs = m.relockBaseRes.Errors()
maps.Clear(st.selectedPatches)
clear(st.selectedPatches)

case tui.ViewModelCloseMsg:
// info view wants to quit, just unfocus it
Expand Down
5 changes: 3 additions & 2 deletions internal/datasource/npm_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"errors"
"fmt"
"io"
"maps"
"net/http"
"slices"
"sync"
"time"

"github.com/tidwall/gjson"
"golang.org/x/exp/maps"
)

type NpmRegistryAPIClient struct {
Expand Down Expand Up @@ -55,7 +56,7 @@ func (c *NpmRegistryAPIClient) Versions(ctx context.Context, pkg string) (NpmReg
}

return NpmRegistryVersions{
Versions: maps.Keys(pkgDetails.Versions),
Versions: slices.Collect(maps.Keys(pkgDetails.Versions)),
Tags: pkgDetails.Tags,
}, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/datasource/npm_registry_cache.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package datasource

import (
"maps"
"strings"
"time"

"golang.org/x/exp/maps"
)

type npmRegistryCache struct {
Expand Down
5 changes: 2 additions & 3 deletions internal/grouper/grouper.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package grouper

import (
"maps"
"slices"
"sort"

"golang.org/x/exp/maps"

"github.com/google/osv-scanner/v2/internal/identifiers"
"github.com/google/osv-scanner/v2/pkg/models"
)
Expand Down Expand Up @@ -51,7 +50,7 @@ func Group(vulns []IDAliases) []models.GroupInfo {
}

// Sort by group ID to maintain stable order for tests.
sortedKeys := maps.Keys(extractedGroups)
sortedKeys := slices.Collect(maps.Keys(extractedGroups))
sort.Ints(sortedKeys)

result := make([]models.GroupInfo, 0, len(sortedKeys))
Expand Down
4 changes: 2 additions & 2 deletions internal/output/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package output
import (
"encoding/json"
"log"
"maps"
"os"
"slices"
"strings"

"github.com/google/osv-scanner/v2/internal/identifiers"
"github.com/google/osv-scanner/v2/pkg/models"
"golang.org/x/exp/maps"
)

type pkgWithSource struct {
Expand All @@ -22,7 +22,7 @@ type pkgSourceSet map[pkgWithSource]struct{}

// StableKeys returns the pkgWithSource keys in a deterministic order
func (pss *pkgSourceSet) StableKeys() []pkgWithSource {
pkgWithSrcKeys := maps.Keys(*pss)
pkgWithSrcKeys := slices.Collect(maps.Keys(*pss))

slices.SortFunc(pkgWithSrcKeys, func(a, b pkgWithSource) int {
// compare based on each field in descending priority
Expand Down
6 changes: 3 additions & 3 deletions internal/output/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package output
import (
"fmt"
"io"
"maps"
"path/filepath"
"slices"
"sort"
"strings"

"golang.org/x/exp/maps"

"github.com/google/osv-scanner/v2/internal/utility/results"
"github.com/google/osv-scanner/v2/internal/utility/severity"
"github.com/google/osv-scanner/v2/pkg/lockfile"
Expand Down Expand Up @@ -298,7 +298,7 @@ func licenseSummaryTableBuilder(outputTable table.Writer, vulnResult *models.Vul
// No packages found.
return outputTable
}
licenses := maps.Keys(counts)
licenses := slices.Collect(maps.Keys(counts))
// Sort the license count in descending count order with the UNKNOWN
// license last.
sort.Slice(licenses, func(i, j int) bool {
Expand Down
4 changes: 2 additions & 2 deletions internal/remediation/in_place.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"cmp"
"context"
"errors"
"maps"
"slices"

"deps.dev/util/resolve"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/google/osv-scanner/v2/internal/resolution/util"
"github.com/google/osv-scanner/v2/internal/utility/vulns"
"github.com/google/osv-scanner/v2/pkg/models"
"golang.org/x/exp/maps"
)

type InPlacePatch struct {
Expand Down Expand Up @@ -123,7 +123,7 @@ func ComputeInPlacePatches(ctx context.Context, cl client.ResolutionClient, grap
}
}
}
set, err := buildConstraintSet(vk.Semver(), maps.Keys(reqVers))
set, err := buildConstraintSet(vk.Semver(), slices.Collect(maps.Keys(reqVers)))
if err != nil {
// TODO: log error?
continue
Expand Down
4 changes: 2 additions & 2 deletions internal/remediation/in_place_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package remediation_test
import (
"cmp"
"context"
"maps"
"slices"
"testing"

Expand All @@ -15,7 +16,6 @@ import (
"github.com/google/osv-scanner/v2/internal/resolution/lockfile"
"github.com/google/osv-scanner/v2/internal/testutility"
lf "github.com/google/osv-scanner/v2/pkg/lockfile"
"golang.org/x/exp/maps"
)

func parseInPlaceFixture(t *testing.T, universePath, lockfilePath string) (*resolve.Graph, client.ResolutionClient) {
Expand Down Expand Up @@ -56,7 +56,7 @@ func checkInPlaceResults(t *testing.T, res remediation.InPlaceResult) {
for _, sg := range v.Subgraphs {
nodes[sg.Dependency] = struct{}{}
}
sortedNodes := maps.Keys(nodes)
sortedNodes := slices.Collect(maps.Keys(nodes))
slices.Sort(sortedNodes)

return minimalVuln{
Expand Down
2 changes: 1 addition & 1 deletion internal/remediation/suggest/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"errors"
"fmt"
"log"
"slices"

"deps.dev/util/resolve"
"deps.dev/util/semver"
"github.com/google/osv-scanner/v2/internal/resolution/manifest"
"github.com/google/osv-scanner/v2/pkg/lockfile"
"golang.org/x/exp/slices"
)

type MavenSuggester struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/remediation/testhelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package remediation_test
import (
"cmp"
"context"
"maps"
"slices"
"testing"

Expand All @@ -13,7 +14,6 @@ import (
"github.com/google/osv-scanner/v2/internal/resolution/manifest"
"github.com/google/osv-scanner/v2/internal/testutility"
lf "github.com/google/osv-scanner/v2/pkg/lockfile"
"golang.org/x/exp/maps"
)

func parseRemediationFixture(t *testing.T, universePath, manifestPath string, opts resolution.ResolveOpts) (*resolution.Result, client.ResolutionClient) {
Expand Down Expand Up @@ -61,7 +61,7 @@ func checkRemediationResults(t *testing.T, res []resolution.Difference) {
for _, sg := range v.Subgraphs {
nodes[sg.Dependency] = struct{}{}
}
sortedNodes := maps.Keys(nodes)
sortedNodes := slices.Collect(maps.Keys(nodes))
slices.Sort(sortedNodes)

return minimalVuln{
Expand Down
4 changes: 2 additions & 2 deletions internal/resolution/lockfile/npm_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"cmp"
"context"
"errors"
"maps"
"path/filepath"
"slices"
"strings"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/tidwall/gjson"
"github.com/tidwall/pretty"
"github.com/tidwall/sjson"
"golang.org/x/exp/maps"
)

// New-style (npm >= 7 / lockfileVersion 2+) structure
Expand Down Expand Up @@ -177,7 +177,7 @@ func (rw NpmReadWriter) makeNodeModuleDeps(pkg lockfile.NpmLockPackage, includeD
}

func (rw NpmReadWriter) packageNamesByNodeModuleDepth(packages map[string]lockfile.NpmLockPackage) []string {
keys := maps.Keys(packages)
keys := slices.Collect(maps.Keys(packages))
slices.SortFunc(keys, func(a, b string) int {
aSplit := strings.Split(a, "node_modules/")
bSplit := strings.Split(b, "node_modules/")
Expand Down
6 changes: 3 additions & 3 deletions internal/scalibrextract/language/java/pomxmlnet/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package pomxmlnet
import (
"context"
"fmt"
"maps"
"path/filepath"

"golang.org/x/exp/maps"
"slices"

mavenresolve "deps.dev/util/resolve/maven"
mavenutil "github.com/google/osv-scanner/v2/internal/utility/maven"
Expand Down Expand Up @@ -170,7 +170,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
details[inventory.Name] = &inventory
}

return maps.Values(details), nil
return slices.Collect(maps.Values(details)), nil
}

// ToPURL converts an inventory created by this extractor into a PURL.
Expand Down
1 change: 1 addition & 0 deletions internal/testutility/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func ValueIfOnWindows(win, or string) string {
func CreateTestDir(t *testing.T) string {
t.Helper()

//nolint:usetesting // we need to customize the directory name to replace in snapshots
p, err := os.MkdirTemp("", "osv-scanner-test-*")
if err != nil {
t.Fatalf("could not create test directory: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/dependency-graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package tui

import (
"fmt"
"slices"
"strings"

"deps.dev/util/resolve"
"github.com/charmbracelet/lipgloss"
"github.com/google/osv-scanner/v2/internal/resolution"
"golang.org/x/exp/slices"
)

type chainGraphNode struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/lockfile/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func expectPackages(t *testing.T, actualPackages []lockfile.PackageDetails, expe
func createTestDir(t *testing.T) (string, func()) {
t.Helper()

//nolint:usetesting // we need to customize the directory name to replace in snapshots
p, err := os.MkdirTemp("", "osv-scanner-test-*")
if err != nil {
t.Fatalf("could not create test directory: %v", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/lockfile/parse-go-lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package lockfile
import (
"fmt"
"io"
"maps"
"path/filepath"
"slices"
"strings"

"golang.org/x/exp/maps"
"golang.org/x/mod/modfile"
)

Expand Down Expand Up @@ -92,7 +93,7 @@ func (e GoLockExtractor) Extract(f DepFile) ([]PackageDetails, error) {
}
}

return maps.Values(deduplicatePackages(packages)), nil
return slices.Collect(maps.Values(deduplicatePackages(packages))), nil
}

var _ Extractor = GoLockExtractor{}
Expand Down
Loading
Loading