fix: more revive rules (#8814)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2025-05-05 07:50:37 +02:00
committed by GitHub
parent 296eb3c814
commit 3ab459e3b6
18 changed files with 65 additions and 103 deletions

View File

@@ -91,16 +91,28 @@ linters:
max-open-files: 2048
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md
rules:
- name: bool-literal-in-expr
- name: context-as-argument
arguments:
- allowTypesBefore: "*testing.T"
- name: duplicated-imports
- name: early-return
arguments:
- preserve-scope
- name: if-return
- name: increment-decrement
- name: indent-error-flow
arguments:
- preserve-scope
- name: range
- name: range-val-address
- name: superfluous-else
arguments:
- preserve-scope
- name: time-equal
- name: unnecessary-stmt
- name: unused-parameter
- name: use-any
testifylint:
enable-all: true

View File

@@ -42,8 +42,5 @@ func run() error {
}
app := commands.NewApp()
if err := app.Execute(); err != nil {
return err
}
return nil
return app.Execute()
}

77
go.mod
View File

@@ -20,7 +20,6 @@ require (
github.com/aquasecurity/go-pep440-version v0.0.1
github.com/aquasecurity/go-version v0.0.1
github.com/aquasecurity/iamgo v0.0.10
github.com/aquasecurity/jfather v0.0.8 // indirect
github.com/aquasecurity/table v1.8.0
github.com/aquasecurity/testdocker v0.0.0-20240730042311-4642e94c7fc8
github.com/aquasecurity/tml v0.6.1
@@ -49,8 +48,6 @@ require (
github.com/fatih/color v1.18.0
github.com/go-git/go-git/v5 v5.15.0
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 // Replace with encoding/json/v2 when proposal is accepted. Track https://github.com/golang/go/issues/71497
github.com/go-openapi/runtime v0.28.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-redis/redis/v8 v8.11.5
github.com/gocsaf/csaf/v3 v3.2.0
github.com/golang-jwt/jwt/v5 v5.2.2
@@ -94,7 +91,6 @@ require (
github.com/openvex/discovery v0.1.1-0.20240802171711-7c54efc57553
github.com/openvex/go-vex v0.2.5
github.com/owenrumney/go-sarif/v2 v2.3.3
github.com/owenrumney/squealer v1.2.11 // indirect
github.com/package-url/packageurl-go v0.1.3
github.com/quasilyte/go-ruleguard/dsl v0.3.22
github.com/rust-secure-code/go-rustaudit v0.0.0-20250226111315-e20ec32e963c
@@ -120,7 +116,6 @@ require (
github.com/zclconf/go-cty-yaml v1.1.0
go.etcd.io/bbolt v1.4.0
golang.org/x/crypto v0.37.0
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
golang.org/x/mod v0.24.0
golang.org/x/net v0.39.0
golang.org/x/sync v0.13.0
@@ -134,7 +129,6 @@ require (
k8s.io/api v0.33.0
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
modernc.org/sqlite v1.37.0
sigs.k8s.io/yaml v1.4.0 // indirect
)
require (
@@ -174,10 +168,23 @@ require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/agnivade/levenshtein v1.2.1 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/aquasecurity/jfather v0.0.8 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go v1.55.7 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ebs v1.22.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
@@ -214,10 +221,13 @@ require (
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ebitengine/purego v0.8.2 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
@@ -237,9 +247,12 @@ require (
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/runtime v0.28.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-yaml v1.15.23 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
@@ -251,9 +264,12 @@ require (
github.com/google/certificate-transparency-go v1.1.8 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-github/v31 v31.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.9 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/subcommands v1.2.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
github.com/gorilla/mux v1.8.1 // indirect
@@ -275,6 +291,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/knqyf263/labeler v0.0.0-20200423181506-7a6e545148c3 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/letsencrypt/boulder v0.0.0-20240620165639-de9c06129bec // indirect
@@ -292,9 +309,11 @@ require (
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/go-archive v0.1.0 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/moby/sys/atomicwriter v0.1.0 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/signal v0.7.1 // indirect
@@ -310,9 +329,12 @@ require (
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/opencontainers/selinux v1.11.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/owenrumney/squealer v1.2.11 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
@@ -331,12 +353,15 @@ require (
github.com/rubenv/sql-migrate v1.7.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/samber/oops v1.15.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/sassoftware/relic v7.2.1+incompatible // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shibumi/go-pathspec v1.3.0 // indirect
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/sigstore/cosign/v2 v2.2.4 // indirect
github.com/sigstore/protobuf-specs v0.4.1 // indirect
github.com/sigstore/sigstore v1.9.1 // indirect
github.com/sigstore/timestamp-authority v1.2.2 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
@@ -350,6 +375,7 @@ require (
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/tonglil/versioning v0.0.0-20170205083536-8b2a4334bd1d // indirect
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4 // indirect
github.com/transparency-dev/merkle v0.0.2 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
@@ -377,6 +403,7 @@ require (
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
golang.org/x/oauth2 v0.28.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/telemetry v0.0.0-20240522233618-39ace7a40ae7 // indirect
@@ -391,6 +418,7 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.32.2 // indirect
k8s.io/apimachinery v0.33.0 // indirect
k8s.io/apiserver v0.32.2 // indirect
@@ -406,43 +434,12 @@ require (
mvdan.cc/sh/v3 v3.11.0 // indirect
oras.land/oras-go v1.2.5 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/kind v0.19.0 // indirect
sigs.k8s.io/kustomize/api v0.19.0 // indirect
sigs.k8s.io/kustomize/kyaml v0.19.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
)
require (
github.com/alessio/shellescape v1.4.1 // indirect
github.com/aws/aws-sdk-go v1.55.7 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ebs v1.22.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
github.com/ebitengine/purego v0.8.2 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/google/go-github/v31 v31.0.0 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/google/subcommands v1.2.0 // indirect
github.com/knqyf263/labeler v0.0.0-20200423181506-7a6e545148c3 // indirect
github.com/moby/go-archive v0.1.0 // indirect
github.com/moby/sys/atomicwriter v0.1.0 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/samber/oops v1.15.0 // indirect
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
github.com/sigstore/protobuf-specs v0.4.1 // indirect
github.com/tonglil/versioning v0.0.0-20170205083536-8b2a4334bd1d // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/kind v0.19.0 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
tool (

View File

@@ -38,10 +38,7 @@ func fixtureContainerImages() error {
}
// Save trivy-test-images/containerd image
if err := saveImage("containerd", "latest"); err != nil {
return err
}
return nil
return saveImage("containerd", "latest")
}
func saveImage(subpath, tag string) error {
@@ -65,10 +62,7 @@ func saveImage(subpath, tag string) error {
if err = crane.Save(img, imgName, tarPath); err != nil {
return err
}
if err = sh.Run("gzip", tarPath); err != nil {
return err
}
return nil
return sh.Run("gzip", tarPath)
}
func fixtureVMImages() error {

View File

@@ -189,19 +189,13 @@ func (Test) FixtureTerraformPlanSnapshots() error {
// GenerateModules compiles WASM modules for unit tests
func (Test) GenerateModules() error {
pattern := filepath.Join("pkg", "module", "testdata", "*", "*.go")
if err := compileWasmModules(pattern); err != nil {
return err
}
return nil
return compileWasmModules(pattern)
}
// GenerateExampleModules compiles example Wasm modules for integration tests
func (Test) GenerateExampleModules() error {
pattern := filepath.Join("examples", "module", "*", "*.go")
if err := compileWasmModules(pattern); err != nil {
return err
}
return nil
return compileWasmModules(pattern)
}
// UpdateGolden updates golden files for integration tests

View File

@@ -245,7 +245,6 @@ func (p *Parser) markRootPkgs(id string, pkgs map[string]ftypes.Package, deps ma
for _, depID := range deps[id].DependsOn {
p.markRootPkgs(depID, pkgs, deps, visited)
}
return
}
func (p *Parser) parseLockfileVersion(lockFile LockFile) float64 {

View File

@@ -175,7 +175,7 @@ func (r *Rule) MatchKeywords(content []byte) bool {
if len(r.Keywords) == 0 {
return true
}
var contentLower = bytes.ToLower(content)
contentLower := bytes.ToLower(content)
for _, kw := range r.Keywords {
if bytes.Contains(contentLower, []byte(strings.ToLower(kw))) {
return true
@@ -499,7 +499,7 @@ func findLocation(start, end int, content []byte) (int, int, types.Code, string)
if lineStart == -1 {
lineStart = 0
} else {
lineStart += 1
lineStart++
}
lineEnd := bytes.Index(content[start:], lineSep)

View File

@@ -312,11 +312,7 @@ func (f *Flag[T]) Bind(cmd *cobra.Command) error {
}
// Bind environmental variable
if err := f.BindEnv(); err != nil {
return err
}
return nil
return f.BindEnv()
}
func (f *Flag[T]) BindEnv() error {

View File

@@ -20,11 +20,8 @@ func Unmarshal(data []byte, target any, metadata *types.Metadata) error {
if err != nil {
return err
}
if err := node.Decode(target); err != nil {
return err
}
return nil
return node.Decode(target)
}
func UnmarshalFromReader(r io.ReadSeeker, target any, metadata *types.Metadata) error {
@@ -32,9 +29,6 @@ func UnmarshalFromReader(r io.ReadSeeker, target any, metadata *types.Metadata)
if err != nil {
return err
}
if err := node.Decode(target); err != nil {
return err
}
return nil
return node.Decode(target)
}

View File

@@ -96,10 +96,7 @@ func (p *Property) UnmarshalYAML(node *yaml.Node) error {
p.StartLine = node.Line
p.EndLine = calculateEndLine(node)
p.comment = node.LineComment
if err := setPropertyValueFromYaml(node, p); err != nil {
return err
}
return nil
return setPropertyValueFromYaml(node, p)
}
func (p *Property) UnmarshalJSONFrom(dec *jsontext.Decoder) error {

View File

@@ -74,13 +74,13 @@ func (s *Scanner) ScanFS(ctx context.Context, fsys fs.FS, dir string) (scan.Resu
}
if detection.IsArchive(filePath) {
scanResults, err := s.getScanResults(filePath, ctx, fsys)
scanResults, err := s.getScanResults(ctx, filePath, fsys)
if err != nil {
return err
}
results = append(results, scanResults...)
} else if path.Base(filePath) == chartutil.ChartfileName {
if scanResults, err := s.getScanResults(filepath.Dir(filePath), ctx, fsys); err != nil {
if scanResults, err := s.getScanResults(ctx, filepath.Dir(filePath), fsys); err != nil {
return err
} else {
results = append(results, scanResults...)
@@ -97,7 +97,7 @@ func (s *Scanner) ScanFS(ctx context.Context, fsys fs.FS, dir string) (scan.Resu
}
func (s *Scanner) getScanResults(path string, ctx context.Context, target fs.FS) (results []scan.Result, err error) {
func (s *Scanner) getScanResults(ctx context.Context, path string, target fs.FS) (results []scan.Result, err error) {
helmParser, err := parser.New(path, s.parserOptions...)
if err != nil {
return nil, err

View File

@@ -108,8 +108,5 @@ func (p *Pipeline[T, U]) Do(ctx context.Context) error {
// Check whether any of the goroutines failed. Since g is accumulating the
// errors, we don't need to send them (or check for them) in the individual
// results sent on the channel.
if err := g.Wait(); err != nil {
return err
}
return nil
return g.Wait()
}

View File

@@ -81,10 +81,7 @@ func WalkDir[T any](ctx context.Context, fsys fs.FS, root string, parallel int,
// Check whether any of the goroutines failed. Since g is accumulating the
// errors, we don't need to send them (or check for them) in the individual
// results sent on the channel.
if err := g.Wait(); err != nil {
return err
}
return nil
return g.Wait()
}
func walk[T any](ctx context.Context, fsys fs.FS, path string, c chan T, onFile onFile[T]) error {

View File

@@ -52,8 +52,6 @@ func (r *pkgLicenseRenderer) Render(result types.Result) {
r.printf("Total: %d (%s)\n\n", total, strings.Join(summaries, ", "))
r.tableWriter.Render()
return
}
func (r *pkgLicenseRenderer) setHeaders() {
@@ -136,8 +134,6 @@ func (r *fileLicenseRenderer) Render(result types.Result) {
r.printf("Total: %d (%s)\n\n", total, strings.Join(summaries, ", "))
r.tableWriter.Render()
return
}
func (r *fileLicenseRenderer) setHeaders() {

View File

@@ -77,7 +77,6 @@ func (r *misconfigRenderer) Render(result types.Result) {
if r.trace {
r.outputTrace(result.Target, result.Misconfigurations)
}
return
}
func (r *misconfigRenderer) countSeverities(misconfigs []types.DetectedMisconfiguration) map[string]int {
@@ -116,7 +115,6 @@ func (r *misconfigRenderer) renderSingle(target string, typ ftypes.TargetType, m
}
func (r *misconfigRenderer) renderSummary(misconf types.DetectedMisconfiguration) {
// show pass/fail/exception unless we are only showing failures
if r.includeNonFailures {
switch misconf.Status {

View File

@@ -53,7 +53,6 @@ func (r *secretRenderer) Render(result types.Result) {
for _, m := range result.Secrets {
r.renderSingle(result.Target, m)
}
return
}
func (r *secretRenderer) countSeverities(secrets []types.DetectedSecret) map[string]int {
@@ -85,7 +84,6 @@ func (r *secretRenderer) renderSingle(target string, secret types.DetectedSecret
}
func (r *secretRenderer) renderSummary(secret types.DetectedSecret) {
// severity
switch secret.Severity {
case severityCritical:

View File

@@ -201,8 +201,6 @@ func (r *summaryRenderer) Render(report types.Report) {
r.printf("Legend:\n" +
"- '-': Not scanned\n" +
"- '0': Clean (no security findings detected)\n\n")
return
}
func (r *summaryRenderer) printf(format string, args ...any) {

View File

@@ -85,8 +85,6 @@ func (r *vulnerabilityRenderer) Render(result types.Result) {
} else if len(result.ModifiedFindings) > 0 {
showSuppressedOnce()
}
return
}
func (r *vulnerabilityRenderer) renderDetectedVulnerabilities(result types.Result) {