redefines-builtin-id
What it does
Section titled “What it does”Reports a variable, constant, function, parameter, named result or type parameter that has the name of a predeclared identifier (len, new, string, nil, max, …); a name on the left of an assignment counts too. A method and a receiver are not reported. The options allow, kinds, except_parents and assigned_by change what is checked.
Why it matters
Section titled “Why it matters”The name hides the built-in in that scope, so a later len(x) or string(b) calls the new thing or fails to compile far from the declaration. The code works until somebody needs the built-in in the same scope, and then the error is hard to understand.
To fix, rename the declaration.
Example
Section titled “Example”package a
var len = 1
const iota = 2
func new() {}
func f(copy int, s string) (error int) { max := 1 min = 2 _, print := 1, 2 return}
func (string T) method() {}
func g[any int]() {}Configuration
Section titled “Configuration”go: lint: rules: redefines-builtin-id: level: warn # off (default), warn, error options: allow: [] kinds: [] except_parents: ["ReceiverList"] assigned_by: ["AssignmentStatement"]python: lint: rules: redefines-builtin-id: level: warn # off (default), warn, error options: allow: [] kinds: [] except_parents: ["ReceiverList"] assigned_by: ["AssignmentStatement"]| Option | Type | Default | Description |
|---|---|---|---|
allow |
list | [] |
Names that may be declared. |
kinds |
list | [] |
The declarations that are checked (empty: all). Values: variable, parameter, function, class, import, type |
except_parents |
list | ["ReceiverList"] |
Grammar kinds whose direct declarations are left out (a receiver). |
assigned_by |
list | ["AssignmentStatement"] |
Grammar kinds of statements whose left-side names are reported too (len = 1, max += 1). |
Enabled by the presets: go/revive.
Suppress one line with sudsy-disable-next-line redefines-builtin-id in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| revive | redefines-builtin-id |
full |
| ruff | A001 |
full |
| ruff | A002 |
full |