Skip to content

Commit

Permalink
[Fix rubocop#3272] Add escape character missing to LITERAL_REGEX
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke committed Jul 6, 2016
1 parent 1d71c51 commit 7eb0919
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### Changes

* [#3230](https://github.com/bbatsov/rubocop/issues/3230): Improve highlighting for `Style/AsciiComments` cop. ([@drenmi][])
* [#3272](https://github.com/bbatsov/rubocop/issues/3272): Add escape character missing to LITERAL_REGEX. ([@pocke][])

## 0.41.1 (2016-06-26)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Util

# Match literal regex characters, not including anchors, character
# classes, alternatives, groups, repetitions, references, etc
LITERAL_REGEX = /[\w\s\-,"'!#%&<>=;:`~]|\\[^AbBdDgGkwWszZS0-9]/
LITERAL_REGEX = /[\w\s\-,"'!#%&<>=;:`~]|\\[^AbBdDgGhHkpPRwWXsSzZS0-9]/

module_function

Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/performance/end_with_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
end

# character classes, anchors
%w(w W s S d D A Z z G b B).each do |str|
%w(w W s S d D A Z z G b B h H R X S).each do |str|
it "doesn't register an error for #{method} /\\#{str}\\z/" do
inspect_source(cop, "str#{method} /\\#{str}\\z/")
expect(cop.messages).to be_empty
end
end

# characters with no special meaning whatsoever
%w(h i j l m o q y).each do |str|
%w(i j l m o q y).each do |str|
it "autocorrects #{method} /\\#{str}\\z/" do
new_source = autocorrect_source(cop, "str#{method} /\\#{str}\\z/")
expect(new_source).to eq "str.end_with?('#{str}')"
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/performance/start_with_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
end

# character classes, anchors
%w(w W s S d D A Z z G b B).each do |str|
%w(w W s S d D A Z z G b B h H R X S).each do |str|
it "doesn't register an error for #{method} /\\A\\#{str}/" do
inspect_source(cop, "str#{method} /\\A\\#{str}/")
expect(cop.messages).to be_empty
end
end

# characters with no special meaning whatsoever
%w(h i j l m o q y).each do |str|
%w(i j l m o q y).each do |str|
it "autocorrects #{method} /\\A\\#{str}/" do
new_source = autocorrect_source(cop, "str#{method} /\\A\\#{str}/")
expect(new_source).to eq "str.start_with?('#{str}')"
Expand Down

0 comments on commit 7eb0919

Please sign in to comment.