Skip to content

Commit 241fe6b

Browse files
koicbbatsov
authored andcommitted
Fix an error for Style/RedundantFormat
Follow-up to #13844 (comment). This PR fixes an error for `Style/RedundantFormat` when numeric placeholders is used in the template argument.
1 parent b573711 commit 241fe6b

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

lib/rubocop/cop/style/redundant_format.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def matching_argument?(sequence, argument)
160160
end
161161

162162
def numeric?(argument)
163-
argument.type?(:numeric, :str) ||
163+
argument&.type?(:numeric, :str) ||
164164
rational_number?(argument) ||
165165
complex_number?(argument)
166166
end

spec/rubocop/cop/style/redundant_format_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@
314314
#{method}('%{foo}', foo)
315315
RUBY
316316
end
317+
318+
it 'does not register an offense when given numeric placeholders in the template argument' do
319+
expect_no_offenses(<<~RUBY)
320+
#{method}('%<placeholder>d, %<placeholder>f', placeholder)
321+
RUBY
322+
end
317323
end
318324

319325
context 'with an interpolated format string' do

0 commit comments

Comments
 (0)