From b6ec0ce387b0a3d9fb6f58ba43ca27943f99fb93 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 17:41:53 -0700 Subject: lint: Turn on dogsled --- lib/textui/log.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/textui/log.go') diff --git a/lib/textui/log.go b/lib/textui/log.go index 5ddc7a8..bc8b159 100644 --- a/lib/textui/log.go +++ b/lib/textui/log.go @@ -1,5 +1,5 @@ // Copyright (C) 2019-2022 Ambassador Labs -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: Apache-2.0 // @@ -159,6 +159,7 @@ var ( ) func init() { + //nolint:dogsled // I can't change the signature of the stdlib. _, file, _, _ := runtime.Caller(0) thisModDir = filepath.Dir(filepath.Dir(filepath.Dir(file))) } -- cgit v1.2.3-54-g00ecf From 1faafcd3809fe5b452a1a742137ca2cb7336aad6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 17:39:11 -0700 Subject: lint: Turn on dupword --- .golangci.yml | 7 ++++++- lib/btrfs/btrfsitem/item_uuid.go | 4 ++-- lib/btrfs/btrfssum/csum_test.go | 5 +++-- lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go | 4 ++-- lib/containers/rbtree.go | 10 ++++++---- lib/textui/log.go | 4 ++-- 6 files changed, 21 insertions(+), 13 deletions(-) (limited to 'lib/textui/log.go') diff --git a/.golangci.yml b/.golangci.yml index ea06c75..077a82b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,7 +25,6 @@ linters: # These are disabled not because I think they're bad, but because # they currently don't pass, and I haven't evaluated them yet. - cyclop - - dupword - errorlint - exhaustive - exhaustruct @@ -71,6 +70,12 @@ linters-settings: nolintlint: require-explanation: true require-specific: true + allow-no-explanation: + - dupword issues: + exclude-rules: + # Ignore false positives that don't actually have any words. + - linters: [dupword] + source: "^[^a-zA-Z]*$" max-issues-per-linter: 0 max-same-issues: 0 diff --git a/lib/btrfs/btrfsitem/item_uuid.go b/lib/btrfs/btrfsitem/item_uuid.go index e1a6cf9..5f5f357 100644 --- a/lib/btrfs/btrfsitem/item_uuid.go +++ b/lib/btrfs/btrfsitem/item_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 @@ -12,7 +12,7 @@ import ( ) // The Key for this item is a UUID, and the item is a subvolume IDs -// that that UUID maps to. +// that UUID maps to. // // key.objectid = first half of UUID // key.offset = second half of UUID diff --git a/lib/btrfs/btrfssum/csum_test.go b/lib/btrfs/btrfssum/csum_test.go index d8ccbfc..5c17779 100644 --- a/lib/btrfs/btrfssum/csum_test.go +++ b/lib/btrfs/btrfssum/csum_test.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -22,11 +22,12 @@ func TestCSumFormat(t *testing.T) { } csum := btrfssum.CSum{0xbd, 0x7b, 0x41, 0xf4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} testcases := map[string]TestCase{ + "s": {InputSum: csum, InputFmt: "%s", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, "x": {InputSum: csum, InputFmt: "%x", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, "v": {InputSum: csum, InputFmt: "%v", Output: "bd7b41f400000000000000000000000000000000000000000000000000000000"}, "70s": {InputSum: csum, InputFmt: "|% 70s", Output: "| bd7b41f400000000000000000000000000000000000000000000000000000000"}, - "#180v": {InputSum: csum, InputFmt: "%#180v", Output: " btrfssum.CSum{0xbd, 0x7b, 0x41, 0xf4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}"}, + "#180v": {InputSum: csum, InputFmt: "%#180v", Output: " btrfssum.CSum{0xbd, 0x7b, 0x41, 0xf4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}"}, //nolint:dupword } for tcName, tc := range testcases { tc := tc diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go index 45c9c97..df5ae71 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild_graph.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -113,7 +113,7 @@ func handleItem(o rebuildCallbacks, ctx context.Context, treeID btrfsprim.ObjID, // nothing case btrfsitem.Extent: //if body.Head.Flags.Has(btrfsitem.EXTENT_FLAG_TREE_BLOCK) { - // // Supposedly this flag indicates that that + // // Supposedly this flag indicates that // // body.Info.Key identifies a node by the // // first key in the node. But nothing in the // // kernel ever reads this, so who knows if it diff --git a/lib/containers/rbtree.go b/lib/containers/rbtree.go index e2d8f8a..17bb3e3 100644 --- a/lib/containers/rbtree.go +++ b/lib/containers/rbtree.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -65,9 +65,9 @@ func (node *RBNode[V]) walk(fn func(*RBNode[V]) error) error { } // Search the tree for a value that satisfied the given callbackk -// function. A return value of 0 means to to return this value; <0 -// means to go left on the tree (the value is too high), >0 means to -// go right on th etree (the value is too low). +// function. A return value of 0 means to return this value; <0 means +// to go left on the tree (the value is too high), >0 means to go +// right on th etree (the value is too low). // // +-----+ // | v=8 | == 0 : this is it @@ -287,6 +287,8 @@ func (t *RBTree[K, V]) leftRotate(x *RBNode[V]) { } func (t *RBTree[K, V]) rightRotate(y *RBNode[V]) { + //nolint:dupword + // // | | // +---+ +---+ // | y | | x | diff --git a/lib/textui/log.go b/lib/textui/log.go index bc8b159..0fe03e5 100644 --- a/lib/textui/log.go +++ b/lib/textui/log.go @@ -172,8 +172,8 @@ func (l *logger) log(lvl dlog.LogLevel, writeMsg func(io.Writer)) { // This is optimized for mostly-single-threaded usage. If I cared more // about multi-threaded performance, I'd trade in some // memory-use/allocations and (1) instead of using a static `logBuf`, - // I'd have a `logBufPool` `sync.Pool`, and (2) have the the final call - // to `l.out.Write()` be the only thing protected by `logMu`. + // I'd have a `logBufPool` `sync.Pool`, and (2) have the final call to + // `l.out.Write()` be the only thing protected by `logMu`. logMu.Lock() defer logMu.Unlock() defer logBuf.Reset() -- cgit v1.2.3-54-g00ecf From 6e1a9fbb1e9a943e04902ed3a4958f6821e39456 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 22:41:34 -0700 Subject: lint: Set exclude-use-default=false --- .golangci.yml | 11 +++++++++++ cmd/btrfs-rec/inspect_lsfiles.go | 8 ++++++-- cmd/btrfs-rec/inspect_lstrees.go | 2 +- cmd/btrfs-rec/inspect_spewitems.go | 6 +++--- lib/textui/log.go | 8 ++++---- lib/textui/text.go | 8 ++++---- 6 files changed, 29 insertions(+), 14 deletions(-) (limited to 'lib/textui/log.go') diff --git a/.golangci.yml b/.golangci.yml index d1c1798..6b9a830 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -55,6 +55,9 @@ linters: - varnamelen - wrapcheck linters-settings: + errcheck: + exclude-functions: + - "git.lukeshu.com/btrfs-progs-ng/lib/textui.Fprintf" gci: sections: - standard @@ -74,6 +77,10 @@ linters-settings: gomoddirectives: replace-allow-list: - github.com/jacobsa/fuse + gosec: + excludes: + - G104 # duplicates errcheck + - G304 # this program opens arbitrary files nolintlint: require-explanation: true require-specific: true @@ -83,12 +90,16 @@ linters-settings: checks: - "all" - "-ST1003" # CONST_VAL names for consistency with other btrfs code + - "-ST1000" # TODO: get this to pass + - "-ST1020" # TODO: get this to pass + - "-ST1021" # TODO: get this to pass tagliatelle: case: use-field-name: true rules: json: pascal issues: + exclude-use-default: false exclude-rules: # Ignore false positives that don't actually have any words. - linters: [dupword] diff --git a/cmd/btrfs-rec/inspect_lsfiles.go b/cmd/btrfs-rec/inspect_lsfiles.go index 502d91d..395f60a 100644 --- a/cmd/btrfs-rec/inspect_lsfiles.go +++ b/cmd/btrfs-rec/inspect_lsfiles.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -34,7 +34,11 @@ func init() { }, RunE: func(fs *btrfs.FS, cmd *cobra.Command, _ []string) (err error) { out := bufio.NewWriter(os.Stdout) - defer out.Flush() + defer func() { + if _err := out.Flush(); _err != nil && err == nil { + err = _err + } + }() defer func() { if r := derror.PanicToError(recover()); r != nil { textui.Fprintf(out, "\n\n%+v\n", r) diff --git a/cmd/btrfs-rec/inspect_lstrees.go b/cmd/btrfs-rec/inspect_lstrees.go index 0f70cd1..f74956a 100644 --- a/cmd/btrfs-rec/inspect_lstrees.go +++ b/cmd/btrfs-rec/inspect_lstrees.go @@ -60,7 +60,7 @@ func init() { textui.Fprintf(table, " %v items\t% *s\n", typ, numWidth, strconv.Itoa(treeItemCnt[typ])) } textui.Fprintf(table, " total items\t% *s\n", numWidth, strconv.Itoa(totalItems)) - table.Flush() + _ = table.Flush() } visitedNodes := make(containers.Set[btrfsvol.LogicalAddr]) btrfsutil.WalkAllTrees(ctx, fs, btrfsutil.WalkAllTreesHandler{ diff --git a/cmd/btrfs-rec/inspect_spewitems.go b/cmd/btrfs-rec/inspect_spewitems.go index 8d71797..3b79e8b 100644 --- a/cmd/btrfs-rec/inspect_spewitems.go +++ b/cmd/btrfs-rec/inspect_spewitems.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -39,13 +39,13 @@ func init() { Item: func(path btrfstree.TreePath, item btrfstree.Item) error { textui.Fprintf(os.Stdout, "%s = ", path) spew.Dump(item) - os.Stdout.WriteString("\n") + _, _ = os.Stdout.WriteString("\n") return nil }, BadItem: func(path btrfstree.TreePath, item btrfstree.Item) error { textui.Fprintf(os.Stdout, "%s = ", path) spew.Dump(item) - os.Stdout.WriteString("\n") + _, _ = os.Stdout.WriteString("\n") return nil }, }, diff --git a/lib/textui/log.go b/lib/textui/log.go index 0fe03e5..d2373f8 100644 --- a/lib/textui/log.go +++ b/lib/textui/log.go @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2022 Ambassador Labs +// Copyright (C) 2019-2022-2023 Ambassador Labs // Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: Apache-2.0 @@ -134,21 +134,21 @@ func (l *logger) Log(lvl dlog.LogLevel, msg string) { // UnformattedLog implements dlog.OptimizedLogger. func (l *logger) UnformattedLog(lvl dlog.LogLevel, args ...any) { l.log(lvl, func(w io.Writer) { - printer.Fprint(w, args...) + _, _ = printer.Fprint(w, args...) }) } // UnformattedLogln implements dlog.OptimizedLogger. func (l *logger) UnformattedLogln(lvl dlog.LogLevel, args ...any) { l.log(lvl, func(w io.Writer) { - printer.Fprintln(w, args...) + _, _ = printer.Fprintln(w, args...) }) } // UnformattedLogf implements dlog.OptimizedLogger. func (l *logger) UnformattedLogf(lvl dlog.LogLevel, format string, args ...any) { l.log(lvl, func(w io.Writer) { - printer.Fprintf(w, format, args...) + _, _ = printer.Fprintf(w, format, args...) }) } diff --git a/lib/textui/text.go b/lib/textui/text.go index 615516d..c0a3c5e 100644 --- a/lib/textui/text.go +++ b/lib/textui/text.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -53,7 +53,7 @@ var ( // String implements fmt.Formatter. func (h humanized) Format(f fmt.State, verb rune) { - printer.Fprintf(f, fmtutil.FmtStateString(f, verb), h.val) + _, _ = printer.Fprintf(f, fmtutil.FmtStateString(f, verb), h.val) } // String implements fmt.Stringer. @@ -144,7 +144,7 @@ func (v metric[T]) Format(f fmt.State, verb rune) { if v.Val < 0 { y = -y } - printer.Fprintf(f, fmtutil.FmtStateString(f, verb)+"%s%s", + _, _ = printer.Fprintf(f, fmtutil.FmtStateString(f, verb)+"%s%s", y, prefix, v.Unit) } @@ -192,7 +192,7 @@ func (v iec[T]) Format(f fmt.State, verb rune) { if v.Val < 0 { y = -y } - printer.Fprintf(f, fmtutil.FmtStateString(f, verb)+"%s%s", + _, _ = printer.Fprintf(f, fmtutil.FmtStateString(f, verb)+"%s%s", number.Decimal(y), prefix, v.Unit) } -- cgit v1.2.3-54-g00ecf