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

This commit is contained in:
Christopher Angelo Phillips 2022-09-16 13:58:16 -04:00 committed by GitHub
parent 0a1cd25ba5
commit b48316742f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 14 additions and 22 deletions

View File

@ -10,7 +10,6 @@ linters:
enable: enable:
- asciicheck - asciicheck
- bodyclose - bodyclose
- deadcode
- depguard - depguard
- dogsled - dogsled
- dupl - dupl
@ -31,20 +30,18 @@ linters:
- nakedret - nakedret
- nolintlint - nolintlint
- revive - revive
- rowserrcheck
- staticcheck - staticcheck
- structcheck
- stylecheck - stylecheck
- typecheck - typecheck
- unconvert - unconvert
- unparam - unparam
- unused - unused
- varcheck
- whitespace - whitespace
# do not enable... # do not enable...
# - gochecknoglobals # - gochecknoglobals
# - gochecknoinits # this is too aggressive # - gochecknoinits # this is too aggressive
# - rowserrcheck disabled per generics https://github.com/golangci/golangci-lint/issues/2649
# - godot # - godot
# - godox # - godox
# - goerr113 # - goerr113

View File

@ -3,7 +3,7 @@ package packages
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"github.com/wagoodman/go-partybus" "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) 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 { if err != nil {
return fmt.Errorf("unable to read dockerfile=%q: %w", app.Anchore.Dockerfile, err) return fmt.Errorf("unable to read dockerfile=%q: %w", app.Anchore.Dockerfile, err)
} }

View File

@ -3,7 +3,7 @@ package file
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "io"
"regexp" "regexp"
"text/template" "text/template"
@ -84,7 +84,7 @@ func (c Classifier) Classify(resolver source.FileResolver, location source.Locat
defer internal.CloseAndLogError(contentReader, location.VirtualPath) 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. // 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"regexp" "regexp"
"sort" "sort"
@ -111,7 +110,7 @@ func extractValue(resolver source.FileResolver, location source.Location, start,
} }
defer internal.CloseAndLogError(readCloser, location.VirtualPath) 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 { if err != nil {
return "", fmt.Errorf("unable to read contents for location=%q : %w", location, err) return "", fmt.Errorf("unable to read contents for location=%q : %w", location, err)
} }

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"regexp" "regexp"
"github.com/anchore/syft/internal" "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) return nil, fmt.Errorf("unable to fetch reader for location=%q : %w", location, err)
} }
if seekPosition > 0 { if seekPosition > 0 {
n, err := io.CopyN(ioutil.Discard, readCloser, seekPosition) n, err := io.CopyN(io.Discard, readCloser, seekPosition)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read contents for location=%q while searching for secrets: %w", location, err) return nil, fmt.Errorf("unable to read contents for location=%q while searching for secrets: %w", location, err)
} }

View File

@ -4,7 +4,7 @@
// Package xcoff implements access to XCOFF (Extended Common Object File Format) files. // Package xcoff implements access to XCOFF (Extended Common Object File Format) files.
//nolint //this is an internal golang lib //nolint:all
package xcoff package xcoff
import ( import (

View File

@ -7,7 +7,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//nolint // this is an internal golang lib //nolint:all
package xcoff package xcoff
// File Header. // File Header.

View File

@ -3,7 +3,6 @@ package java
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -12,7 +11,7 @@ import (
func saveArchiveToTmp(archiveVirtualPath string, reader io.Reader) (string, string, func(), error) { func saveArchiveToTmp(archiveVirtualPath string, reader io.Reader) (string, string, func(), error) {
name := filepath.Base(archiveVirtualPath) name := filepath.Base(archiveVirtualPath)
tempDir, err := ioutil.TempDir("", "syft-archive-contents-") tempDir, err := os.MkdirTemp("", "syft-archive-contents-")
if err != nil { if err != nil {
return "", "", func() {}, fmt.Errorf("unable to create tempdir for archive processing: %w", err) return "", "", func() {}, fmt.Errorf("unable to create tempdir for archive processing: %w", err)
} }

View File

@ -4,7 +4,7 @@ import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"path/filepath" "path/filepath"
"github.com/anchore/syft/internal" "github.com/anchore/syft/internal"
@ -169,7 +169,7 @@ func (c *PackageCataloger) fetchDirectURLData(resolver source.FileResolver, meta
} }
defer internal.CloseAndLogError(directURLContents, directURLLocation.VirtualPath) defer internal.CloseAndLogError(directURLContents, directURLLocation.VirtualPath)
buffer, err := ioutil.ReadAll(directURLContents) buffer, err := io.ReadAll(directURLContents)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -3,7 +3,6 @@ package rpm
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
rpmdb "github.com/knqyf263/go-rpmdb/pkg" 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. // 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) { 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 { if err != nil {
return nil, fmt.Errorf("failed to create temp rpmdb file: %w", err) return nil, fmt.Errorf("failed to create temp rpmdb file: %w", err)
} }

View File

@ -3,7 +3,6 @@ package swift
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"strings" "strings"
"gopkg.in/yaml.v3" "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. // 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) { func parsePodfileLock(_ string, reader io.Reader) ([]*pkg.Package, []artifact.Relationship, error) {
bytes, err := ioutil.ReadAll(reader) bytes, err := io.ReadAll(reader)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("unable to read file: %w", err) return nil, nil, fmt.Errorf("unable to read file: %w", err)
} }