Closed
Description
Thank you for creating/maintaining this tool. Very useful!
Short summary
When declaring a literal const or var with a type conversion in a block, mnd detects the argument of the type conversion as a magic number. This happens only when type conversions are used in block declarations: inline/standalone declarations don't trip up the detection.
Steps to reproduce the behavior
In main.go
:
package main
// Could also be `var`.
const (
// FooBlockLiteral is okay.
FooBlockLiteral = 512
// FooBlockTypeConversion trips up mnd:
//
// Magic number: 512, in <argument> detected
FooBlockTypeConversion = int64(512)
)
// FooLiteral is okay.
const FooLiteral = 512
// FooTypeConversion is also okay.
const FooTypeConversion = int64(512)
In go.mod
:
module mnd-test
go 1.16
Then:
$ mnd .
/path/to/mnd-test/main.go:9:33: Magic number: 512, in <argument> detected
go-mnd version or commit ref
v2.3.1
Go version (output of 'go version')
go version go1.16.2 linux/amd64
Operating system / Environment
Debian 10.
Expected behavior
No/clean output from mnd
:
$ mnd .
Actual behavior
See the error in the reproduction steps.
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Don't report type conversions in const block declarations, fixes #22
tommy-muehle commentedon Apr 16, 2021
@MrDOS
Thanks for the report! Good catch. I fixed it and will release a new version soon.
MrDOS commentedon Apr 16, 2021
Thanks!
Don't report type conversions in const block declarations, fixes tomm…