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: add depguard #6963

Merged
merged 5 commits into from
Jun 20, 2024
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
11 changes: 11 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
linters-settings:
depguard:
rules:
main:
list-mode: lax
deny:
# Cannot use gomodguard, which examines go.mod, as "golang.org/x/exp/slices" is not a module and doesn't appear in go.mod.
- pkg: "golang.org/x/exp/slices"
desc: "Use 'slices' instead"
- pkg: "golang.org/x/exp/maps"
desc: "Use 'maps' or 'github.com/samber/lo' instead"
dupl:
threshold: 100
errcheck:
Expand Down Expand Up @@ -81,6 +91,7 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- gci
- goconst
- gocritic
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ require (
github.com/zclconf/go-cty-yaml v1.0.3
go.etcd.io/bbolt v1.3.10
golang.org/x/crypto v0.24.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.17.0
golang.org/x/net v0.26.0
golang.org/x/sync v0.7.0
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package commands
import (
"context"
"errors"
"slices"
"sort"
"strings"

"github.com/aws/aws-sdk-go-v2/service/sts"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy-aws/pkg/errs"
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/artifact/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"errors"
"fmt"
"slices"

"github.com/hashicorp/go-multierror"
"github.com/samber/lo"
"github.com/spf13/viper"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"

"github.com/aquasecurity/go-version/pkg/semver"
Expand Down
4 changes: 2 additions & 2 deletions pkg/compliance/spec/compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"

"golang.org/x/exp/maps"
"github.com/samber/lo"
"golang.org/x/xerrors"
"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -39,7 +39,7 @@ func (cs *ComplianceSpec) Scanners() (types.Scanners, error) {
scannerTypes[scannerType] = struct{}{}
}
}
return maps.Keys(scannerTypes), nil
return lo.Keys(scannerTypes), nil
}

// CheckIDs return list of compliance check IDs
Expand Down
2 changes: 1 addition & 1 deletion pkg/compliance/spec/mapper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package spec

import (
"golang.org/x/exp/slices"
"slices"

"github.com/aquasecurity/trivy/pkg/types"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/c/conan/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package conan

import (
"io"
"slices"
"strings"

"github.com/liamg/jfather"
"github.com/samber/lo"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy/pkg/dependency"
Expand Down
3 changes: 1 addition & 2 deletions pkg/dependency/parser/golang/mod/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/samber/lo"
"golang.org/x/exp/maps"
"golang.org/x/mod/modfile"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -148,7 +147,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
}
}

return maps.Values(pkgs), nil, nil
return lo.Values(pkgs), nil, nil
}

// Check if the Go version is less than 1.17
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/java/pom/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"os"
"regexp"
"slices"
"strings"

"github.com/samber/lo"
"golang.org/x/exp/slices"

ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/log"
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependency/parser/java/pom/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"os"
"path"
"path/filepath"
"slices"
"sort"
"strings"

multierror "github.com/hashicorp/go-multierror"
"github.com/samber/lo"
"golang.org/x/exp/slices"
"golang.org/x/net/html/charset"
"golang.org/x/xerrors"

Expand Down
4 changes: 2 additions & 2 deletions pkg/dependency/parser/julia/manifest/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sort"

"github.com/BurntSushi/toml"
"golang.org/x/exp/maps"
"github.com/samber/lo"
"golang.org/x/xerrors"

ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
Expand Down Expand Up @@ -156,7 +156,7 @@ func decodeDependency(man *primitiveManifest, dep primitiveDependency, metadata
var possibleDepsMap map[string]string
err = metadata.PrimitiveDecode(dep.Dependencies, &possibleDepsMap)
if err == nil {
possibleUuids := maps.Values(possibleDepsMap)
possibleUuids := lo.Values(possibleDepsMap)
sort.Strings(possibleUuids)
dep.DependsOn = possibleUuids
return dep, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/dependency/parser/nodejs/npm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package npm
import (
"fmt"
"io"
"maps"
"path"
"slices"
"sort"
"strings"

"github.com/liamg/jfather"
"github.com/samber/lo"
"golang.org/x/exp/maps"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy/pkg/dependency"
Expand Down Expand Up @@ -186,7 +186,7 @@ func (p *Parser) parseV2(packages map[string]Package) ([]ftypes.Package, []ftype

}

return maps.Values(pkgs), deps
return lo.Values(pkgs), deps
}

// for local package npm uses links. e.g.:
Expand Down
3 changes: 1 addition & 2 deletions pkg/dependency/parser/nodejs/pnpm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/samber/lo"
"golang.org/x/exp/maps"
"golang.org/x/xerrors"
"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -216,7 +215,7 @@ func (p *Parser) parseV9(lockFile LockFile) ([]ftypes.Package, []ftypes.Dependen
}
}

