Skip to content

Commit

Permalink
Use regexp argument instead of redundant equality comparison block
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Mar 16, 2023
1 parent 2033fa5 commit 43209b3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/redundant_cop_disable_directive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def trailing_range?(ranges, range)
.drop_while { |r| !r.equal?(range) }
.each_cons(2)
.map { |range1, range2| range1.end.join(range2.begin).source }
.all? { |intervening| /\A\s*,\s*\Z/.match?(intervening) }
.all?(/\A\s*,\s*\z/)
end

SIMILAR_COP_NAMES_CACHE = Hash.new do |hash, cop_name|
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/document_dynamic_eval_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def comment_block_docs?(arg_node)
return if comments.none?

regexp = comment_regexp(arg_node)
comments.any? { |comment| regexp.match?(comment) } || regexp.match?(comments.join)
comments.any?(regexp) || regexp.match?(comments.join)
end

def preceding_comment_blocks(node)
Expand Down
5 changes: 2 additions & 3 deletions lib/rubocop/cop/style/percent_literal_delimiters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ def include_same_character_as_used_for_delimiter?(node, type)

def contains_delimiter?(node, delimiters)
delimiters_regexp = Regexp.union(delimiters)
node
.children.map { |n| string_source(n) }.compact
.any? { |s| delimiters_regexp.match?(s) }

node.children.map { |n| string_source(n) }.compact.any?(delimiters_regexp)
end

def string_source(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/redundant_percent_q.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def acceptable_q?(node)

return true if STRING_INTERPOLATION_REGEXP.match?(src)

src.scan(/\\./).any? { |s| ESCAPED_NON_BACKSLASH.match?(s) }
src.scan(/\\./).any?(ESCAPED_NON_BACKSLASH)
end

def acceptable_capital_q?(node)
Expand Down

0 comments on commit 43209b3

Please sign in to comment.