go-mnd icon indicating copy to clipboard operation
go-mnd copied to clipboard

`strconv.FormatInt` or `strconv.FormatUint` and magic numbers ?

Open butuzov opened this issue 3 years ago • 9 comments

Become curious: should any number (within consition 2 <= n <= 36) be considered as magic number if used in strconv.FormatInt or strconv.FormatUint ?

butuzov avatar Sep 01 '21 13:09 butuzov

I have the same issue with strconv.ParseFloat, where the argument bitSize is considered as magic number even though the only two valid values are 32 and 64.

breml avatar Sep 22 '21 05:09 breml

@butuzov @breml

got same issue with gomnd / staticcheck

.....go:413:53: mnd: Magic number: 64, in <argument> detected (gomnd)
                lon, err := strconv.ParseFloat(*addr.Data.GeoLon, 64)
                                                                  ^
....go:91:43: SA1030: 'fmt' argument is invalid: unknown format '\n' (staticcheck)
		lat := strconv.FormatFloat(*ts.Lot.Lat, 10, 5, 64)
		                                        ^

Rollback to golangci-lint v1.40.1 helped

  1. remove currently installed golangci-lint
  2. install v1.40.1 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.40.1

solokirrik avatar Nov 09 '21 10:11 solokirrik

@solokirrik bad advice considering improvements in 1.43 and backwards compatibility for go versions.

butuzov avatar Nov 09 '21 10:11 butuzov

@butuzov agree, but that's how it works now wo PR in go-mnd

solokirrik avatar Nov 09 '21 11:11 solokirrik

Before PR we might need a comment from @tommy-muehle.

butuzov avatar Nov 09 '21 11:11 butuzov

and looks like a way to ignore such patterns was just added

butuzov avatar Nov 09 '21 11:11 butuzov

@tommy-muehle could you please tag a new version with built-in functions fix? #29

solokirrik avatar Jan 17 '22 10:01 solokirrik

+1 to @solokirrik, because support to ignored-functions just landed to golangci-lint json schema (but not golangci-lint itself)

butuzov avatar Jan 17 '22 12:01 butuzov

Sure. Thanks for the heads up @solokirrik @butuzov !

tommy-muehle avatar Jan 17 '22 21:01 tommy-muehle