Skip to content

redundant-string-coercion

Rubysuspiciousno fixdefault: offruby/rubocop

Reports to_s on the last expression of a #{...} and on an argument of puts, print or warn.

Interpolation and these methods already convert the value with to_s, so the call adds nothing.

To fix, delete .to_s.

Reported
...
2.times { f }
...
puts "#{x.to_s} #{y}"
puts x.to_s, y
...
a == b
ruby:
lint:
rules:
redundant-string-coercion: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line redundant-string-coercion 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/RedundantStringCoercion full