Skip to content

Commit

Permalink
[Fix rubocop#7439] Ignore percent escapes
Browse files Browse the repository at this point in the history
`%%` is technically a format sequence in the `unannotated` style. But it
cannot be written in another style in a sensible way.
  • Loading branch information
buehmann committed Oct 17, 2019
1 parent ef25ea2 commit 8264e32
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
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

0 comments on commit 8264e32

Please sign in to comment.