Skip to main content

var-shadows-builtin

Summary: Variable shadows built-in

Category: Bugs

Avoid

package policy

# variable `http` shadows `http.send` built-in function
allow if {
http := startswith(input.url, "http://")
# do something with http
}

Prefer

package policy

# variable `is_http` doesn't shadow any built-in function
allow if {
is_http := startswith(input.url, "http://")
# do something with is_http
}

Rationale

Using the name of built-in functions or operators as variable names can lead to confusion and unexpected behavior. A variable that shadows a built-in function (or the namespace of a function, like http in http.send) prevents any function in that namespace to be used later in the rule. Avoid this!

Configuration Options

This linter rule provides the following configuration options:

rules:
bugs:
var-shadows-builtin:
# one of "error", "warning", "ignore"
level: error