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 #7439] Ignore percent escapes #7440

Merged
merged 1 commit into from Oct 17, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#7439](https://github.com/rubocop-hq/rubocop/issues/7439): Make `Style/FormatStringToken` ignore percent escapes (`%%`). ([@buehmann][])

## 0.75.1 (2019-10-14)

### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/style/format_string_token.rb
Expand Up @@ -104,6 +104,8 @@ def token_ranges(contents)
format_string = RuboCop::Cop::Utils::FormatString.new(contents.source)

format_string.format_sequences.each do |seq|
next if seq.percent?

detected_style = seq.style
token = contents.begin.adjust(
begin_pos: seq.begin_pos,
Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/style/format_string_token_spec.rb
Expand Up @@ -81,6 +81,10 @@
end
end

it 'ignores percent escapes' do
expect_no_offenses("format('%<hit_rate>6.2f%%', hit_rate: 12.34)")
end

it 'ignores xstr' do
expect_no_offenses('`echo "%s %<annotated>s %{template}"`')
end
Expand Down