Skip to content

Commit c494d01

Browse files
committed
refactor: Fix linting issues found in golangci-lint v1.50.0
1 parent 31fa3de commit c494d01

File tree

32 files changed

+190
-187
lines changed

32 files changed

+190
-187
lines changed

cmd/diff/cmddiff.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package diff
55

66
import (
7-
"io/ioutil"
87
"os"
98

109
"github.com/spf13/cobra"
@@ -104,7 +103,7 @@ func Initialize(o *diff.DiffOptions, f util.Factory, args []string) (func(), err
104103
func createTempDir() (string, error) {
105104
// Create a temporary file with the passed prefix in
106105
// the default temporary directory.
107-
tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
106+
tmpDir, err := os.MkdirTemp("", tmpDirPrefix)
108107
if err != nil {
109108
return "", err
110109
}

pkg/apply/common_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"bytes"
88
"context"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"net/http"
1212
"regexp"
1313
"testing"
@@ -240,20 +240,20 @@ func (g *genericHandler) handle(t *testing.T, req *http.Request) (*http.Response
240240

241241
if req.URL.Path == singlePath && req.Method == http.MethodGet {
242242
if r.exists {
243-
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
243+
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
244244
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
245245
}
246246
return &http.Response{StatusCode: http.StatusNotFound, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.StringBody("")}, true, nil
247247
}
248248

249249
if req.URL.Path == singlePath && req.Method == http.MethodPatch {
250-
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
250+
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
251251
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
252252
}
253253

254254
if req.URL.Path == singlePath && req.Method == http.MethodDelete {
255255
if r.exists {
256-
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
256+
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
257257
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
258258
}
259259

@@ -271,12 +271,12 @@ func (g *genericHandler) handle(t *testing.T, req *http.Request) (*http.Response
271271
Kind: r.resource.GetKind(),
272272
},
273273
}
274-
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, result)))
274+
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, result)))
275275
return &http.Response{StatusCode: status, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
276276
}
277277

278278
if req.URL.Path == allPath && req.Method == http.MethodPost {
279-
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
279+
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, r.resource)))
280280
return &http.Response{StatusCode: http.StatusCreated, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
281281
}
282282
}
@@ -341,7 +341,7 @@ func (n *nsHandler) handle(t *testing.T, req *http.Request) (*http.Response, boo
341341
Name: nsName,
342342
},
343343
}
344-
bodyRC := ioutil.NopCloser(bytes.NewReader(toJSONBytes(t, &ns)))
344+
bodyRC := io.NopCloser(bytes.NewReader(toJSONBytes(t, &ns)))
345345
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: bodyRC}, true, nil
346346
}
347347
return nil, false, nil

pkg/apply/event/event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
// Type determines the type of events that are available.
16+
//
1617
//go:generate stringer -type=Type
1718
type Type int
1819

pkg/apply/prune/event-factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func CreateEventFactory(isDelete bool, groupName string) EventFactory {
3333

3434
// PruneEventFactory implements EventFactory interface as a concrete
3535
// representation of for prune events.
36+
//
3637
//nolint:revive // stuttering ok because Prune is a type of PruneEvent
3738
type PruneEventFactory struct {
3839
groupName string

pkg/apply/prune/prune.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ type Options struct {
8080
// automatically prune/delete).
8181
//
8282
// Parameters:
83-
// objs - objects to prune (delete)
84-
// pruneFilters - list of filters for deletion permission
85-
// taskContext - task for apply/prune
86-
// taskName - name of the parent task group, for events
87-
// opts - options for dry-run
83+
//
84+
// objs - objects to prune (delete)
85+
// pruneFilters - list of filters for deletion permission
86+
// taskContext - task for apply/prune
87+
// taskName - name of the parent task group, for events
88+
// opts - options for dry-run
8889
func (p *Pruner) Prune(
8990
objs object.UnstructuredSet,
9091
pruneFilters []filter.ValidationFilter,

pkg/apply/task/apply_task.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"context"
88
"errors"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"strings"
1212

1313
"k8s.io/apimachinery/pkg/api/meta"
@@ -192,8 +192,8 @@ func newApplyOptions(taskName string, eventChannel chan<- event.Event, serverSid
192192
OpenAPIPatch: true, // Normally set in apply.NewApplyOptions
193193
Recorder: genericclioptions.NoopRecorder{},
194194
IOStreams: genericclioptions.IOStreams{
195-
Out: ioutil.Discard,
196-
ErrOut: ioutil.Discard, // TODO: Warning for no lastConfigurationAnnotation
195+
Out: io.Discard,
196+
ErrOut: io.Discard, // TODO: Warning for no lastConfigurationAnnotation
197197
// is printed directly to stderr in ApplyOptions. We
198198
// should turn that into a warning on the event channel.
199199
},

pkg/apply/taskrunner/runner.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ type Options struct {
4242
//
4343
// The tasks run in a loop where a single goroutine will process events from
4444
// three different channels.
45-
// - taskQueue is read to allow updating the task queue at runtime.
46-
// - statusChannel is read to allow updates to the resource cache and triggering
47-
// validation of wait conditions.
48-
// - eventChannel is written to with events based on status updates, if
49-
// emitStatusEvents is true.
45+
// - taskQueue is read to allow updating the task queue at runtime.
46+
// - statusChannel is read to allow updates to the resource cache and triggering
47+
// validation of wait conditions.
48+
// - eventChannel is written to with events based on status updates, if
49+
// emitStatusEvents is true.
5050
func (tsr *TaskStatusRunner) Run(
5151
ctx context.Context,
5252
taskContext *TaskContext,

pkg/common/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const (
9090
)
9191

9292
// ClientDryRun returns true if input drs is DryRunClient
93+
//
9394
//nolint:stylecheck // Prevent lint errors on receiver names caused by string generation above
9495
func (drs DryRunStrategy) ClientDryRun() bool {
9596
return drs == DryRunClient

pkg/common/path.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package common
66
import (
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"os"
1110
"path/filepath"
1211

@@ -94,11 +93,11 @@ func ExpandPackageDir(f genericclioptions.FileNameFlags) (genericclioptions.File
9493
// an error if one occurs.
9594
func FilterInputFile(in io.Reader, tmpDir string) error {
9695
// Copy the config from "in" into a local temp file.
97-
dir, err := ioutil.TempDir("", tmpDirPrefix)
96+
dir, err := os.MkdirTemp("", tmpDirPrefix)
9897
if err != nil {
9998
return err
10099
}
101-
tmpFile, err := ioutil.TempFile(dir, fileRegexp)
100+
tmpFile, err := os.CreateTemp(dir, fileRegexp)
102101
if err != nil {
103102
return err
104103
}

pkg/common/path_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package common
55

66
import (
77
"bytes"
8-
"io/ioutil"
98
"os"
109
"path/filepath"
1110
"strings"
@@ -201,7 +200,7 @@ func TestFilterInputFile(t *testing.T) {
201200
t.Fatalf("Unexpected error in FilterInputFile: %s", err)
202201
}
203202
// Retrieve the files from the test filesystem.
204-
actualFiles, err := ioutil.ReadDir(tf.GetRootDir())
203+
actualFiles, err := os.ReadDir(tf.GetRootDir())
205204
if err != nil {
206205
t.Fatalf("Error reading test filesystem directory: %s", err)
207206
}
@@ -215,7 +214,7 @@ func TestFilterInputFile(t *testing.T) {
215214
if len(actualFiles) != 0 {
216215
actualFilename := (actualFiles[0]).Name()
217216
defer os.Remove(actualFilename)
218-
actual, err := ioutil.ReadFile(actualFilename)
217+
actual, err := os.ReadFile(actualFilename)
219218
if err != nil {
220219
t.Fatalf("Error reading created file (%s): %s", actualFilename, err)
221220
}

0 commit comments

Comments
 (0)