Import Name Collision

ID

go.import_name_collision

Severity

low

Remediation Complexity

simple

Remediation Risk

medium

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

reliability

Description

Reports a declared variable, constant, function or type whose name equals an imported package’s local name.

Rationale

The declaration shadows the package within its scope, so any later reference to fmt.X fails to compile or silently resolves to the local symbol — a confusing, easily-missed bug. Method receivers and parameters are excluded, since their shadowing is local and conventional.

import "fmt"

// Bad
var fmt = "x" // FLAW — shadows the fmt package

// Good
var format = "x" // OK

Remediation

Rename the declaration (or alias the import) so the two names no longer clash.