Skip to content

literal-in-interpolation

Rubysuspiciousno fixdefault: offruby/rubocop

Reports a number, symbol, true, false, nil or string literal that is the whole content of a #{...}.

A literal does not need interpolation, and in "a #{1}" the value is known to the reader. Often it is a leftover of an expression that was replaced by a constant.

To fix, write the literal in the string itself.

Reported
...
y = :ok
...
"a #{1} #{x} #{[:a]}"
...
/(?<a>x)(?:y)/
...
ruby:
lint:
rules:
literal-in-interpolation: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line literal-in-interpolation 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/LiteralInInterpolation full