Skip to content

Commit

Permalink
Fix an error for Style/RedundantFormat
Browse files Browse the repository at this point in the history
Follow-up to #13844 (comment).

This PR fixes an error for `Style/RedundantFormat`
when numeric placeholders is used in the template argument.
  • Loading branch information
koic authored and bbatsov committed Feb 17, 2025
1 parent b573711 commit 241fe6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_style_redundant_format_cop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#13857](https://github.com/rubocop/rubocop/pull/13857): Fix an error for `Style/RedundantFormat` when numeric placeholders is used in the template argument. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/redundant_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def matching_argument?(sequence, argument)
end

def numeric?(argument)
argument.type?(:numeric, :str) ||
argument&.type?(:numeric, :str) ||
rational_number?(argument) ||
complex_number?(argument)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/style/redundant_format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@
#{method}('%{foo}', foo)
RUBY
end

it 'does not register an offense when given numeric placeholders in the template argument' do
expect_no_offenses(<<~RUBY)
#{method}('%<placeholder>d, %<placeholder>f', placeholder)
RUBY
end
end

context 'with an interpolated format string' do
Expand Down

0 comments on commit 241fe6b

Please sign in to comment.