Skip to content

Commit f7a36f5

Browse files
ferhatelmask8s-ci-robot
authored andcommitted
lint: enable errcheck and fix some issues (#327)
* lint: enable errcheck and fix some issues * add .errcheck-excluded.txt to disable some function calls * related to #325 * drop ignore file and be more explicit
1 parent 35dcafb commit f7a36f5

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ linters-settings:
44
# put imports beginning with prefix after 3rd-party packages;
55
# it's a comma-separated list of prefixes
66
local-prefixes: sigs.k8s.io/krew
7+
errcheck:
8+
check-type-assertions: false
9+
check-blank: false
710

811
# options for analysis running
912
run:
@@ -36,5 +39,4 @@ linters:
3639
- prealloc
3740
- deadcode
3841
- varcheck
39-
disable:
4042
- errcheck

cmd/krew/cmd/root.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ func Execute() {
6262

6363
func init() {
6464
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
65-
flag.CommandLine.Parse([]string{}) // convince pkg/flag we parsed the flags
65+
_ = flag.CommandLine.Parse([]string{}) // convince pkg/flag we parsed the flags
6666
flag.CommandLine.VisitAll(func(f *flag.Flag) {
6767
if f.Name != "v" { // hide all glog flags except for -v
6868
pflag.Lookup(f.Name).Hidden = true
6969
}
7070
})
71-
flag.Set("logtostderr", "true") // Set glog default to stderr
71+
if err := flag.Set("logtostderr", "true"); err != nil {
72+
fmt.Printf("can't set log to stderr %+v", err)
73+
os.Exit(1)
74+
}
7275

7376
paths = environment.MustGetKrewPaths()
7477
if err := ensureDirs(paths.BasePath(),

cmd/validate-krew-manifest/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ var flManifest string
4040

4141
func init() {
4242
flag.StringVar(&flManifest, "manifest", "", "path to plugin manifest file")
43-
flag.Set("logtostderr", "true") // Set glog default to stderr
43+
if err := flag.Set("logtostderr", "true"); err != nil {
44+
fmt.Printf("can't set log to stderr %+v", err)
45+
os.Exit(1)
46+
}
4447
// TODO(ahmetb) iterate over glog flags and hide them (not sure if possible without using pflag)
4548
flag.Parse()
4649
}

integration_test/testutil_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ func (it *ITest) initializeIndex() {
257257
it.t.Fatalf("cannot clone repository: %s", err)
258258
}
259259

260-
ioutil.WriteFile(persistentCacheFile, indexTar, 0600)
260+
if err = ioutil.WriteFile(persistentCacheFile, indexTar, 0600); err != nil {
261+
it.t.Fatalf("cannot write persistent cache file: %s", err)
262+
}
261263
})
262264

263265
indexDir := filepath.Join(it.Root(), "index")

pkg/download/downloader.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ func extractZIP(targetDir string, read io.ReaderAt, size int64) error {
6161
for _, f := range zipReader.File {
6262
path := filepath.Join(targetDir, filepath.FromSlash(f.Name))
6363
if f.FileInfo().IsDir() {
64-
os.MkdirAll(path, f.Mode())
64+
if err := os.MkdirAll(path, f.Mode()); err != nil {
65+
return errors.Wrap(err, "can't create directory tree")
66+
}
6567
continue
6668
}
6769

pkg/download/verifier_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestSha256Verifier(t *testing.T) {
5050
for _, tt := range tests {
5151
t.Run(tt.name, func(t *testing.T) {
5252
v := NewSha256Verifier(tt.args.hash)
53-
io.Copy(v, bytes.NewReader(tt.write))
53+
_, _ = io.Copy(v, bytes.NewReader(tt.write))
5454
if err := v.Verify(); (err != nil) != tt.wantError {
5555
t.Errorf("NewSha256Verifier().Write(%x).Verify() = %v, wantReader %v", tt.write, err, tt.wantError)
5656
return
@@ -84,7 +84,7 @@ func TestTrueVerifier(t *testing.T) {
8484
for _, tt := range tests {
8585
t.Run(tt.name, func(t *testing.T) {
8686
v := NewInsecureVerifier()
87-
io.Copy(v, bytes.NewReader(tt.write))
87+
_, _ = io.Copy(v, bytes.NewReader(tt.write))
8888
if err := v.Verify(); (err != nil) != tt.wantError {
8989
t.Errorf("NewInsecureVerifier().Write(%x).Verify() = %v, wantReader %v", tt.write, err, tt.wantError)
9090
return

pkg/receiptsmigration/migration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func TestIsMigrated(t *testing.T) {
6868

6969
newPaths := environment.MustGetKrewPaths()
7070

71-
os.MkdirAll(tmpDir.Path("receipts"), os.ModePerm)
72-
os.MkdirAll(tmpDir.Path("store"), os.ModePerm)
71+
_ = os.MkdirAll(tmpDir.Path("receipts"), os.ModePerm)
72+
_ = os.MkdirAll(tmpDir.Path("store"), os.ModePerm)
7373
for _, name := range test.filesPresent {
7474
touch(tmpDir, name)
7575
}

0 commit comments

Comments
 (0)