Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literals in type conversions in block declarations should be okay #22

Closed
MrDOS opened this issue Mar 29, 2021 · 2 comments
Closed

Literals in type conversions in block declarations should be okay #22

MrDOS opened this issue Mar 29, 2021 · 2 comments
Assignees
Labels
false positive Mistaken result of a scientific test

Comments

@MrDOS
Copy link

MrDOS commented Mar 29, 2021

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.

@tommy-muehle tommy-muehle self-assigned this Apr 15, 2021
@tommy-muehle tommy-muehle added the false positive Mistaken result of a scientific test label Apr 15, 2021
@tommy-muehle
Copy link
Owner

@MrDOS
Thanks for the report! Good catch. I fixed it and will release a new version soon.

@MrDOS
Copy link
Author

MrDOS commented Apr 16, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false positive Mistaken result of a scientific test
Projects
None yet
Development

No branches or pull requests

2 participants