rbhint 0.85.1.rc1 → 0.85.1.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -2
  3. data/assets/output.html.erb +1 -1
  4. data/config/default.yml +13 -1
  5. data/lib/rbhint.rb +8 -0
  6. data/lib/rbhint/version.rb +1 -1
  7. data/lib/rubocop.rb +2 -0
  8. data/lib/rubocop/config.rb +1 -1
  9. data/lib/rubocop/config_loader_resolver.rb +1 -1
  10. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
  11. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  12. data/lib/rubocop/cop/layout/assignment_indentation.rb +2 -2
  13. data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
  14. data/lib/rubocop/cop/layout/block_end_newline.rb +1 -1
  15. data/lib/rubocop/cop/layout/case_indentation.rb +2 -2
  16. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
  17. data/lib/rubocop/cop/layout/comment_indentation.rb +4 -4
  18. data/lib/rubocop/cop/layout/condition_position.rb +1 -1
  19. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  20. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  21. data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
  22. data/lib/rubocop/cop/layout/empty_comment.rb +2 -2
  23. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  24. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -2
  25. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  26. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -1
  27. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +2 -0
  28. data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +1 -1
  29. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -1
  30. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
  31. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +2 -2
  32. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +1 -1
  33. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +1 -1
  34. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  35. data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
  36. data/lib/rubocop/cop/layout/extra_spacing.rb +6 -6
  37. data/lib/rubocop/cop/layout/first_argument_indentation.rb +3 -3
  38. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
  39. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +2 -2
  40. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -2
  41. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
  42. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -1
  43. data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +1 -1
  44. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  45. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
  46. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
  47. data/lib/rubocop/cop/layout/heredoc_indentation.rb +3 -3
  48. data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -1
  49. data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
  50. data/lib/rubocop/cop/layout/indentation_width.rb +2 -2
  51. data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
  52. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  53. data/lib/rubocop/cop/layout/leading_empty_lines.rb +1 -1
  54. data/lib/rubocop/cop/layout/line_length.rb +6 -6
  55. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +1 -1
  56. data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +1 -1
  57. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  58. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  59. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +1 -1
  60. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
  61. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
  62. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
  63. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
  64. data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
  65. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
  66. data/lib/rubocop/cop/layout/parameter_alignment.rb +1 -1
  67. data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
  68. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
  69. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  70. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +6 -6
  71. data/lib/rubocop/cop/layout/space_around_operators.rb +2 -2
  72. data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
  73. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
  74. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
  75. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -1
  76. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  77. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
  78. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +1 -1
  79. data/lib/rubocop/cop/layout/trailing_empty_lines.rb +1 -1
  80. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  81. data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
  82. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  83. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +6 -1
  84. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  85. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  86. data/lib/rubocop/cop/lint/raise_exception.rb +4 -4
  87. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +4 -2
  88. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
  89. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  90. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
  91. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  92. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
  93. data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
  94. data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
  95. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  96. data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
  97. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  98. data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
  99. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
  100. data/lib/rubocop/cop/mixin/range_help.rb +1 -1
  101. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +27 -0
  102. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  103. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
  104. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  105. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +2 -2
  106. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  107. data/lib/rubocop/cop/naming/file_name.rb +1 -3
  108. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  109. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  110. data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
  111. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  112. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  113. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  114. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  115. data/lib/rubocop/cop/style/copyright.rb +3 -3
  116. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
  117. data/lib/rubocop/cop/style/documentation.rb +2 -2
  118. data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
  119. data/lib/rubocop/cop/style/encoding.rb +1 -1
  120. data/lib/rubocop/cop/style/exponential_notation.rb +2 -2
  121. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  122. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  123. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  124. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  125. data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
  126. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  127. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
  128. data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
  129. data/lib/rubocop/cop/style/next.rb +2 -2
  130. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
  131. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  132. data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
  133. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
  134. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
  135. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +14 -23
  136. data/lib/rubocop/cop/style/redundant_self.rb +6 -9
  137. data/lib/rubocop/cop/style/sample.rb +1 -1
  138. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  139. data/lib/rubocop/cop/style/struct_inheritance.rb +21 -0
  140. data/lib/rubocop/cop/style/symbol_array.rb +5 -5
  141. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  142. data/lib/rubocop/cop/style/word_array.rb +1 -1
  143. data/lib/rubocop/cop/util.rb +2 -2
  144. data/lib/rubocop/cop/utils/format_string.rb +1 -1
  145. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  146. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  147. data/lib/rubocop/name_similarity.rb +6 -0
  148. data/lib/rubocop/path_util.rb +2 -2
  149. data/lib/rubocop/platform.rb +1 -1
  150. data/lib/rubocop/rspec/expect_offense.rb +12 -2
  151. data/lib/rubocop/target_finder.rb +1 -1
  152. data/lib/rubocop/target_ruby.rb +1 -1
  153. metadata +10 -2
