Skip to content

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

Closed
@MrDOS

Description

@MrDOS

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.

Activity

self-assigned this
on Apr 15, 2021
added a commit that references this issue on Apr 16, 2021
15774da
tommy-muehle

tommy-muehle commented on Apr 16, 2021

@tommy-muehle
Owner

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

MrDOS

MrDOS commented on Apr 16, 2021

@MrDOS
Author

Thanks!

added a commit that references this issue on Nov 30, 2024
19bf57c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

false positiveMistaken result of a scientific test

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @MrDOS@tommy-muehle

      Issue actions

        Literals in type conversions in block declarations should be okay · Issue #22 · tommy-muehle/go-mnd