Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #10203] Fix Style/FormatStringToken to respect IgnoredMethods with nested structures #10235

Merged
merged 1 commit into from Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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