@@ -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
@@ -123,10 +123,9 @@ module RuboCop
123
123
  # special handling for Action Pack Variants file names like
124
124
  # some_file.xlsx+mobile.axlsx
125
125
  basename = basename.sub('+', '_')
126
- basename =~ (regex || SNAKE_CASE)
126
+ basename.match?(regex || SNAKE_CASE)
127
127
  end
128
128
 
129
- # rubocop:disable Metrics/CyclomaticComplexity
130
129
  def find_class_or_module(node, namespace)
131
130
  return nil unless node
132
131
 
@@ -145,7 +144,6 @@ module RuboCop
145
144
 
146
145
  nil
147
146
  end
148
- # rubocop:enable Metrics/CyclomaticComplexity
149
147
 
150
148
  def match_namespace(node, namespace, expected)
151
149
  match_partial = partial_matcher!(expected)
@@ -42,7 +42,7 @@ module RuboCop
42
42
  return false unless /\w/.match?(delimiters)
43
43
 
44
44
  forbidden_delimiters.none? do |forbidden_delimiter|
45
- delimiters =~ Regexp.new(forbidden_delimiter)
45
+ Regexp.new(forbidden_delimiter).match?(delimiters)
46
46
  end
47
47
  end
48
48
 
@@ -60,7 +60,7 @@ module RuboCop
60
60
  end
61
61
 
62
62
  def requires_percent_q?(source)
63
- style == :percent_q && source =~ /^%[^\w]/
63
+ style == :percent_q && /^%[^\w]/.match?(source)
64
64
  end
65
65
 
66
66
  def requires_bare_percent?(source)
@@ -245,14 +245,13 @@ module RuboCop
245
245
  end
246
246
 
247
247
  def whitespace_before?(range)
248
- range.source_buffer.source[range.begin_pos - 1, 1] =~ /\s/
248
+ /\s/.match?(range.source_buffer.source[range.begin_pos - 1, 1])
249
249
  end
250
250
 
251
251
  def whitespace_after?(range, length = 1)
252
- range.source_buffer.source[range.begin_pos + length, 1] =~ /\s/
252
+ /\s/.match?(range.source_buffer.source[range.begin_pos + length, 1])
253
253
  end
254
254
 
255
- # rubocop:disable Metrics/CyclomaticComplexity
256
255
  def get_blocks(node, &block)
257
256
  case node.type
258
257
  when :block
@@ -270,7 +269,6 @@ module RuboCop
270
269
  node.each_child_node { |child| get_blocks(child, &block) }
271
270
  end
272
271
  end
273
- # rubocop:enable Metrics/CyclomaticComplexity
274
272
 
275
273
  def proper_block_style?(node)
276
274
  return special_method_proper_block_style?(node) if special_method?(node.method_name)
@@ -143,7 +143,7 @@ module RuboCop
143
143
  end
144
144
 
145
145
  def compact_node_name?(node)
146
- node.loc.name.source =~ /::/
146
+ /::/.match?(node.loc.name.source)
147
147
  end
148
148
  end
149
149
  end
@@ -153,7 +153,7 @@ module RuboCop
153
153
  end
154
154
 
155
155
  def contains_backtick?(node)
156
- node_body(node) =~ /`/
156
+ /`/.match?(node_body(node))
157
157
  end
158
158
 
159
159
  def node_body(node)
@@ -55,8 +55,8 @@ module RuboCop
55
55
 
56
56
  def offensive?(comment)
57
57
  line = line(comment)
