Skip to content

Commit

Permalink
Merge pull request #10235 from tejasbubane/fix-10203
Browse files Browse the repository at this point in the history
[Fix #10203] Fix `Style/FormatStringToken` to respect `IgnoredMethods` with nested structures
  • Loading branch information
dvandersluis committed Nov 5, 2021
2 parents df440de + 7531811 commit ddc74de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
@@ -0,0 +1 @@
* [#10203](https://github.com/rubocop/rubocop/issues/10203): Fix `Style/FormatStringToken` to respect `IgnoredMethods` with nested structures. ([@tejasbubane][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/format_string_token.rb
Expand Up @@ -102,7 +102,8 @@ def format_string_token?(node)
end

def use_ignored_method?(node)
(parent = node.parent) && parent.send_type? && ignored_method?(parent.method_name)
send_parent = node.each_ancestor(:send).first
send_parent && ignored_method?(send_parent.method_name)
end

def unannotated_format?(node, detected_style)
Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/style/format_string_token_spec.rb
Expand Up @@ -261,6 +261,19 @@
redirect("%{foo}")
RUBY
end

it 'does not register an offense for value in nested structure' do
expect_no_offenses(<<~RUBY)
redirect("%{foo}", bye: "%{foo}")
RUBY
end

it 'registers an offense for different method call within ignored method' do
expect_offense(<<~RUBY)
redirect("%{foo}", bye: foo("%{foo}"))
^^^^^^ Prefer annotated tokens (like `%<foo>s`) over template tokens (like `%{foo}`).
RUBY
end
end

context 'when `IgnoredMethods: []`' do
Expand Down

0 comments on commit ddc74de

Please sign in to comment.