diff --git a/CHANGELOG.md b/CHANGELOG.md index 81831bfbbefe..43c2b95e994f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rubocop/cop/style/format_string_token.rb b/lib/rubocop/cop/style/format_string_token.rb index fc9594d3cfe0..77c5e10d9ea4 100644 --- a/lib/rubocop/cop/style/format_string_token.rb +++ b/lib/rubocop/cop/style/format_string_token.rb @@ -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, diff --git a/spec/rubocop/cop/style/format_string_token_spec.rb b/spec/rubocop/cop/style/format_string_token_spec.rb index cc4ae3a89f1b..56bdb0ee8c36 100644 --- a/spec/rubocop/cop/style/format_string_token_spec.rb +++ b/spec/rubocop/cop/style/format_string_token_spec.rb @@ -81,6 +81,10 @@ end end + it 'ignores percent escapes' do + expect_no_offenses("format('%6.2f%%', hit_rate: 12.34)") + end + it 'ignores xstr' do expect_no_offenses('`echo "%s %s %{template}"`') end