diff --git a/.golangci.yaml b/.golangci.yaml index 75f0538bf6c..a07f7b91969 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -10,7 +10,6 @@ linters: enable: - asciicheck - bodyclose - - deadcode - depguard - dogsled - dupl @@ -31,20 +30,18 @@ linters: - nakedret - nolintlint - revive - - rowserrcheck - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - unused - - varcheck - whitespace # do not enable... # - gochecknoglobals # - gochecknoinits # this is too aggressive +# - rowserrcheck disabled per generics https://github.com/golangci/golangci-lint/issues/2649 # - godot # - godox # - goerr113 diff --git a/cmd/syft/cli/packages/packages.go b/cmd/syft/cli/packages/packages.go index 55954b1ecd0..40681b944db 100644 --- a/cmd/syft/cli/packages/packages.go +++ b/cmd/syft/cli/packages/packages.go @@ -3,7 +3,7 @@ package packages import ( "context" "fmt" - "io/ioutil" + "io" "os" "github.com/wagoodman/go-partybus" @@ -162,7 +162,7 @@ func runPackageSbomUpload(src *source.Source, s sbom.SBOM, app *config.Applicati return fmt.Errorf("unable to open dockerfile=%q: %w", app.Anchore.Dockerfile, err) } - dockerfileContents, err = ioutil.ReadAll(fh) + dockerfileContents, err = io.ReadAll(fh) if err != nil { return fmt.Errorf("unable to read dockerfile=%q: %w", app.Anchore.Dockerfile, err) } diff --git a/syft/file/classifier.go b/syft/file/classifier.go index d4efa538a1e..9b35b511057 100644 --- a/syft/file/classifier.go +++ b/syft/file/classifier.go @@ -3,7 +3,7 @@ package file import ( "bytes" "fmt" - "io/ioutil" + "io" "regexp" "text/template" @@ -84,7 +84,7 @@ func (c Classifier) Classify(resolver source.FileResolver, location source.Locat defer internal.CloseAndLogError(contentReader, location.VirtualPath) // TODO: there is room for improvement here, as this may use an excessive amount of memory. Alternate approach is to leverage a RuneReader. - contents, err := ioutil.ReadAll(contentReader) + contents, err := io.ReadAll(contentReader) if err != nil { return nil, err } diff --git a/syft/file/secrets_cataloger.go b/syft/file/secrets_cataloger.go index aae97acf547..224307b7537 100644 --- a/syft/file/secrets_cataloger.go +++ b/syft/file/secrets_cataloger.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "regexp" "sort" @@ -111,7 +110,7 @@ func extractValue(resolver source.FileResolver, location source.Location, start, } defer internal.CloseAndLogError(readCloser, location.VirtualPath) - n, err := io.CopyN(ioutil.Discard, readCloser, start) + n, err := io.CopyN(io.Discard, readCloser, start) if err != nil { return "", fmt.Errorf("unable to read contents for location=%q : %w", location, err) } diff --git a/syft/file/secrets_search_by_line_strategy.go b/syft/file/secrets_search_by_line_strategy.go index 9a453544b76..d241846fab1 100644 --- a/syft/file/secrets_search_by_line_strategy.go +++ b/syft/file/secrets_search_by_line_strategy.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "regexp" "github.com/anchore/syft/internal" @@ -79,7 +78,7 @@ func readerAtPosition(resolver source.FileResolver, location source.Location, se return nil, fmt.Errorf("unable to fetch reader for location=%q : %w", location, err) } if seekPosition > 0 { - n, err := io.CopyN(ioutil.Discard, readCloser, seekPosition) + n, err := io.CopyN(io.Discard, readCloser, seekPosition) if err != nil { return nil, fmt.Errorf("unable to read contents for location=%q while searching for secrets: %w", location, err) } diff --git a/syft/pkg/cataloger/golang/internal/xcoff/file.go b/syft/pkg/cataloger/golang/internal/xcoff/file.go index 76a39a34f74..e4eb8876a74 100644 --- a/syft/pkg/cataloger/golang/internal/xcoff/file.go +++ b/syft/pkg/cataloger/golang/internal/xcoff/file.go @@ -4,7 +4,7 @@ // Package xcoff implements access to XCOFF (Extended Common Object File Format) files. -//nolint //this is an internal golang lib +//nolint:all package xcoff import ( diff --git a/syft/pkg/cataloger/golang/internal/xcoff/xcoff.go b/syft/pkg/cataloger/golang/internal/xcoff/xcoff.go index 96cf01d25b6..5500269c54e 100644 --- a/syft/pkg/cataloger/golang/internal/xcoff/xcoff.go +++ b/syft/pkg/cataloger/golang/internal/xcoff/xcoff.go @@ -7,7 +7,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//nolint // this is an internal golang lib +//nolint:all package xcoff // File Header. diff --git a/syft/pkg/cataloger/java/save_archive_to_tmp.go b/syft/pkg/cataloger/java/save_archive_to_tmp.go index e8a4abe4749..c602170a7e0 100644 --- a/syft/pkg/cataloger/java/save_archive_to_tmp.go +++ b/syft/pkg/cataloger/java/save_archive_to_tmp.go @@ -3,7 +3,6 @@ package java import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" @@ -12,7 +11,7 @@ import ( func saveArchiveToTmp(archiveVirtualPath string, reader io.Reader) (string, string, func(), error) { name := filepath.Base(archiveVirtualPath) - tempDir, err := ioutil.TempDir("", "syft-archive-contents-") + tempDir, err := os.MkdirTemp("", "syft-archive-contents-") if err != nil { return "", "", func() {}, fmt.Errorf("unable to create tempdir for archive processing: %w", err) } diff --git a/syft/pkg/cataloger/python/package_cataloger.go b/syft/pkg/cataloger/python/package_cataloger.go index 2a95a2498ee..e27610fd41e 100644 --- a/syft/pkg/cataloger/python/package_cataloger.go +++ b/syft/pkg/cataloger/python/package_cataloger.go @@ -4,7 +4,7 @@ import ( "bufio" "encoding/json" "fmt" - "io/ioutil" + "io" "path/filepath" "github.com/anchore/syft/internal" @@ -169,7 +169,7 @@ func (c *PackageCataloger) fetchDirectURLData(resolver source.FileResolver, meta } defer internal.CloseAndLogError(directURLContents, directURLLocation.VirtualPath) - buffer, err := ioutil.ReadAll(directURLContents) + buffer, err := io.ReadAll(directURLContents) if err != nil { return nil, nil, err } diff --git a/syft/pkg/cataloger/rpm/parse_rpmdb.go b/syft/pkg/cataloger/rpm/parse_rpmdb.go index 5fc82b25a50..96ffd08fb49 100644 --- a/syft/pkg/cataloger/rpm/parse_rpmdb.go +++ b/syft/pkg/cataloger/rpm/parse_rpmdb.go @@ -3,7 +3,6 @@ package rpm import ( "fmt" "io" - "io/ioutil" "os" rpmdb "github.com/knqyf263/go-rpmdb/pkg" @@ -17,7 +16,7 @@ import ( // parseRpmDb parses an "Packages" RPM DB and returns the Packages listed within it. func parseRpmDB(resolver source.FilePathResolver, dbLocation source.Location, reader io.Reader) ([]pkg.Package, error) { - f, err := ioutil.TempFile("", internal.ApplicationName+"-rpmdb") + f, err := os.CreateTemp("", internal.ApplicationName+"-rpmdb") if err != nil { return nil, fmt.Errorf("failed to create temp rpmdb file: %w", err) } diff --git a/syft/pkg/cataloger/swift/parse_podfile_lock.go b/syft/pkg/cataloger/swift/parse_podfile_lock.go index 735f28a08c8..0bde98ece83 100644 --- a/syft/pkg/cataloger/swift/parse_podfile_lock.go +++ b/syft/pkg/cataloger/swift/parse_podfile_lock.go @@ -3,7 +3,6 @@ package swift import ( "fmt" "io" - "io/ioutil" "strings" "gopkg.in/yaml.v3" @@ -18,7 +17,7 @@ var _ common.ParserFn = parsePodfileLock // parsePodfileLock is a parser function for Podfile.lock contents, returning all cocoapods pods discovered. func parsePodfileLock(_ string, reader io.Reader) ([]*pkg.Package, []artifact.Relationship, error) { - bytes, err := ioutil.ReadAll(reader) + bytes, err := io.ReadAll(reader) if err != nil { return nil, nil, fmt.Errorf("unable to read file: %w", err) }