summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-03-17 02:28:54 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2023-03-17 02:52:07 -0400
commit1ea26f04701fa66e36b058f3efb3a6c7059cdc5c (patch)
tree9ba66e893d6f66096f6b06284d09c8eb3e50facc /lib
parent0cfc5d80855ee0a28329305cda13e7bff935a297 (diff)
tree-wide: Turn on all revive linters (with exceptions)
Diffstat (limited to 'lib')
-rw-r--r--lib/btrfs/btrfsprim/key.go9
-rw-r--r--lib/btrfs/btrfstree/btree_tree.go5
-rw-r--r--lib/btrfs/btrfstree/path.go27
-rw-r--r--lib/btrfs/btrfstree/types_node.go29
-rw-r--r--lib/btrfs/io4_fs.go16
-rw-r--r--lib/btrfscheck/graph.go2
-rw-r--r--lib/btrfsutil/listnodes.go8
-rw-r--r--lib/btrfsutil/print_addrspace.go2
-rw-r--r--lib/containers/intervaltree.go2
-rw-r--r--lib/containers/optional.go7
-rw-r--r--lib/containers/rbtree.go3
-rw-r--r--lib/containers/rbtree_test.go30
-rw-r--r--lib/diskio/file_blockbuf.go2
-rw-r--r--lib/diskio/file_state_test.go6
-rw-r--r--lib/fmtutil/fmt_test.go6
-rw-r--r--lib/profile/cobra.go2
-rw-r--r--lib/streamio/runescanner.go2
-rw-r--r--lib/textui/log.go6
18 files changed, 82 insertions, 82 deletions
diff --git a/lib/btrfs/btrfsprim/key.go b/lib/btrfs/btrfsprim/key.go
index 2930782..5580c52 100644
--- a/lib/btrfs/btrfsprim/key.go
+++ b/lib/btrfs/btrfsprim/key.go
@@ -42,12 +42,11 @@ func (key Key) Format(tree ObjID) string {
return fmt.Sprintf("(%v %v -1)",
key.ObjectID.Format(tree),
key.ItemType)
- } else {
- return fmt.Sprintf("(%v %v %v)",
- key.ObjectID.Format(tree),
- key.ItemType,
- key.Offset)
}
+ return fmt.Sprintf("(%v %v %v)",
+ key.ObjectID.Format(tree),
+ key.ItemType,
+ key.Offset)
}
}
diff --git a/lib/btrfs/btrfstree/btree_tree.go b/lib/btrfs/btrfstree/btree_tree.go
index df58c0c..1e3c789 100644
--- a/lib/btrfs/btrfstree/btree_tree.go
+++ b/lib/btrfs/btrfstree/btree_tree.go
@@ -188,7 +188,8 @@ func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key,
return nil, nil, err
}
- if node.Data.Head.Level > 0 {
+ switch {
+ case node.Data.Head.Level > 0:
// interior node
// Search for the right-most node.Data.BodyInterior item for which
@@ -220,7 +221,7 @@ func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key,
ToMaxKey: toMaxKey,
})
FreeNodeRef(node)
- } else {
+ default:
// leaf node
// Search for a member of node.Data.BodyLeaf for which
diff --git a/lib/btrfs/btrfstree/path.go b/lib/btrfs/btrfstree/path.go
index dc2fc1d..b9ab5bc 100644
--- a/lib/btrfs/btrfstree/path.go
+++ b/lib/btrfs/btrfstree/path.go
@@ -101,23 +101,22 @@ func (elem TreePathElem) writeNodeTo(w io.Writer) {
func (path TreePath) String() string {
if len(path) == 0 {
return "(empty-path)"
+ }
+ var ret strings.Builder
+ fmt.Fprintf(&ret, "%s->", path[0].FromTree.Format(btrfsprim.ROOT_TREE_OBJECTID))
+ if len(path) == 1 && path[0] == (TreePathElem{FromTree: path[0].FromTree, FromItemSlot: -1}) {
+ ret.WriteString("(empty-path)")
} else {
- var ret strings.Builder
- fmt.Fprintf(&ret, "%s->", path[0].FromTree.Format(btrfsprim.ROOT_TREE_OBJECTID))
- if len(path) == 1 && path[0] == (TreePathElem{FromTree: path[0].FromTree, FromItemSlot: -1}) {
- ret.WriteString("(empty-path)")
- } else {
- path[0].writeNodeTo(&ret)
- }
- for _, elem := range path[1:] {
- fmt.Fprintf(&ret, "[%v]", elem.FromItemSlot)
- if elem.ToNodeAddr != 0 {
- ret.WriteString("->")
- elem.writeNodeTo(&ret)
- }
+ path[0].writeNodeTo(&ret)
+ }
+ for _, elem := range path[1:] {
+ fmt.Fprintf(&ret, "[%v]", elem.FromItemSlot)
+ if elem.ToNodeAddr != 0 {
+ ret.WriteString("->")
+ elem.writeNodeTo(&ret)
}
- return ret.String()
}
+ return ret.String()
}
func (path TreePath) DeepCopy() TreePath {
diff --git a/lib/btrfs/btrfstree/types_node.go b/lib/btrfs/btrfstree/types_node.go
index c770fe8..8295ccb 100644
--- a/lib/btrfs/btrfstree/types_node.go
+++ b/lib/btrfs/btrfstree/types_node.go
@@ -113,20 +113,22 @@ type NodeHeader struct {
// .Head.NumItems.
func (node Node) MaxItems() uint32 {
bodyBytes := node.Size - uint32(nodeHeaderSize)
- if node.Head.Level > 0 {
+ switch {
+ case node.Head.Level > 0:
return bodyBytes / uint32(keyPointerSize)
- } else {
+ default:
return bodyBytes / uint32(itemHeaderSize)
}
}
func (node Node) MinItem() (btrfsprim.Key, bool) {
- if node.Head.Level > 0 {
+ switch {
+ case node.Head.Level > 0:
if len(node.BodyInterior) == 0 {
return btrfsprim.Key{}, false
}
return node.BodyInterior[0].Key, true
- } else {
+ default:
if len(node.BodyLeaf) == 0 {
return btrfsprim.Key{}, false
}
@@ -135,12 +137,13 @@ func (node Node) MinItem() (btrfsprim.Key, bool) {
}
func (node Node) MaxItem() (btrfsprim.Key, bool) {
- if node.Head.Level > 0 {
+ switch {
+ case node.Head.Level > 0:
if len(node.BodyInterior) == 0 {
return btrfsprim.Key{}, false
}
return node.BodyInterior[len(node.BodyInterior)-1].Key, true
- } else {
+ default:
if len(node.BodyLeaf) == 0 {
return btrfsprim.Key{}, false
}
@@ -221,15 +224,15 @@ func (node Node) MarshalBinary() ([]byte, error) {
buf := make([]byte, node.Size)
- if bs, err := binstruct.Marshal(node.Head); err != nil {
+ bs, err := binstruct.Marshal(node.Head)
+ if err != nil {
return buf, err
- } else {
- if len(bs) != nodeHeaderSize {
- return nil, fmt.Errorf("header is %v bytes but expected %v",
- len(bs), nodeHeaderSize)
- }
- copy(buf, bs)
}
+ if len(bs) != nodeHeaderSize {
+ return nil, fmt.Errorf("header is %v bytes but expected %v",
+ len(bs), nodeHeaderSize)
+ }
+ copy(buf, bs)
if node.Head.Level > 0 {
if err := node.marshalInteriorTo(buf[nodeHeaderSize:]); err != nil {
diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go
index e146739..b1a1232 100644
--- a/lib/btrfs/io4_fs.go
+++ b/lib/btrfs/io4_fs.go
@@ -122,7 +122,7 @@ func (sv *Subvolume) LoadBareInode(inode btrfsprim.ObjID) (*BareInode, error) {
})
if err != nil {
val.Errs = append(val.Errs, err)
- return
+ return val
}
switch itemBody := item.Body.(type) {
@@ -135,7 +135,7 @@ func (sv *Subvolume) LoadBareInode(inode btrfsprim.ObjID) (*BareInode, error) {
panic(fmt.Errorf("should not happen: INODE_ITEM has unexpected item type: %T", itemBody))
}
- return
+ return val
})
if val.InodeItem == nil {
return nil, val.Errs
@@ -156,7 +156,7 @@ func (sv *Subvolume) LoadFullInode(inode btrfsprim.ObjID) (*FullInode, error) {
if err != nil {
val.Errs = append(val.Errs, err)
if len(items) == 0 {
- return
+ return val
}
}
for _, item := range items {
@@ -190,7 +190,7 @@ func (sv *Subvolume) LoadFullInode(inode btrfsprim.ObjID) (*FullInode, error) {
val.OtherItems = append(val.OtherItems, item)
}
}
- return
+ return val
})
if val.InodeItem == nil && val.OtherItems == nil {
return nil, val.Errs
@@ -205,12 +205,12 @@ func (sv *Subvolume) LoadDir(inode btrfsprim.ObjID) (*Dir, error) {
fullInode, err := sv.LoadFullInode(inode)
if err != nil {
val.Errs = append(val.Errs, err)
- return
+ return val
}
val.FullInode = *fullInode
val.SV = sv
val.populate()
- return
+ return val
})
if val.Inode == 0 {
return nil, val.Errs
@@ -342,12 +342,12 @@ func (sv *Subvolume) LoadFile(inode btrfsprim.ObjID) (*File, error) {
fullInode, err := sv.LoadFullInode(inode)
if err != nil {
val.Errs = append(val.Errs, err)
- return
+ return val
}
val.FullInode = *fullInode
val.SV = sv
val.populate()
- return
+ return val
})
if val.Inode == 0 {
return nil, val.Errs
diff --git a/lib/btrfscheck/graph.go b/lib/btrfscheck/graph.go
index ae6d1ec..806f609 100644
--- a/lib/btrfscheck/graph.go
+++ b/lib/btrfscheck/graph.go
@@ -47,7 +47,7 @@ func HandleItemWouldBeNoOp(typ btrfsprim.ItemType) bool {
}
}
-func HandleItem(o GraphCallbacks, ctx context.Context, treeID btrfsprim.ObjID, item btrfstree.Item) {
+func HandleItem(ctx context.Context, o GraphCallbacks, treeID btrfsprim.ObjID, item btrfstree.Item) {
// Notionally, just express the relationships shown in
// https://btrfs.wiki.kernel.org/index.php/File:References.png (from the page
// https://btrfs.wiki.kernel.org/index.php/Data_Structures )
diff --git a/lib/btrfsutil/listnodes.go b/lib/btrfsutil/listnodes.go
index 16300da..5505d23 100644
--- a/lib/btrfsutil/listnodes.go
+++ b/lib/btrfsutil/listnodes.go
@@ -30,7 +30,7 @@ func (s nodeStats) String() string {
var _ DeviceScanner[nodeStats, containers.Set[btrfsvol.LogicalAddr]] = (*nodeScanner)(nil)
-func newNodeScanner(ctx context.Context, sb btrfstree.Superblock, numBytes btrfsvol.PhysicalAddr, numSectors int) DeviceScanner[nodeStats, containers.Set[btrfsvol.LogicalAddr]] {
+func newNodeScanner(context.Context, btrfstree.Superblock, btrfsvol.PhysicalAddr, int) DeviceScanner[nodeStats, containers.Set[btrfsvol.LogicalAddr]] {
s := new(nodeScanner)
s.nodes = make(containers.Set[btrfsvol.LogicalAddr])
return s
@@ -40,16 +40,16 @@ func (s *nodeScanner) ScanStats() nodeStats {
return nodeStats{numNodes: len(s.nodes)}
}
-func (*nodeScanner) ScanSector(ctx context.Context, dev *btrfs.Device, paddr btrfsvol.PhysicalAddr) error {
+func (*nodeScanner) ScanSector(context.Context, *btrfs.Device, btrfsvol.PhysicalAddr) error {
return nil
}
-func (s *nodeScanner) ScanNode(ctx context.Context, nodeRef *diskio.Ref[btrfsvol.PhysicalAddr, btrfstree.Node]) error {
+func (s *nodeScanner) ScanNode(_ context.Context, nodeRef *diskio.Ref[btrfsvol.PhysicalAddr, btrfstree.Node]) error {
s.nodes.Insert(nodeRef.Data.Head.Addr)
return nil
}
-func (s *nodeScanner) ScanDone(ctx context.Context) (containers.Set[btrfsvol.LogicalAddr], error) {
+func (s *nodeScanner) ScanDone(_ context.Context) (containers.Set[btrfsvol.LogicalAddr], error) {
return s.nodes, nil
}
diff --git a/lib/btrfsutil/print_addrspace.go b/lib/btrfsutil/print_addrspace.go
index c9c51f0..ae2c492 100644
--- a/lib/btrfsutil/print_addrspace.go
+++ b/lib/btrfsutil/print_addrspace.go
@@ -49,7 +49,7 @@ func PrintPhysicalSpace(out io.Writer, fs *btrfs.FS) {
return mappings[i].PAddr.Compare(mappings[j].PAddr) < 0
})
- var prevDev btrfsvol.DeviceID = 0
+ var prevDev btrfsvol.DeviceID
var prevEnd btrfsvol.PhysicalAddr
var sumHole, sumExt btrfsvol.AddrDelta
for _, mapping := range mappings {
diff --git a/lib/containers/intervaltree.go b/lib/containers/intervaltree.go
index 7b96526..d2e2732 100644
--- a/lib/containers/intervaltree.go
+++ b/lib/containers/intervaltree.go
@@ -39,7 +39,7 @@ type IntervalTree[K Ordered[K], V any] struct {
inner RBTree[intervalValue[K, V]]
}
-func (t *IntervalTree[K, V]) attrFn(node *RBNode[intervalValue[K, V]]) {
+func (*IntervalTree[K, V]) attrFn(node *RBNode[intervalValue[K, V]]) {
max := node.Value.ValSpan.Max
if node.Left != nil && node.Left.Value.ChildSpan.Max.Compare(max) > 0 {
max = node.Left.Value.ChildSpan.Max
diff --git a/lib/containers/optional.go b/lib/containers/optional.go
index c0e7b32..5bb7bb6 100644
--- a/lib/containers/optional.go
+++ b/lib/containers/optional.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -19,11 +19,10 @@ var (
)
func (o Optional[T]) MarshalJSON() ([]byte, error) {
- if o.OK {
- return json.Marshal(o.Val)
- } else {
+ if !o.OK {
return []byte("null"), nil
}
+ return json.Marshal(o.Val)
}
func (o *Optional[T]) UnmarshalJSON(dat []byte) error {
diff --git a/lib/containers/rbtree.go b/lib/containers/rbtree.go
index 6182150..59f63aa 100644
--- a/lib/containers/rbtree.go
+++ b/lib/containers/rbtree.go
@@ -167,9 +167,8 @@ func (t *RBTree[T]) Subrange(rangeFn func(T) int, handleFn func(*RBNode[T]) bool
_, node := t.root.search(func(v T) int {
if rangeFn(v) <= 0 {
return -1
- } else {
- return 1
}
+ return 1
})
for node != nil && rangeFn(node.Value) > 0 {
node = node.Next()
diff --git a/lib/containers/rbtree_test.go b/lib/containers/rbtree_test.go
index d2fe931..c6e7a3b 100644
--- a/lib/containers/rbtree_test.go
+++ b/lib/containers/rbtree_test.go
@@ -108,25 +108,25 @@ func checkRBTree[T constraints.Ordered](t *testing.T, expectedSet Set[T], tree *
}
func FuzzRBTree(f *testing.F) {
- Ins := uint8(0b0100_0000)
- Del := uint8(0)
+ ins := uint8(0b0100_0000)
+ del := uint8(0)
f.Add([]uint8{})
- f.Add([]uint8{Ins | 5, Del | 5})
- f.Add([]uint8{Ins | 5, Del | 6})
- f.Add([]uint8{Del | 6})
+ f.Add([]uint8{ins | 5, del | 5})
+ f.Add([]uint8{ins | 5, del | 6})
+ f.Add([]uint8{del | 6})
f.Add([]uint8{ // CLRS Figure 14.4
- Ins | 1,
- Ins | 2,
- Ins | 5,
- Ins | 7,
- Ins | 8,
- Ins | 11,
- Ins | 14,
- Ins | 15,
-
- Ins | 4,
+ ins | 1,
+ ins | 2,
+ ins | 5,
+ ins | 7,
+ ins | 8,
+ ins | 11,
+ ins | 14,
+ ins | 15,
+
+ ins | 4,
})
f.Fuzz(func(t *testing.T, dat []uint8) {
diff --git a/lib/diskio/file_blockbuf.go b/lib/diskio/file_blockbuf.go
index b7db849..0bb3156 100644
--- a/lib/diskio/file_blockbuf.go
+++ b/lib/diskio/file_blockbuf.go
@@ -99,5 +99,5 @@ func (bf *bufferedFile[A]) WriteAt(dat []byte, off A) (n int, err error) {
bf.blockCache.Delete(blockOffset)
}
- return
+ return n, err
}
diff --git a/lib/diskio/file_state_test.go b/lib/diskio/file_state_test.go
index 3f0c119..32ca705 100644
--- a/lib/diskio/file_state_test.go
+++ b/lib/diskio/file_state_test.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -21,11 +21,11 @@ func (r byteReaderWithName) Name() string {
return r.name
}
-func (r byteReaderWithName) Close() error {
+func (byteReaderWithName) Close() error {
return nil
}
-func (r byteReaderWithName) WriteAt([]byte, int64) (int, error) {
+func (byteReaderWithName) WriteAt([]byte, int64) (int, error) {
panic("not implemented")
}
diff --git a/lib/fmtutil/fmt_test.go b/lib/fmtutil/fmt_test.go
index 2c63c2e..6d21b3e 100644
--- a/lib/fmtutil/fmt_test.go
+++ b/lib/fmtutil/fmt_test.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -53,11 +53,11 @@ func (st FmtState) Flag(b int) bool {
return false
}
-func (st FmtState) Write([]byte) (int, error) {
+func (FmtState) Write([]byte) (int, error) {
panic("not implemented")
}
-func (dst *FmtState) Format(src fmt.State, verb rune) {
+func (dst *FmtState) Format(src fmt.State, _ rune) {
if width, ok := src.Width(); ok {
dst.MWidth = width
}
diff --git a/lib/profile/cobra.go b/lib/profile/cobra.go
index 3094015..9bc55dd 100644
--- a/lib/profile/cobra.go
+++ b/lib/profile/cobra.go
@@ -67,7 +67,7 @@ func (fv *flagValue) Set(filename string) error {
}
// Type implements pflag.Value.
-func (fv *flagValue) Type() string { return "filename" }
+func (*flagValue) Type() string { return "filename" }
func pStart(name string) startFunc {
return func(w io.Writer) (StopFunc, error) {
diff --git a/lib/streamio/runescanner.go b/lib/streamio/runescanner.go
index 947efeb..203439f 100644
--- a/lib/streamio/runescanner.go
+++ b/lib/streamio/runescanner.go
@@ -89,7 +89,7 @@ func (rs *runeScanner) ReadRune() (r rune, size int, err error) {
rs.progressWriter.Set(rs.progress)
}
}
- return
+ return r, size, err
}
// ReadRune implements io.RuneScanner.
diff --git a/lib/textui/log.go b/lib/textui/log.go
index 6cf9abe..9aff364 100644
--- a/lib/textui/log.go
+++ b/lib/textui/log.go
@@ -35,7 +35,7 @@ type LogLevelFlag struct {
var _ pflag.Value = (*LogLevelFlag)(nil)
// Type implements pflag.Value.
-func (lvl *LogLevelFlag) Type() string { return "loglevel" }
+func (*LogLevelFlag) Type() string { return "loglevel" }
// Set implements pflag.Value.
func (lvl *LogLevelFlag) Set(str string) error {
@@ -94,7 +94,7 @@ func NewLogger(out io.Writer, lvl dlog.LogLevel) dlog.Logger {
}
// Helper implements dlog.Logger.
-func (l *logger) Helper() {}
+func (*logger) Helper() {}
// WithField implements dlog.Logger.
func (l *logger) WithField(key string, value any) dlog.Logger {
@@ -127,7 +127,7 @@ func (l *logger) StdLogger(lvl dlog.LogLevel) *log.Logger {
}
// Log implements dlog.Logger.
-func (l *logger) Log(lvl dlog.LogLevel, msg string) {
+func (*logger) Log(dlog.LogLevel, string) {
panic("should not happen: optimized log methods should be used instead")
}