Skip to content

Commit

Permalink
Merge pull request #8024 from andrykonchin/use-match-method
Browse files Browse the repository at this point in the history
Use Regexp/String method #match? instead of #match
  • Loading branch information
koic committed May 25, 2020
2 parents 42ea792 + 8007f8e commit a3ebf71
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/comment_config.rb
Expand Up @@ -124,7 +124,7 @@ def each_mentioned_cop
end

def directive_on_comment_line?(comment)
comment.text[1..-1].match(COMMENT_DIRECTIVE_REGEXP)
comment.text[1..-1].match?(COMMENT_DIRECTIVE_REGEXP)
end

def each_directive
Expand Down
Expand Up @@ -129,7 +129,7 @@ def arg_to_unparenthesized_call?
end

def separating_space?
block_begin.source_buffer.source[block_begin.begin_pos + 2].match(/\s/)
block_begin.source_buffer.source[block_begin.begin_pos + 2].match?(/\s/)
end
end
end
Expand Down
Expand Up @@ -190,7 +190,7 @@ def incorrect_parenthesis_removal_begin(node)
def safe_to_remove_line_containing_closing_paren?(node)
last_line = processed_source[node.loc.end.line - 1]
# Safe to remove if last line only contains `)`, `,`, and whitespace.
last_line.match(/^[ ]*\)[ ]{0,20},{0,1}[ ]*$/)
last_line.match?(/^[ ]*\)[ ]{0,20},{0,1}[ ]*$/)
end

def incorrect_parenthesis_removal_end(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/nested_percent_literal.rb
Expand Up @@ -42,7 +42,7 @@ def on_percent_literal(node)
def contains_percent_literals?(node)
node.each_child_node.any? do |child|
literal = child.children.first.to_s.scrub
REGEXES.any? { |regex| literal.match(regex) }
REGEXES.any? { |regex| literal.match?(regex) }
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/migration/department_name.rb
Expand Up @@ -64,8 +64,8 @@ def check_cop_name(name, comment, offset)
end

def valid_content_token?(content_token)
!/\W+/.match(content_token).nil? ||
!DISABLING_COPS_CONTENT_TOKEN.match(content_token).nil?
/\W+/.match?(content_token) ||
DISABLING_COPS_CONTENT_TOKEN.match?(content_token)
end

def contain_unexpected_character_for_department_name?(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/configurable_formatting.rb
Expand Up @@ -23,7 +23,7 @@ def report_opposing_styles(node, name)
end

def valid_name?(node, name, given_style = style)
name.match(self.class::FORMATS.fetch(given_style)) ||
name.match?(self.class::FORMATS.fetch(given_style)) ||
class_emitter_method?(node, name)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/ignored_pattern.rb
Expand Up @@ -18,7 +18,7 @@ def ignored_line?(line)
end

def matches_ignored_pattern?(line)
ignored_patterns.any? { |pattern| Regexp.new(pattern).match(line) }
ignored_patterns.any? { |pattern| Regexp.new(pattern).match?(line) }
end

def ignored_patterns
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/line_length_help.rb
Expand Up @@ -18,7 +18,7 @@ def directive_on_source_line?(line_index)

return false unless comment

comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
comment.text.match?(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
end

def allow_uri?
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/naming/predicate_name.rb
Expand Up @@ -67,7 +67,7 @@ def on_def(node)
private

def allowed_method_name?(method_name, prefix)
!method_name.match(/^#{prefix}[^0-9]/) ||
!method_name.match?(/^#{prefix}[^0-9]/) ||
method_name == expected_name(method_name, prefix) ||
method_name.end_with?('=') ||
allowed_methods.include?(method_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/inline_comment.rb
Expand Up @@ -23,7 +23,7 @@ class InlineComment < Cop
def investigate(processed_source)
processed_source.each_comment do |comment|
next if comment_line?(processed_source[comment.loc.line - 1]) ||
comment.text.match(/\A# rubocop:(enable|disable)/)
comment.text.match?(/\A# rubocop:(enable|disable)/)

add_offense(comment)
end
Expand Down

0 comments on commit a3ebf71

Please sign in to comment.