Skip to content

Style/RedundantFormat gives doubly inconsistent advice #14604

@forthrin

Description

@forthrin

Steps to reproduce the problem

%w[you sunshine].each do
  puts  format '(%16s)',   "Hello #{it}" # Style/RedundantFormat
  print format "(%16s)\n", "Hello #{it}" # Style/RedundantFormat
  printf       "(%16s)\n", "Hello #{it}" # Identical, but no cop
  puts "(     Hello #{it})"              # Suggestion, different
  puts
end

Expected behavior

Not being pulled over.

Actual behavior

(       Hello you)
(       Hello you)
(       Hello you)
(     Hello you)

(  Hello sunshine)
(  Hello sunshine)
(  Hello sunshine)
(     Hello sunshine)

-:2:9: C: [Correctable] Style/RedundantFormat: Use "(     Hello #{it})" directly instead of format.
  puts  format '(%16s)',   "Hello #{it}" # Style/RedundantFormat
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-:3:9: C: [Correctable] Style/RedundantFormat: Use "(     Hello #{it})
" directly instead of format.
  print format "(%16s)\n", "Hello #{it}" # Style/RedundantFormat
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Side issue: Control characters should appear as originally written (\n in this instance)

RuboCop version

ruby      2025-08-01 30a20bc16
rubocop   2025-10-15 473598c90
System Version: macOS 15.6 (24G84)
Model Identifier: MacBookAir10,1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions