rubocop 0.85.1 → 0.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -4
  3. data/config/default.yml +29 -1
  4. data/lib/rubocop.rb +3 -0
  5. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  6. data/lib/rubocop/config.rb +1 -1
  7. data/lib/rubocop/config_loader_resolver.rb +1 -1
  8. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
  9. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  10. data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
  11. data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
  12. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +2 -0
  13. data/lib/rubocop/cop/layout/end_of_line.rb +1 -1
  14. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  15. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
  16. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
  17. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  18. data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
  19. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  20. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  21. data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
  22. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -1
  23. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  24. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
  25. data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
  26. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  27. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +6 -1
  28. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  29. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  30. data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
  31. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +4 -2
  32. data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
  33. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
  34. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
  35. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  36. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
  37. data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
  38. data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
  39. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  40. data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
  41. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  42. data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
  43. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
  44. data/lib/rubocop/cop/mixin/range_help.rb +1 -1
  45. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +27 -0
  46. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  47. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
  48. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  49. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +2 -2
  50. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  51. data/lib/rubocop/cop/naming/file_name.rb +1 -3
  52. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  53. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  54. data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
  55. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  56. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  57. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  58. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  59. data/lib/rubocop/cop/style/copyright.rb +3 -3
  60. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
  61. data/lib/rubocop/cop/style/documentation.rb +2 -2
  62. data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
  63. data/lib/rubocop/cop/style/encoding.rb +1 -1
  64. data/lib/rubocop/cop/style/exponential_notation.rb +2 -2
  65. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  66. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  67. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  68. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  69. data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
  70. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  71. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
  72. data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
  73. data/lib/rubocop/cop/style/next.rb +2 -2
  74. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
  75. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  76. data/lib/rubocop/cop/style/redundant_fetch_block.rb +103 -0
  77. data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
  78. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
  79. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
  80. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +14 -23
  81. data/lib/rubocop/cop/style/redundant_self.rb +6 -9
  82. data/lib/rubocop/cop/style/sample.rb +1 -1
  83. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  84. data/lib/rubocop/cop/style/struct_inheritance.rb +21 -0
  85. data/lib/rubocop/cop/style/symbol_array.rb +5 -5
  86. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  87. data/lib/rubocop/cop/style/word_array.rb +1 -1
  88. data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
  89. data/lib/rubocop/cop/util.rb +2 -2
  90. data/lib/rubocop/cop/utils/format_string.rb +1 -1
  91. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  92. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  93. data/lib/rubocop/name_similarity.rb +6 -0
  94. data/lib/rubocop/path_util.rb +2 -2
  95. data/lib/rubocop/platform.rb +1 -1
  96. data/lib/rubocop/rspec/expect_offense.rb +12 -2
  97. data/lib/rubocop/target_finder.rb +1 -1
  98. data/lib/rubocop/target_ruby.rb +1 -1
  99. data/lib/rubocop/version.rb +1 -1
  100. metadata +11 -2
@@ -25,7 +25,7 @@ module RuboCop
25
25
  value, = *node
26
26
 
27
27
  return unless value.infinite? ||
28
- value.zero? && node.source =~ /[1-9]/
28
+ value.zero? && /[1-9]/.match?(node.source)
29
29
 
30
30
  add_offense(node)
31
31
  end
@@ -65,7 +65,12 @@ module RuboCop
65
65
  end
66
66
 
67
67
  def invalid_format_string?(node)
68
- !RuboCop::Cop::Utils::FormatString.new(node.source).valid?
68
+ string = if sprintf?(node) || format?(node)
69
+ node.first_argument.source
70
+ else
71
+ node.receiver.source
72
+ end
73
+ !RuboCop::Cop::Utils::FormatString.new(string).valid?
69
74
  end
70
75
 
71
76
  def offending_node?(node)
@@ -62,7 +62,7 @@ module RuboCop
62
62
  # To avoid likely false positives (e.g. a single ' or ")
63
63
  next if literal.gsub(/[^[[:alnum:]]]/, '').empty?
64
64
 
65
- QUOTES_AND_COMMAS.any? { |pat| literal =~ pat }
65
+ QUOTES_AND_COMMAS.any? { |pat| literal.match?(pat) }
66
66
  end
