From 97fa22c161056c289a9978f20e3fb6b05d779a23 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 20:48:22 -0700 Subject: lint: Turn on gomnd --- lib/btrfs/btrfsitem/statmode.go | 4 ++-- lib/btrfs/btrfsprim/objid.go | 3 ++- lib/btrfs/btrfsprim/uuid.go | 3 ++- lib/btrfs/btrfssum/csum.go | 3 ++- lib/btrfs/btrfssum/shortsum.go | 5 +++-- lib/btrfs/btrfstree/types_node.go | 10 ++++++---- 6 files changed, 17 insertions(+), 11 deletions(-) (limited to 'lib/btrfs') diff --git a/lib/btrfs/btrfsitem/statmode.go b/lib/btrfs/btrfsitem/statmode.go index a1302ee..557b688 100644 --- a/lib/btrfs/btrfsitem/statmode.go +++ b/lib/btrfs/btrfsitem/statmode.go @@ -1,5 +1,5 @@ // Copyright (C) 2020-2021 Ambassador Labs -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: Apache-2.0 // @@ -9,7 +9,6 @@ package btrfsitem type StatMode uint32 -//nolint:deadcode,varcheck // not all of these modes will be used const ( // 16 bits = 5⅓ octal characters @@ -73,6 +72,7 @@ func (mode StatMode) IsRegular() bool { // 's' (GNU `ls` behavior; though POSIX notes that many // implementations use '=' for sockets). func (mode StatMode) String() string { + //nolint:gomnd // Magic numbers is all this is. buf := [10]byte{ // type: This string is easy; it directly pairs with // the above ModeFmtXXX list above; the character in diff --git a/lib/btrfs/btrfsprim/objid.go b/lib/btrfs/btrfsprim/objid.go index 17a0eeb..5ba213d 100644 --- a/lib/btrfs/btrfsprim/objid.go +++ b/lib/btrfs/btrfsprim/objid.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -68,6 +68,7 @@ func (id ObjID) Format(typ ItemType) string { case DEV_EXTENT_KEY: return fmt.Sprintf("%d", int64(id)) case QGROUP_RELATION_KEY: + //nolint:gomnd // TODO: I'm not sure what the 48/16 bit split means. return fmt.Sprintf("%d/%d", uint64(id)>>48, uint64(id)&((1<<48)-1)) diff --git a/lib/btrfs/btrfsprim/uuid.go b/lib/btrfs/btrfsprim/uuid.go index 4e3fd6b..0103ee4 100644 --- a/lib/btrfs/btrfsprim/uuid.go +++ b/lib/btrfs/btrfsprim/uuid.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -56,6 +56,7 @@ func (a UUID) Cmp(b UUID) int { return 0 } +//nolint:gomnd // This is all magic numbers. func ParseUUID(str string) (UUID, error) { var ret UUID j := 0 diff --git a/lib/btrfs/btrfssum/csum.go b/lib/btrfs/btrfssum/csum.go index 770f6ea..6df9efd 100644 --- a/lib/btrfs/btrfssum/csum.go +++ b/lib/btrfs/btrfssum/csum.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -70,6 +70,7 @@ func (typ CSumType) String() string { } func (typ CSumType) Size() int { + //nolint:gomnd // This is where we define the magic numbers. sizes := map[CSumType]int{ TYPE_CRC32: 4, TYPE_XXHASH: 8, diff --git a/lib/btrfs/btrfssum/shortsum.go b/lib/btrfs/btrfssum/shortsum.go index 6fd0c68..aaf7a89 100644 --- a/lib/btrfs/btrfssum/shortsum.go +++ b/lib/btrfs/btrfssum/shortsum.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -56,10 +56,11 @@ func (sum ShortSum) EncodeJSON(w io.Writer) error { } func deHex(r rune) (byte, bool) { - if r > 0xff { + if r > math.MaxUint8 { return 0, false } c := byte(r) + //nolint:gomnd // Hex conversion. switch { case '0' <= c && c <= '9': return c - '0', true diff --git a/lib/btrfs/btrfstree/types_node.go b/lib/btrfs/btrfstree/types_node.go index b709d34..a26215b 100644 --- a/lib/btrfs/btrfstree/types_node.go +++ b/lib/btrfs/btrfstree/types_node.go @@ -23,21 +23,23 @@ import ( type NodeFlags uint64 +const sizeofNodeFlags = 7 + func (NodeFlags) BinaryStaticSize() int { - return 7 + return sizeofNodeFlags } func (f NodeFlags) MarshalBinary() ([]byte, error) { var bs [8]byte binary.LittleEndian.PutUint64(bs[:], uint64(f)) - return bs[:7], nil + return bs[:sizeofNodeFlags], nil } func (f *NodeFlags) UnmarshalBinary(dat []byte) (int, error) { var bs [8]byte - copy(bs[:7], dat[:7]) + copy(bs[:sizeofNodeFlags], dat[:sizeofNodeFlags]) *f = NodeFlags(binary.LittleEndian.Uint64(bs[:])) - return 7, nil + return sizeofNodeFlags, nil } var ( -- cgit v1.2.3-54-g00ecf