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

refactor: replace ioutil=>io; update linter #1211

Merged
merged 2 commits into from
Sep 16, 2022
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
5 changes: 1 addition & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ linters:
enable:
- asciicheck
- bodyclose
- deadcode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the other linters be added to the commented section below?

Copy link
Contributor Author

@spiffcs spiffcs Sep 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the ones that were relevant to the generic issue. The ones that have been deleted are:

[WARN] x is deprecated. Replaced by unused.

I can include them commented out if we want to ever incorporate them again if they are picked up by a maintainer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no need if they're deprecated 👍

- depguard
- dogsled
- dupl
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/syft/cli/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package packages
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/wagoodman/go-partybus"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions syft/file/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package file
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"regexp"
"text/template"

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions syft/file/secrets_cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"regexp"
"sort"

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions syft/file/secrets_search_by_line_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"regexp"

"github.com/anchore/syft/internal"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion syft/pkg/cataloger/golang/internal/xcoff/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion syft/pkg/cataloger/golang/internal/xcoff/xcoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions syft/pkg/cataloger/java/save_archive_to_tmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package java
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions syft/pkg/cataloger/python/package_cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"path/filepath"

"github.com/anchore/syft/internal"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions syft/pkg/cataloger/rpm/parse_rpmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rpm
import (
"fmt"
"io"
"io/ioutil"
"os"

rpmdb "github.com/knqyf263/go-rpmdb/pkg"
Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions syft/pkg/cataloger/swift/parse_podfile_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package swift
import (
"fmt"
"io"
"io/ioutil"
"strings"

"gopkg.in/yaml.v3"
Expand All @@ -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)
}
Expand Down