67
67
  end
68
68
  end
@@ -61,7 +61,7 @@ module RuboCop
61
61
  end
62
62
 
63
63
  def non_alphanumeric_literal?(literal)
64
- literal !~ /[[:alnum:]]/
64
+ !/[[:alnum:]]/.match?(literal)
65
65
  end
66
66
  end
67
67
  end
@@ -31,12 +31,12 @@ module RuboCop
31
31
  MSG = 'Use `StandardError` over `Exception`.'
32
32
 
33
33
  def_node_matcher :exception?, <<~PATTERN
34
- (send nil? {:raise :fail} (const ${cbase nil?} :Exception) ... )
34
+ (send nil? {:raise :fail} $(const ${cbase nil?} :Exception) ... )
35
35
  PATTERN
36
36
 
37
37
  def_node_matcher :exception_new_with_message?, <<~PATTERN
38
38
  (send nil? {:raise :fail}
39
- (send (const ${cbase nil?} :Exception) :new ... ))
39
+ (send $(const ${cbase nil?} :Exception) :new ... ))
40
40
  PATTERN
41
41
 
42
42
  def on_send(node)
@@ -44,13 +44,21 @@ module RuboCop
44
44
  exception_new_with_message?(node, &check(node))
45
45
  end
46
46
 
47
+ def autocorrect(node)
48
+ lambda do |corrector|
49
+ exception_class = node.children.first&.cbase_type? ? '::StandardError' : 'StandardError'
50
+
51
+ corrector.replace(node, exception_class)
52
+ end
53
+ end
54
+
47
55
  private
48
56
 
49
57
  def check(node)
50
- lambda do |cbase|
58
+ lambda do |exception_class, cbase|
51
59
  return if cbase.nil? && implicit_namespace?(node)
52
60
 
53
- add_offense(node)
61
+ add_offense(exception_class)
54
62
  end
55
63
  end
56
64
 
@@ -135,6 +135,7 @@ module RuboCop
135
135
  end
136
136
  end
137
137
 
138
+ # rubocop:todo Metrics/CyclomaticComplexity
138
139
  def find_redundant(comment, offenses, cop, line_range, next_line_range)
139
140
  if all_disabled?(comment)
140
141
  # If there's a disable all comment followed by a comment
@@ -152,9 +153,10 @@ module RuboCop
152
153
  cop if cop_offenses.none? { |o| line_range.cover?(o.line) }
153
154
  end
154
155
  end
156
+ # rubocop:enable Metrics/CyclomaticComplexity
155
157
 
156
158
  def all_disabled?(comment)
157
- comment.text =~ /rubocop\s*:\s*(?:disable|todo)\s+all\b/
159
+ /rubocop\s*:\s*(?:disable|todo)\s+all\b/.match?(comment.text)
158
160
  end
159
161
 
160
162
  def ignore_offense?(disabled_ranges, line_range)
@@ -225,7 +227,7 @@ module RuboCop
225
227
  .drop_while { |r| !r.equal?(range) }
226
228
  .each_cons(2)
227
229
  .map { |range1, range2| range1.end.join(range2.begin).source }
228
- .all? { |intervening| intervening =~ /\A\s*,\s*\Z/ }
230
+ .all? { |intervening| /\A\s*,\s*\Z/.match?(intervening) }
229
231
  end
230
232
 
231
233
  def describe(cop)
@@ -23,6 +23,12 @@ module RuboCop
23
23
  def on_match_current_line(node)
24
24
  add_offense(node)
25
25
  end
26
+
27
+ def autocorrect(node)
28
+ lambda do |corrector|
29
+ corrector.replace(node, "#{node.source} =~ $_")
30
+ end
31
+ end
26
32
  end
27
33
  end
28
34
  end
@@ -30,7 +30,7 @@ module RuboCop
30
30
  def on_if(node)
31
31
  return unless safe_navigation_empty_in_conditional?(node)
32
32
 
33
- add_offense(node)
33
+ add_offense(node.condition)
34
34
  end
35
35
  end
36
36
  end