58
- KEYWORDS.any? { |word| line =~ /^\s*#{word}\s/ } &&
59
- ALLOWED_COMMENTS.none? { |c| line =~ /#\s*#{c}/ }
58
+ KEYWORDS.any? { |word| /^\s*#{word}\s/.match?(line) } &&
59
+ ALLOWED_COMMENTS.none? { |c| /#\s*#{c}/.match?(line) }
60
60
  end
61
61
 
62
62
  def message(comment)
@@ -67,7 +67,7 @@ module RuboCop
67
67
 
68
68
  private
69
69
 
70
- def expand_elsif(node, elsif_branches = [])
70
+ def expand_elsif(node, elsif_branches = []) # rubocop:todo Metrics/CyclomaticComplexity
71
71
  return [] if node.nil? || !node.if_type? || !node.elsif?
72
72
 
73
73
  elsif_branches << node.if_branch
@@ -72,14 +72,14 @@ module RuboCop
72
72
  return false if token_index >= processed_source.tokens.size
73
73
 
74
74
  token = processed_source.tokens[token_index]
75
- token.comment? && token.text =~ /^#!.*$/
75
+ token.comment? && /^#!.*$/.match?(token.text)
76
76
  end
77
77
 
78
78
  def encoding_token?(processed_source, token_index)
79
79
  return false if token_index >= processed_source.tokens.size
80
80
 
81
81
  token = processed_source.tokens[token_index]
82
- token.comment? && token.text =~ /^#.*coding\s?[:=]\s?(?:UTF|utf)-8/
82
+ token.comment? && /^#.*coding\s?[:=]\s?(?:UTF|utf)-8/.match?(token.text)
83
83
  end
84
84
 
85
85
  def notice_found?(processed_source)
@@ -88,7 +88,7 @@ module RuboCop
88
88
  processed_source.each_token do |token|
89
89
  break unless token.comment?
90
90
 
91
- notice_found = !(token.text =~ notice_regexp).nil?
91
+ notice_found = notice_regexp.match?(token.text)
92
92
  break if notice_found
93
93
  end
94
94
  notice_found
@@ -41,7 +41,7 @@ module RuboCop
41
41
  private
42
42
 
43
43
  def rubocop_directive_comment?(comment)
44
- comment.text =~ CommentConfig::COMMENT_DIRECTIVE_REGEXP
44
+ CommentConfig::COMMENT_DIRECTIVE_REGEXP.match?(comment.text)
45
45
  end
46
46
  end
47
47
  end
@@ -104,7 +104,7 @@ module RuboCop
104
104
  end
105
105
 
106
106
  def compact_namespace?(node)
107
- node.loc.name.source =~ /::/
107
+ /::/.match?(node.loc.name.source)
108
108
  end
109
109
 
110
110
  # First checks if the :nodoc: comment is associated with the
@@ -123,7 +123,7 @@ module RuboCop
123
123
  end
124
124
 
125
125
  def nodoc?(comment, require_all = false)
126
- comment.text =~ /^#\s*:nodoc:#{"\s+all\s*$" if require_all}/
126
+ /^#\s*:nodoc:#{"\s+all\s*$" if require_all}/.match?(comment.text)
127
127
  end
128
128
 
129
129
  def nodoc(node)
@@ -43,13 +43,15 @@ module RuboCop
43
43
 
44
44
  def on_case(case_node)
45
45
  return if case_node.condition
46
- return if case_node.when_branches.any? do |when_branch|
47
- when_branch.each_descendant.any?(&:return_type?)
48
- end
49
46
 
50
- if (else_branch = case_node.else_branch)
51
- return if else_branch.return_type? ||
52
- else_branch.each_descendant.any?(&:return_type?)
47
+ branch_bodies = [
48
+ *case_node.when_branches.map(&:body),
49
+ case_node.else_branch
50
+ ].compact
51
+
52
+ return if branch_bodies.any? do |body|
53
+ body.return_type? ||
54
+ body.each_descendant.any?(&:return_type?)
53
55
  end
54
56
 
55
57
  add_offense(case_node, location: :keyword)
@@ -42,7 +42,7 @@ module RuboCop
42
42
  end
43
43
 
44
44
  def encoding_omitable?(line)
45
- line =~ ENCODING_PATTERN
45
+ ENCODING_PATTERN.match?(line)
46
46
  end
47
47
 
48
48
  def encoding_line_number(processed_source)
@@ -69,7 +69,7 @@ module RuboCop
69
69
 
70
70
  def scientific?(node)
71
71
  mantissa, = node.source.split('e')
72
- mantissa =~ /^-?[1-9](\.\d*[0-9])?$/
72
+ /^-?[1-9](\.\d*[0-9])?$/.match?(mantissa)
73
73
  end
74
74
 
75
75
  def engineering?(node)
@@ -85,7 +85,7 @@ module RuboCop
85
85
 
86
86
  def integral(node)
87
87
  mantissa, = node.source.split('e')
88
- mantissa =~ /^-?[1-9](\d*[1-9])?$/
88
+ /^-?[1-9](\d*[1-9])?$/.match?(mantissa)
89
89
  end
90
90
 
91
91
  def offense?(node)