return maps.Values(resolvedPkgs), maps.Values(resolvedDeps)
return lo.Values(resolvedPkgs), lo.Values(resolvedDeps)
}

// markRootPkgs sets `Dev` to false for non dev dependency.
Expand Down
4 changes: 2 additions & 2 deletions pkg/dependency/parser/php/composer/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/liamg/jfather"
"golang.org/x/exp/maps"
"github.com/samber/lo"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy/pkg/dependency"
Expand Down Expand Up @@ -98,7 +98,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
})
}

pkgSlice := maps.Values(pkgs)
pkgSlice := lo.Values(pkgs)
sort.Sort(ftypes.Packages(pkgSlice))
sort.Sort(deps)

Expand Down
4 changes: 2 additions & 2 deletions pkg/dependency/parser/ruby/bundler/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sort"
"strings"

"golang.org/x/exp/maps"
"github.com/samber/lo"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy/pkg/dependency"
Expand Down Expand Up @@ -103,7 +103,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
return nil, nil, xerrors.Errorf("scan error: %w", err)
}

pkgSlice := maps.Values(pkgs)
pkgSlice := lo.Values(pkgs)
sort.Sort(ftypes.Packages(pkgSlice))
return pkgSlice, deps, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dependency/parser/swift/cocoapods/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"sort"
"strings"

"golang.org/x/exp/maps"
"github.com/samber/lo"
"golang.org/x/xerrors"
"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -86,7 +86,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
}

sort.Sort(deps)
return utils.UniquePackages(maps.Values(parsedDeps)), deps, nil
return utils.UniquePackages(lo.Values(parsedDeps)), deps, nil
}

func parseDep(dep string) (ftypes.Package, error) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/dependency/parser/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package utils

import (
"fmt"
"maps"
"sort"

"golang.org/x/exp/maps"
"github.com/samber/lo"

ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
)
Expand Down Expand Up @@ -48,7 +49,7 @@ func UniquePackages(pkgs []ftypes.Package) []ftypes.Package {
}
}
}
pkgSlice := maps.Values(unique)
pkgSlice := lo.Values(unique)
sort.Sort(ftypes.Packages(pkgSlice))

return pkgSlice
Expand Down
6 changes: 3 additions & 3 deletions pkg/detector/ospkg/redhat/redhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package redhat
import (
"context"
"fmt"
"slices"
"sort"
"strings"
"time"

version "github.com/knqyf263/go-rpm-version"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"github.com/samber/lo"
"golang.org/x/xerrors"

dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
Expand Down Expand Up @@ -176,7 +176,7 @@ func (s *Scanner) detect(osVer string, pkg ftypes.Package) ([]types.DetectedVuln
}
}

vulns := maps.Values(uniqVulns)
vulns := lo.Values(uniqVulns)
sort.Slice(vulns, func(i, j int) bool {
return vulns[i].VulnerabilityID < vulns[j].VulnerabilityID
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/downloader/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package downloader

import (
"context"
"maps"
"os"

getter "github.com/hashicorp/go-getter"
"golang.org/x/exp/maps"
"golang.org/x/xerrors"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"io/fs"
"os"
"regexp"
"slices"
"sort"
"strings"
"sync"

"github.com/samber/lo"
"golang.org/x/exp/slices"
"golang.org/x/sync/semaphore"
"golang.org/x/xerrors"

Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/config_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package analyzer

import (
"context"
"slices"

v1 "github.com/google/go-containerregistry/pkg/v1"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy/pkg/fanal/types"
Expand Down
4 changes: 2 additions & 2 deletions pkg/fanal/analyzer/imgconf/apk/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

v1 "github.com/google/go-containerregistry/pkg/v1"
"golang.org/x/exp/maps"
"github.com/samber/lo"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
Expand Down Expand Up @@ -138,7 +138,7 @@ func (a alpineCmdAnalyzer) parseConfig(apkIndexArchive *apkIndex, config *v1.Con
}
}

return maps.Values(uniqPkgs)
return lo.Values(uniqPkgs)
}

func (a alpineCmdAnalyzer) parseCommand(command string, envs map[string]string) (pkgs []string) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/fanal/analyzer/language/dart/pub/pubspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sort"

"github.com/samber/lo"
"golang.org/x/exp/maps"
"golang.org/x/xerrors"
"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -166,7 +165,7 @@ func parsePubSpecYaml(r io.Reader) (string, []string, error) {

// pubspec.yaml uses version ranges
// save only dependencies names
dependsOn := maps.Keys(spec.Dependencies)
dependsOn := lo.Keys(spec.Dependencies)

return dependency.ID(types.Pub, spec.Name, spec.Version), dependsOn, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/analyzer/language/dotnet/nuget/nuget.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"io/fs"
"os"
"path/filepath"
"slices"
"sort"

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

"github.com/aquasecurity/trivy/pkg/dependency/parser/nuget/config"
Expand Down
Loading