@@ -13,19 +13,51 @@ module RuboCop
13
13
  # operator (or keyword and) can be converted to a nested if statement,
14
14
  # and ||/or is shorthand for a sequence of ifs, so they also add one.
15
15
  # Loops can be said to have an exit condition, so they add one.
16
+ # Blocks that are calls to builtin iteration methods
17
+ # (e.g. `ary.map{...}) also add one, others are ignored.
18
+ #
19
+ # def each_child_node(*types) # count begins: 1
20
+ # unless block_given? # unless: +1
21
+ # return to_enum(__method__, *types)
22
+ #
23
+ # children.each do |child| # each{}: +1
24
+ # next unless child.is_a?(Node) # unless: +1
25
+ #
26
+ # yield child if types.empty? || # if: +1, ||: +1
27
+ # types.include?(child.type)
28
+ # end
29
+ #
30
+ # self
31
+ # end # total: 6
16
32
  class CyclomaticComplexity < Cop
17
33
  include MethodComplexity
34
+ include Utils::IteratingBlock
18
35
 
19
36
  MSG = 'Cyclomatic complexity for %<method>s is too high. ' \
20
37
  '[%<complexity>d/%<max>d]'
21
- COUNTED_NODES = %i[if while until for
22
- rescue when and or].freeze
38
+ COUNTED_NODES = %i[if while until for csend block block_pass
39
+ rescue when and or or_asgn and_asgn].freeze
23
40
 
24
41
  private
25
42
 
26
- def complexity_score_for(_node)
43
+ def complexity_score_for(node)
44
+ return 0 if iterating_block?(node) == false
45
+
27
46
  1
28
47
  end
48
+
49
+ def block_method(node)
50
+ case node.type
51
+ when :block
52
+ node.method_name
53
+ when :block_pass
54
+ node.parent.method_name
55
+ end
56
+ end
57
+
58
+ def count_block?(block)
59
+ KNOWN_ITERATING_METHODS.include? block.method_name
60
+ end
29
61
  end
30
62
  end
31
63
  end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # > Condition -- a logical/Boolean test, == != <= >= < > else case
20
20
  # > default try catch ? and unary conditionals.
21
21
  # > http://c2.com/cgi/wiki?AbcMetric
22
- CONDITION_NODES = CyclomaticComplexity::COUNTED_NODES.freeze
22
+ CONDITION_NODES = (CyclomaticComplexity::COUNTED_NODES - %i[block block_pass]).freeze
23
23
 
24
24
  def self.calculate(node)
25
25
  new(node).calculate
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Metrics
6
+ module Utils
7
+ # Used to identify iterating blocks like `.map{}` and `.map(&:...)`
8
+ module IteratingBlock
9
+ enumerable = %i[
10
+ all? any? chain chunk chunk_while collect collect_concat count cycle
11
+ detect drop drop_while each each_cons each_entry each_slice
12
+ each_with_index each_with_object entries filter filter_map find
13
+ find_all find_index flat_map grep grep_v group_by inject lazy map
14
+ max max_by min min_by minmax minmax_by none? one? partition reduce
15
+ reject reverse_each select slice_after slice_before slice_when sort
16
+ sort_by sum take take_while tally to_h uniq zip
17
+ ]
18
+
19
+ enumerator = %i[with_index with_object]
20
+
21
+ array = %i[
22
+ bsearch bsearch_index collect! combination d_permutation delete_if
23
+ each_index keep_if map! permutation product reject! repeat
24
+ repeated_combination select! sort sort! sort_by sort_by
25
+ ]
26
+
27
+ hash = %i[
28
+ each_key each_pair each_value fetch fetch_values has_key? merge
29
+ merge! transform_keys transform_keys! transform_values
30
+ transform_values!
31
+ ]
32
+
33
+ KNOWN_ITERATING_METHODS = (Set.new(enumerable) + enumerator + array + hash).freeze
34
+
35
+ # Returns the name of the method called with a block
36
+ # if node is a block node, or a block-pass node.
37
+ def block_method_name(node)
38
+ case node.type
39
+ when :block
40
+ node.method_name
41
+ when :block_pass
42
+ node.parent.method_name
43
+ end
44
+ end
45
+
46
+ # Returns true iff name is a known iterating type (e.g. :each, :transform_values)
47
+ def iterating_method?(name)
48
+ KNOWN_ITERATING_METHODS.include? name
49
+ end
50
+
51
+ # Returns nil if node is neither a block node or a block-pass node.
52
+ # Otherwise returns true/false if method call is a known iterating call
53
+ def iterating_block?(node)
54
+ name = block_method_name(node)
55
+ name && iterating_method?(name)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -9,7 +9,7 @@ module RuboCop
9
9
 
