Skip to content

Commit

Permalink
refactor: replace ioutil=>io; update linter (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiffcs authored Sep 16, 2022
1 parent 0a1cd25 commit b483167
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 22 deletions.
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
- 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

0 comments on commit b483167

Please sign in to comment.