Skip to content

Commit d8aa061

Browse files
committed
ci: add nonamedreturns linter
1 parent 82a2ef1 commit d8aa061

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ linters:
3636
- misspell
3737
- nilnil
3838
- nolintlint
39+
- nonamedreturns
3940
- prealloc
4041
- revive
4142
- rowserrcheck

internal/app/siftool/file.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, Sylabs Inc. All rights reserved.
1+
// Copyright (c) 2021-2022, Sylabs Inc. All rights reserved.
22
// This software is licensed under a 3-clause BSD license. Please consult the
33
// LICENSE file distributed with the sources of this project regarding your
44
// rights to use or distribute this software.
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
// withFileImage calls fn with a FileImage loaded from path.
15-
func withFileImage(path string, writable bool, fn func(*sif.FileImage) error) (err error) {
15+
func withFileImage(path string, writable bool, fn func(*sif.FileImage) error) error {
1616
flag := os.O_RDONLY
1717
if writable {
1818
flag = os.O_RDWR
@@ -22,11 +22,12 @@ func withFileImage(path string, writable bool, fn func(*sif.FileImage) error) (e
2222
if err != nil {
2323
return err
2424
}
25-
defer func() {
26-
if uerr := f.UnloadContainer(); uerr != nil && err == nil {
27-
err = uerr
28-
}
29-
}()
3025

31-
return fn(f)
26+
err = fn(f)
27+
28+
if uerr := f.UnloadContainer(); err == nil {
29+
err = uerr
30+
}
31+
32+
return err
3233
}

pkg/integrity/select.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2021, Sylabs Inc. All rights reserved.
1+
// Copyright (c) 2020-2022, Sylabs Inc. All rights reserved.
22
// This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file
33
// distributed with the sources of this project regarding your rights to use or distribute this
44
// software.
@@ -152,7 +152,9 @@ func getGroupMinObjectID(f *sif.FileImage, groupID uint32) (uint32, error) {
152152

153153
// getGroupIDs returns all identifiers for the groups contained in f, sorted by ID. If no groups
154154
// are present, errNoGroupsFound is returned.
155-
func getGroupIDs(f *sif.FileImage) (groupIDs []uint32, err error) {
155+
func getGroupIDs(f *sif.FileImage) ([]uint32, error) {
156+
var groupIDs []uint32
157+
156158
f.WithDescriptors(func(od sif.Descriptor) bool {
157159
if groupID := od.GroupID(); groupID != 0 {
158160
groupIDs = insertSorted(groupIDs, groupID)
@@ -161,10 +163,10 @@ func getGroupIDs(f *sif.FileImage) (groupIDs []uint32, err error) {
161163
})
162164

163165
if len(groupIDs) == 0 {
164-
err = errNoGroupsFound
166+
return nil, errNoGroupsFound
165167
}
166168

167-
return groupIDs, err
169+
return groupIDs, nil
168170
}
169171

170172
// getFingerprints returns a sorted list of unique fingerprints contained in sigs.

pkg/sif/buffer.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, Sylabs Inc. All rights reserved.
1+
// Copyright (c) 2021-2022, Sylabs Inc. All rights reserved.
22
// This software is licensed under a 3-clause BSD license. Please consult the
33
// LICENSE file distributed with the sources of this project regarding your
44
// rights to use or distribute this software.
@@ -25,7 +25,7 @@ func NewBuffer(buf []byte) *Buffer {
2525
var errNegativeOffset = errors.New("negative offset")
2626

2727
// ReadAt implements the io.ReaderAt interface.
28-
func (b *Buffer) ReadAt(p []byte, off int64) (n int, err error) {
28+
func (b *Buffer) ReadAt(p []byte, off int64) (int, error) {
2929
if off < 0 {
3030
return 0, errNegativeOffset
3131
}
@@ -34,17 +34,17 @@ func (b *Buffer) ReadAt(p []byte, off int64) (n int, err error) {
3434
return 0, io.EOF
3535
}
3636

37-
n = copy(p, b.buf[off:])
37+
n := copy(p, b.buf[off:])
3838
if n < len(p) {
39-
err = io.EOF
39+
return n, io.EOF
4040
}
41-
return n, err
41+
return n, nil
4242
}
4343

4444
var errNegativePosition = errors.New("negative position")
4545

4646
// Write implements the io.Writer interface.
47-
func (b *Buffer) Write(p []byte) (n int, err error) {
47+
func (b *Buffer) Write(p []byte) (int, error) {
4848
if b.pos < 0 {
4949
return 0, errNegativePosition
5050
}
@@ -53,7 +53,7 @@ func (b *Buffer) Write(p []byte) (n int, err error) {
5353
b.buf = append(b.buf, make([]byte, need-have)...)
5454
}
5555

56-
n = copy(b.buf[b.pos:], p)
56+
n := copy(b.buf[b.pos:], p)
5757
b.pos += int64(n)
5858
return n, nil
5959
}

pkg/sif/descriptor.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018-2021, Sylabs Inc. All rights reserved.
1+
// Copyright (c) 2018-2022, Sylabs Inc. All rights reserved.
22
// Copyright (c) 2017, SingularityWare, LLC. All rights reserved.
33
// Copyright (c) 2017, Yannick Cote <[email protected]> All rights reserved.
44
// This software is licensed under a 3-clause BSD license. Please consult the
@@ -96,7 +96,7 @@ func (d *rawDescriptor) setExtra(v interface{}) error {
9696
}
9797

9898
// getPartitionMetadata gets metadata for a partition data object.
99-
func (d rawDescriptor) getPartitionMetadata() (fs FSType, pt PartType, arch string, err error) {
99+
func (d rawDescriptor) getPartitionMetadata() (FSType, PartType, string, error) {
100100
if got, want := d.DataType, DataPartition; got != want {
101101
return 0, 0, "", &unexpectedDataTypeError{got, []DataType{want}}
102102
}
@@ -142,6 +142,7 @@ func (d Descriptor) GroupID() uint32 { return d.raw.GroupID &^ descrGroupMask }
142142
// LinkedID returns the object/group ID d is linked to, or zero if d does not contain a linked
143143
// ID. If isGroup is true, the returned id is an object group ID. Otherwise, the returned id is a
144144
// data object ID.
145+
//nolint:nonamedreturns // Named returns effective as documentation.
145146
func (d Descriptor) LinkedID() (id uint32, isGroup bool) {
146147
return d.raw.LinkedID &^ descrGroupMask, d.raw.LinkedID&descrGroupMask == descrGroupMask
147148
}
@@ -162,6 +163,7 @@ func (d Descriptor) ModifiedAt() time.Time { return time.Unix(d.raw.ModifiedAt,
162163
func (d Descriptor) Name() string { return strings.TrimRight(string(d.raw.Name[:]), "\000") }
163164

164165
// PartitionMetadata gets metadata for a partition data object.
166+
//nolint:nonamedreturns // Named returns effective as documentation.
165167
func (d Descriptor) PartitionMetadata() (fs FSType, pt PartType, arch string, err error) {
166168
return d.raw.getPartitionMetadata()
167169
}
@@ -186,6 +188,7 @@ func getHashType(ht hashType) (crypto.Hash, error) {
186188
}
187189

188190
// SignatureMetadata gets metadata for a signature data object.
191+
//nolint:nonamedreturns // Named returns effective as documentation.
189192
func (d Descriptor) SignatureMetadata() (ht crypto.Hash, fp []byte, err error) {
190193
if got, want := d.raw.DataType, DataSignature; got != want {
191194
return ht, fp, &unexpectedDataTypeError{got, []DataType{want}}

0 commit comments

Comments
 (0)