10
10
  FORMATS = {
11
11
  snake_case: /^@{0,2}[\da-z_]+[!?=]?$/,
12
- camelCase: /^@{0,2}_?[a-z][\da-zA-Z]+[!?=]?$/
12
+ camelCase: /^@{0,2}(?:_|_?[a-z][\da-zA-Z]*)[!?=]?$/
13
13
  }.freeze
14
14
  end
15
15
  end
@@ -41,11 +41,11 @@ module RuboCop
41
41
  end
42
42
 
43
43
  def interpreter_directive_comment?(comment)
44
- comment.text =~ /^#\s*(frozen_string_literal|encoding):/
44
+ /^#\s*(frozen_string_literal|encoding):/.match?(comment.text)
45
45
  end
46
46
 
47
47
  def rubocop_directive_comment?(comment)
48
- comment.text =~ CommentConfig::COMMENT_DIRECTIVE_REGEXP
48
+ CommentConfig::COMMENT_DIRECTIVE_REGEXP.match?(comment.text)
49
49
  end
50
50
  end
51
51
  end
@@ -51,7 +51,7 @@ module RuboCop
51
51
 
52
52
  def accept_end_kw_alignment?(end_loc)
53
53
  end_loc.nil? || # Discard modifier forms of if/while/until.
54
- processed_source.lines[end_loc.line - 1] !~ /\A[ \t]*end/
54
+ !/\A[ \t]*end/.match?(processed_source.lines[end_loc.line - 1])
55
55
  end
56
56
 
57
57
  def style_parameter_name
@@ -17,7 +17,7 @@ module RuboCop
17
17
 
18
18
  def method_uses_parens?(node, limit)
19
19
  source = node.source_range.source_line[0...limit.loc.column]
