Skip to content

Commit

Permalink
Use Regexp option predicate from rubocop-ast
Browse files Browse the repository at this point in the history
  • Loading branch information
owst committed Jun 4, 2020
1 parent b52b6e4 commit 513811b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 25 deletions.
1 change: 0 additions & 1 deletion lib/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
require_relative 'rubocop/cop/mixin/preceding_following_alignment'
require_relative 'rubocop/cop/mixin/preferred_delimiters'
require_relative 'rubocop/cop/mixin/rational_literal'
require_relative 'rubocop/cop/mixin/regexp_literal_help'
require_relative 'rubocop/cop/mixin/rescue_node'
require_relative 'rubocop/cop/mixin/safe_assignment'
require_relative 'rubocop/cop/mixin/space_after_punctuation'
Expand Down
16 changes: 0 additions & 16 deletions lib/rubocop/cop/mixin/regexp_literal_help.rb

This file was deleted.

7 changes: 3 additions & 4 deletions lib/rubocop/cop/style/redundant_regexp_character_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module Style
# r = /[ab]/
class RedundantRegexpCharacterClass < Cop
include MatchRange
include RegexpLiteralHelp

MSG_REDUNDANT_CHARACTER_CLASS = 'Redundant single-element character class, ' \
'`%<char_class>s` can be replaced with `%<element>s`.'
Expand All @@ -44,7 +43,7 @@ class RedundantRegexpCharacterClass < Cop

def on_regexp(node)
each_redundant_character_class(node) do |loc|
next if whitespace_in_free_space_mode?(node, loc)
next if whitespace_in_extended_regexp?(node, loc)

add_offense(
node,
Expand Down Expand Up @@ -78,8 +77,8 @@ def without_character_class(loc)
loc.source[1..-2]
end

def whitespace_in_free_space_mode?(node, loc)
return false unless freespace_mode_regexp?(node)
def whitespace_in_extended_regexp?(node, loc)
return false unless node.extended?

/\[\s\]/.match?(loc.source)
end
Expand Down
5 changes: 1 addition & 4 deletions lib/rubocop/cop/style/redundant_regexp_escape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Style
# /[+\-]\d/
class RedundantRegexpEscape < Cop
include RangeHelp
include RegexpLiteralHelp

MSG_REDUNDANT_ESCAPE = 'Redundant escape inside regexp literal'

Expand Down Expand Up @@ -111,12 +110,10 @@ def escape_range_at_index(node, index)
end

def pattern_source(node)
freespace_mode = freespace_mode_regexp?(node)

node.children.reject(&:regopt_type?).map do |child|
source = child.source

if freespace_mode
if node.extended?
# Remove comments to avoid misleading results
source.sub(/(?<!\\)#.*/, '')
else
Expand Down

0 comments on commit 513811b

Please sign in to comment.