Repository: lightningnetwork/lnd
Pull request #7335 (2023-01-17 18:21:27)

lint: disable gomnd
Fix the annoying "magic number" linter.


Patch:
diff --git a/.golangci.yml b/.golangci.yml
index 7b97fee00..40dca985e 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -184,6 +184,10 @@ linters:
     # call t.Helper() within those functions, we lose the information where
     # exactly a test failed in the generated failure stack trace.
     - thelper
+    
+    # The linter is too aggressive and doesn't add much value since reviewers
+    # will also catch magic numbers that make sense to extract.
+    - gomnd
 
 
 issues:
diff --git a/channeldb/invoices.go b/channeldb/invoices.go
index c05776eb5..14084b55c 100644
--- a/channeldb/invoices.go
+++ b/channeldb/invoices.go
@@ -1380,7 +1380,7 @@ func decodeCircuitKeys(r io.Reader, val interface{}, buf *[8]byte,
 
 			key.ChanID = lnwire.NewShortChanIDFromInt(scid)
 
-			err := tlv.DUint64(r, &key.HtlcID, buf, 8) //nolint:gomnd,lll
+			err := tlv.DUint64(r, &key.HtlcID, buf, 8)
 			if err != nil {
 				return err
 			}
@@ -1450,7 +1450,7 @@ func ampStateEncoder(w io.Writer, val interface{}, buf *[8]byte) error {
 						keys := ampState.InvoiceKeys
 						numKeys := uint64(len(keys))
 						size := tlv.VarIntSize(numKeys)
-						dataSize := (numKeys * 16) //nolint:gomnd,lll
+						dataSize := (numKeys * 16)
 
 						return size + dataSize
 					},
diff --git a/cmd/lncli/cmd_payments.go b/cmd/lncli/cmd_payments.go
index a7ac1802d..923f65b4c 100644
--- a/cmd/lncli/cmd_payments.go
+++ b/cmd/lncli/cmd_payments.go
@@ -1653,7 +1653,6 @@ func clearLines(count int) {
 
 // ordinalNumber returns the ordinal number as a string of a number.
 func ordinalNumber(num uint32) string {
-	//nolint:gomnd
 	switch num {
 	case 1:
 		return "1st"
diff --git a/docs/release-notes/release-notes-0.16.0.md b/docs/release-notes/release-notes-0.16.0.md
index 1146051de..563a8b23a 100644
--- a/docs/release-notes/release-notes-0.16.0.md
+++ b/docs/release-notes/release-notes-0.16.0.md
@@ -336,7 +336,8 @@ data.
 * [`golangci-lint` will now check new code using additional
   linters](https://github.com/lightningnetwork/lnd/pull/7064) and was
   [fine-tuned](https://github.com/lightningnetwork/lnd/pull/7289) to fit our
-  code style.
+  code style or to [disable annoying new
+  linters](https://github.com/lightningnetwork/lnd/pull/7335).
 
 * Update github actions to [check commits against the target base 
   branch](https://github.com/lightningnetwork/lnd/pull/7103) rather than just 
diff --git a/watchtower/wtdb/migration4/client_db.go b/watchtower/wtdb/migration4/client_db.go
index 0dcb499c8..923380490 100644
--- a/watchtower/wtdb/migration4/client_db.go
+++ b/watchtower/wtdb/migration4/client_db.go
@@ -148,9 +148,8 @@ func migrateAckedUpdates(db kvdb.Backend, sessionsPerTx int) error {
 
 		// Calculate and log the progress if the progress is less than
 		// one hundred percent.
-		//nolint:gomnd
 		progress := float64(migrated) / float64(total) * 100
-		if progress >= 100 { //nolint:gomnd
+		if progress >= 100 {
 			break
 		}
 
diff --git a/watchtower/wtdb/migration4/range_index.go b/watchtower/wtdb/migration4/range_index.go
index 79793ce24..9386834e0 100644
--- a/watchtower/wtdb/migration4/range_index.go
+++ b/watchtower/wtdb/migration4/range_index.go
@@ -208,7 +208,7 @@ func (a *RangeIndex) lowerBoundIndex(n uint64) (int, bool) {
 		rangeIndex = -1
 	)
 	for {
-		mid := (low + high) / 2 //nolint: gomnd
+		mid := (low + high) / 2
 		currentRange := a.set[mid]
 
 		switch {
diff --git a/watchtower/wtdb/range_index.go b/watchtower/wtdb/range_index.go
index 77d09f645..268b603c7 100644
--- a/watchtower/wtdb/range_index.go
+++ b/watchtower/wtdb/range_index.go
@@ -208,7 +208,7 @@ func (a *RangeIndex) lowerBoundIndex(n uint64) (int, bool) {
 		rangeIndex = -1
 	)
 	for {
-		mid := (low + high) / 2 //nolint: gomnd
+		mid := (low + high) / 2
 		currentRange := a.set[mid]
 
 		switch {


Test patch:
diff --git a/invoices/test_utils.go b/invoices/test_utils.go
index dc83fa253..2a80795a4 100644
--- a/invoices/test_utils.go
+++ b/invoices/test_utils.go
@@ -64,7 +64,7 @@ var (
 
 	testInvoiceDescription = "coffee"
 
-	testInvoiceAmount = lnwire.MilliSatoshi(100000) //nolint:gomnd
+	testInvoiceAmount = lnwire.MilliSatoshi(100000)
 
 	testNetParams = &chaincfg.MainNetParams
 
@@ -152,7 +152,7 @@ func generateInvoiceExpiryTestData(
 	for i := 1; i <= numExpired; i++ {
 		var preimage lntypes.Preimage
 		binary.BigEndian.PutUint32(preimage[:4], uint32(offset+i))
-		duration := (i + offset) % 24 //nolint:gomnd
+		duration := (i + offset) % 24
 		expiry := time.Duration(duration) * time.Hour
 		invoice := newTestInvoice(
 			t, preimage, expiredCreationDate, expiry,
@@ -163,7 +163,7 @@ func generateInvoiceExpiryTestData(
 	for i := 1; i <= numPending; i++ {
 		var preimage lntypes.Preimage
 		binary.BigEndian.PutUint32(preimage[4:], uint32(offset+i))
-		duration := (i + offset) % 24 //nolint:gomnd
+		duration := (i + offset) % 24
 		expiry := time.Duration(duration) * time.Hour
 		invoice := newTestInvoice(t, preimage, now, expiry)
 		testData.pendingInvoices[preimage.Hash()] = invoice