20
- source =~ /\s*\(\s*$/
20
+ /\s*\(\s*$/.match?(source)
21
21
  end
22
22
 
23
23
  def check_children_line_break(node, children, start = node)
@@ -152,7 +152,7 @@ module RuboCop
152
152
  expression
153
153
  end
154
154
 
155
- def argument_in_method_call(node, kind)
155
+ def argument_in_method_call(node, kind) # rubocop:todo Metrics/CyclomaticComplexity
156
156
  node.each_ancestor(:send, :block).find do |a|
157
157
  # If the node is inside a block, it makes no difference if that block
158
158
  # is an argument in a method call. It doesn't count.
@@ -9,8 +9,7 @@ module RuboCop
9
9
  def parens_required?(node)
10
10
  range = node.source_range
11
11
  source = range.source_buffer.source
12
- source[range.begin_pos - 1] =~ /[a-z]/ ||
13
- source[range.end_pos] =~ /[a-z]/
12
+ /[a-z]/.match?(source[range.begin_pos - 1]) || /[a-z]/.match?(source[range.end_pos])
14
13
  end
15
14
  end
16
15
  end
@@ -87,7 +87,7 @@ module RuboCop
87
87
  end
88
88
 
89
89
  def aligned_words?(range, line)
90
- line[range.column - 1, 2] =~ /\s\S/
90
+ /\s\S/.match?(line[range.column - 1, 2])
91
91
  end
92
92
 
93
93
  def aligned_char?(range, line)
@@ -109,7 +109,7 @@ module RuboCop
109
109
 
110
110
  def move_pos(src, pos, step, condition, regexp)
111
111
  offset = step == -1 ? -1 : 0
112
- pos += step while condition && src[pos + offset] =~ regexp
112
+ pos += step while condition && regexp.match?(src[pos + offset])
113
113
  pos.negative? ? 0 : pos
114
114
  end
115
115
  end
@@ -11,6 +11,33 @@ module RuboCop
11
11
 
12
12
  regopt.children.include?(:x)
13
13
  end
14
+
15
+ def pattern_source(node)
16
+ freespace_mode = freespace_mode_regexp?(node)
17
+
18
+ node.children.reject(&:regopt_type?).map do |child|
19
+ source_with_comments_and_interpolations_blanked(child, freespace_mode)
20
+ end.join
21
+ end
22
+
23
+ def source_with_comments_and_interpolations_blanked(child, freespace_mode)
24
+ source = child.source
25
+
26
+ # We don't want to consider the contents of interpolations or free-space mode comments as
27
+ # part of the pattern source, but need to preserve their width, to allow offsets to
28
+ # correctly line up with the original source: spaces have no effect, and preserve width.
29
+ if child.begin_type?
30
+ replace_match_with_spaces(source, /.*/) # replace all content
31
+ elsif freespace_mode
32
+ replace_match_with_spaces(source, /(?<!\\)#.*/) # replace any comments
33
+ else
34
+ source
35
+ end
36
+ end
37
+
38
+ def replace_match_with_spaces(source, pattern)
39
+ source.sub(pattern) { ' ' * Regexp.last_match[0].length }
40
+ end
14
41
  end
15
42
  end
16
43
  end
@@ -15,7 +15,7 @@ module RuboCop
15
15
  if style == :single_quotes
16
16
  !double_quotes_required?(src)
17
17
  else
18
- src !~ /" | \\[^'] | \#(@|\{)/x
18
+ !/" | \\[^'] | \#(@|\{)/x.match?(src)
19
19
  end
20
20
  end
21
21
  end
@@ -87,15 +87,15 @@ module RuboCop
87
87
  return false unless token
88
88
 
89
89
  if side == :left
90
- String(token.space_after?) =~ SINGLE_SPACE_REGEXP
90
+ SINGLE_SPACE_REGEXP.match?(String(token.space_after?))
91
91
  else
92
- String(token.space_before?) =~ SINGLE_SPACE_REGEXP
92
+ SINGLE_SPACE_REGEXP.match?(String(token.space_before?))
93
93
  end
94
94
  end
95
95
 
96
96
  def reposition(src, pos, step)
97
97
  offset = step == -1 ? -1 : 0
98
- pos += step while src[pos + offset] =~ SINGLE_SPACE_REGEXP
98
+ pos += step while SINGLE_SPACE_REGEXP.match?(src[pos + offset])
99
99
  pos.negative? ? 0 : pos
100
100
  end
101
101
 
@@ -31,7 +31,7 @@ module RuboCop
31
31
  # If there is any heredoc in items, then match the comma succeeding
32
32
  # any whitespace (except newlines), otherwise allow for newlines
33
33
  comma_regex = any_heredoc?(items) ? /\A[^\S\n]*,/ : /\A\s*,/
34
- range.source =~ comma_regex && range.source.index(',')
34
+ comma_regex.match?(range.source) && range.source.index(',')
35
35
  end
36
36
 
37
37
  def check_comma(node, kind, comma_pos)
@@ -44,7 +44,7 @@ module RuboCop
44
44
  end
45
45
 
46
46
  def uppercase?(name)
47
- name =~ /[[:upper:]]/
47
+ /[[:upper:]]/.match?(name)
48
48
  end
49
49
 
50
50
  def name_type(node)
@@ -62,7 +62,7 @@ module RuboCop
62
62
  end
63
63
 
64
64
  def ends_with_num?(name)
65
- name[-1] =~ /\d/
65
+ /\d/.match?(name[-1])
66
66
  end
67
67
 
68
68
  def length_offense(node, range)
@@ -35,7 +35,7 @@ module RuboCop
35
35
  def op_method?(name)
36
36
  return false if BLACKLISTED.include?(name)
37
37
 
38
- name !~ /\A\w/ || OP_LIKE_METHODS.include?(name)
38
+ !/\A\w/.match?(name) || OP_LIKE_METHODS.include?(name)
39
39
  end
40
40
  end
41
41
  end