Skip to content

underscore-prefixed-variable-used

Rubystyleno fixdefault: offruby/rubocop

Reports a variable whose name starts with _, which says it is unused, but that is read. No fix.

A leading underscore tells the reader that the value is ignored. Reading it breaks that promise, and the next editor may remove the variable or the argument as unused.

To fix, drop the underscore, or stop reading the variable.

Reported
def a(x, y)
...
_w = y
puts _w
x
end
...
ruby:
lint:
rules:
underscore-prefixed-variable-used: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line underscore-prefixed-variable-used in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/UnderscorePrefixedVariableName full