rubocop 0.58.2 → 0.59.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +22 -7
  4. data/config/disabled.yml +33 -4
  5. data/config/enabled.yml +4 -11
  6. data/lib/rubocop.rb +5 -0
  7. data/lib/rubocop/ast/builder.rb +1 -0
  8. data/lib/rubocop/ast/node.rb +11 -33
  9. data/lib/rubocop/ast/node/block_node.rb +8 -1
  10. data/lib/rubocop/ast/node/defined_node.rb +13 -0
  11. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +16 -5
  12. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +21 -0
  13. data/lib/rubocop/ast/node/send_node.rb +3 -12
  14. data/lib/rubocop/ast/traversal.rb +10 -0
  15. data/lib/rubocop/cli.rb +4 -1
  16. data/lib/rubocop/config.rb +21 -5
  17. data/lib/rubocop/config_loader.rb +2 -0
  18. data/lib/rubocop/config_loader_resolver.rb +3 -1
  19. data/lib/rubocop/cop/autocorrect_logic.rb +1 -0
  20. data/lib/rubocop/cop/bundler/gem_comment.rb +64 -0
  21. data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -0
  22. data/lib/rubocop/cop/commissioner.rb +2 -0
  23. data/lib/rubocop/cop/cop.rb +3 -0
  24. data/lib/rubocop/cop/corrector.rb +2 -0
  25. data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -0
  26. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -0
  27. data/lib/rubocop/cop/correctors/space_corrector.rb +2 -0
  28. data/lib/rubocop/cop/force.rb +1 -0
  29. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
  30. data/lib/rubocop/cop/generator.rb +1 -0
  31. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -0
  32. data/lib/rubocop/cop/layout/class_structure.rb +4 -0
  33. data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +5 -4
  34. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +35 -0
  35. data/lib/rubocop/cop/layout/else_alignment.rb +1 -0
  36. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -0
  37. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -0
  38. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +5 -2
  39. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -0
  40. data/lib/rubocop/cop/layout/end_of_line.rb +1 -0
  41. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -0
  42. data/lib/rubocop/cop/layout/indent_array.rb +1 -0
  43. data/lib/rubocop/cop/layout/indent_heredoc.rb +3 -0
  44. data/lib/rubocop/cop/layout/indentation_width.rb +2 -0
  45. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -0
  46. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -1
  47. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +34 -11
  48. data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -0
  49. data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
  50. data/lib/rubocop/cop/layout/space_around_keyword.rb +3 -1
  51. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -0
  52. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -0
  53. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +16 -8
  54. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -0
  55. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
  56. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -0
  57. data/lib/rubocop/cop/layout/tab.rb +1 -0
  58. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -0
  59. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -0
  60. data/lib/rubocop/cop/lint/duplicate_methods.rb +9 -1
  61. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
  62. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
  63. data/lib/rubocop/cop/lint/interpolation_check.rb +2 -0
  64. data/lib/rubocop/cop/lint/literal_as_condition.rb +3 -6
  65. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -0
  66. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -0
  67. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -0
  68. data/lib/rubocop/cop/lint/rescue_type.rb +1 -0
  69. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +2 -2
  70. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +2 -0
  71. data/lib/rubocop/cop/lint/script_permission.rb +1 -0
  72. data/lib/rubocop/cop/lint/shadowed_argument.rb +3 -0
  73. data/lib/rubocop/cop/lint/shadowed_exception.rb +2 -0
  74. data/lib/rubocop/cop/lint/unneeded_cop_disable_directive.rb +1 -0
  75. data/lib/rubocop/cop/lint/unneeded_cop_enable_directive.rb +1 -0
  76. data/lib/rubocop/cop/lint/unneeded_require_statement.rb +1 -0
  77. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
  78. data/lib/rubocop/cop/lint/unreachable_code.rb +2 -0
  79. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -0
  80. data/lib/rubocop/cop/lint/useless_setter_call.rb +3 -0
  81. data/lib/rubocop/cop/lint/void.rb +1 -0
  82. data/lib/rubocop/cop/message_annotator.rb +1 -0
  83. data/lib/rubocop/cop/metrics/block_length.rb +1 -0
  84. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -0
  85. data/lib/rubocop/cop/metrics/line_length.rb +6 -1
  86. data/lib/rubocop/cop/metrics/method_length.rb +1 -0
  87. data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -0
  88. data/lib/rubocop/cop/mixin/classish_length.rb +1 -0
  89. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -0
  90. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
  91. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +12 -6
  92. data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
  93. data/lib/rubocop/cop/mixin/ignored_methods.rb +19 -0
  94. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +25 -1
  95. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +5 -3
  96. data/lib/rubocop/cop/mixin/percent_literal.rb +2 -0
  97. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
  98. data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -1
  99. data/lib/rubocop/cop/mixin/statement_modifier.rb +6 -1
  100. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -0
  101. data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -0
  102. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -0
  103. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +2 -0
  104. data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -0
  105. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
  106. data/lib/rubocop/cop/naming/file_name.rb +4 -1
  107. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -0
  108. data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
  109. data/lib/rubocop/cop/naming/uncommunicative_block_param_name.rb +1 -0
  110. data/lib/rubocop/cop/naming/uncommunicative_method_param_name.rb +1 -0
  111. data/lib/rubocop/cop/naming/variable_name.rb +1 -0
  112. data/lib/rubocop/cop/performance/case_when_splat.rb +11 -7
  113. data/lib/rubocop/cop/performance/casecmp.rb +33 -42
  114. data/lib/rubocop/cop/performance/chain_array_allocation.rb +77 -0
  115. data/lib/rubocop/cop/performance/compare_with_block.rb +3 -0
  116. data/lib/rubocop/cop/performance/regexp_match.rb +1 -0
  117. data/lib/rubocop/cop/performance/sample.rb +2 -0
  118. data/lib/rubocop/cop/performance/size.rb +8 -2
  119. data/lib/rubocop/cop/performance/string_replacement.rb +1 -0
  120. data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -0
  121. data/lib/rubocop/cop/rails/bulk_change_table.rb +9 -2
  122. data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +1 -0
  123. data/lib/rubocop/cop/rails/delegate.rb +7 -2
  124. data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -0
  125. data/lib/rubocop/cop/rails/find_each.rb +7 -2
  126. data/lib/rubocop/cop/rails/http_positional_arguments.rb +1 -1
  127. data/lib/rubocop/cop/rails/http_status.rb +2 -0
  128. data/lib/rubocop/cop/rails/inverse_of.rb +4 -0
  129. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +1 -0
  130. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -0
  131. data/lib/rubocop/cop/rails/reversible_migration.rb +1 -0
  132. data/lib/rubocop/cop/rails/save_bang.rb +189 -38
  133. data/lib/rubocop/cop/rails/time_zone.rb +1 -0
  134. data/lib/rubocop/cop/security/eval.rb +1 -0
  135. data/lib/rubocop/cop/security/json_load.rb +2 -2
  136. data/lib/rubocop/cop/security/open.rb +6 -3
  137. data/lib/rubocop/cop/severity.rb +1 -0
  138. data/lib/rubocop/cop/style/and_or.rb +3 -3
  139. data/lib/rubocop/cop/style/ascii_comments.rb +1 -0
  140. data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
  141. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +2 -3
  142. data/lib/rubocop/cop/style/class_and_module_children.rb +3 -0
  143. data/lib/rubocop/cop/style/class_vars.rb +1 -1
  144. data/lib/rubocop/cop/style/colon_method_definition.rb +1 -0
  145. data/lib/rubocop/cop/style/commented_keyword.rb +2 -0
  146. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
  147. data/lib/rubocop/cop/style/copyright.rb +7 -2
  148. data/lib/rubocop/cop/style/date_time.rb +40 -7
  149. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  150. data/lib/rubocop/cop/style/empty_case_condition.rb +8 -0
  151. data/lib/rubocop/cop/style/empty_else.rb +2 -0
  152. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -0
  153. data/lib/rubocop/cop/style/eval_with_location.rb +2 -0
  154. data/lib/rubocop/cop/style/for.rb +56 -10
  155. data/lib/rubocop/cop/style/format_string_token.rb +1 -1
  156. data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -0
  157. data/lib/rubocop/cop/style/inverse_methods.rb +1 -0
  158. data/lib/rubocop/cop/style/lambda.rb +1 -0
  159. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +3 -5
  160. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +3 -5
  161. data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -2
  162. data/lib/rubocop/cop/style/missing_else.rb +1 -0
  163. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -0
  164. data/lib/rubocop/cop/style/multiline_method_signature.rb +65 -0
  165. data/lib/rubocop/cop/style/multiple_comparison.rb +1 -0
  166. data/lib/rubocop/cop/style/nil_comparison.rb +45 -5
  167. data/lib/rubocop/cop/style/not.rb +1 -1
  168. data/lib/rubocop/cop/style/numeric_predicate.rb +5 -0
  169. data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
  170. data/lib/rubocop/cop/style/or_assignment.rb +2 -0
  171. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  172. data/lib/rubocop/cop/style/random_with_offset.rb +1 -0
  173. data/lib/rubocop/cop/style/redundant_begin.rb +13 -0
  174. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -0
  175. data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -1
  176. data/lib/rubocop/cop/style/redundant_return.rb +1 -0
  177. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -0
  178. data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -0
  179. data/lib/rubocop/cop/style/safe_navigation.rb +4 -0
  180. data/lib/rubocop/cop/style/semicolon.rb +4 -0
  181. data/lib/rubocop/cop/style/signal_exception.rb +1 -0
  182. data/lib/rubocop/cop/style/string_hash_keys.rb +1 -0
  183. data/lib/rubocop/cop/style/symbol_proc.rb +1 -8
  184. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -0
  185. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -0
  186. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -0
  187. data/lib/rubocop/cop/style/unneeded_condition.rb +13 -2
  188. data/lib/rubocop/cop/style/unneeded_percent_q.rb +2 -0
  189. data/lib/rubocop/cop/style/word_array.rb +13 -1
  190. data/lib/rubocop/cop/team.rb +1 -0
  191. data/lib/rubocop/cop/variable_force.rb +5 -0
  192. data/lib/rubocop/cop/variable_force/assignment.rb +4 -0
  193. data/lib/rubocop/cop/variable_force/branch.rb +4 -0
  194. data/lib/rubocop/cop/variable_force/branchable.rb +2 -0
  195. data/lib/rubocop/cop/variable_force/scope.rb +6 -0
  196. data/lib/rubocop/cop/variable_force/variable_table.rb +1 -0
  197. data/lib/rubocop/file_finder.rb +2 -0
  198. data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -4
  199. data/lib/rubocop/formatter/file_list_formatter.rb +1 -0
  200. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -0
  201. data/lib/rubocop/options.rb +16 -0
  202. data/lib/rubocop/path_util.rb +16 -1
  203. data/lib/rubocop/processed_source.rb +4 -0
  204. data/lib/rubocop/remote_config.rb +6 -1
  205. data/lib/rubocop/result_cache.rb +1 -0
  206. data/lib/rubocop/rspec/cop_helper.rb +3 -5
  207. data/lib/rubocop/rspec/shared_examples.rb +1 -9
  208. data/lib/rubocop/runner.rb +4 -0
  209. data/lib/rubocop/target_finder.rb +2 -0
  210. data/lib/rubocop/version.rb +1 -1
  211. metadata +7 -2
@@ -71,6 +71,7 @@ module RuboCop
71
71
 
72
72
  def on_array(node)
73
73
  return unless node.square_brackets?
74
+
74
75
  left, right = array_brackets(node)
75
76
  if empty_brackets?(left, right)
76
77
  return empty_offenses(node, left, right, EMPTY_MSG)
@@ -125,6 +126,7 @@ module RuboCop
125
126
  def end_has_own_line?(token)
126
127
  line, col = line_and_column_for(token)
127
128
  return true if col == -1
129
+
128
130
  processed_source.lines[line][0..col].delete(' ').empty?
129
131
  end
130
132
 
@@ -88,7 +88,7 @@ module RuboCop
88
88
  # brace plus space (rather than just inserting a space), then any
89
89
  # removal of the same brace will give us a clobbering error. This
90
90
  # in turn will make RuboCop fall back on cop-by-cop
91
- # auto-correction. Problem solved.
91
+ # auto-correction. Problem solved.
92
92
  case range.source
93
93
  when /\s/ then corrector.remove(range)
94
94
  when '{' then corrector.replace(range, '{ ')
@@ -65,9 +65,11 @@ module RuboCop
65
65
  def on_send(node)
66
66
  return if node.multiline?
67
67
  return unless bracket_method?(node)
68
+
68
69
  tokens = tokens(node)
69
70
  left_token = left_ref_bracket(node, tokens)
70
71
  return unless left_token
72
+
71
73
  right_token = closing_bracket(tokens, left_token)
72
74
 
73
75
  if empty_brackets?(left_token, right_token)
@@ -32,6 +32,7 @@ module RuboCop
32
32
  processed_source.lines.each.with_index(1) do |line, lineno|
33
33
  match = line.match(/^([^\t]*)\t+/)
34
34
  next unless match
35
+
35
36
  prefix = match.captures[0]
36
37
  col = prefix.length
37
38
  next if in_string_literal?(str_ranges, lineno, col)
@@ -49,6 +49,7 @@ module RuboCop
49
49
 
50
50
  def extract_heredoc_ranges(ast)
51
51
  return [] unless ast
52
+
52
53
  ast.each_node(:str, :dstr, :xstr).select(&:heredoc?).map do |node|
53
54
  body = node.location.heredoc_body
54
55
  (body.first_line...body.last_line)
@@ -69,6 +69,7 @@ module RuboCop
69
69
  DEPRECATED_METHODS_OBJECT.each do |data|
70
70
  next unless data.class_nodes.include?(node.receiver)
71
71
  next unless node.method?(data.deprecated_method)
72
+
72
73
  yield data
73
74
  end
74
75
  end
@@ -138,6 +138,7 @@ module RuboCop
138
138
 
139
139
  def found_instance_method(node, name)
140
140
  return unless (scope = node.parent_module_name)
141
+
141
142
  if scope =~ /\A#<Class:(.*)>\Z/
142
143
  found_method(node, "#{Regexp.last_match(1)}.#{name}")
143
144
  else
@@ -147,7 +148,12 @@ module RuboCop
147
148
 
148
149
  def found_method(node, method_name)
149
150
  if @definitions.key?(method_name)
150
- loc = node.send_type? ? node.loc.selector : node.loc.keyword
151
+ loc = case node.type
152
+ when :def, :defs
153
+ node.loc.keyword.join(node.loc.name)
154
+ else
155
+ node.loc.expression
156
+ end
151
157
  message = message_for_dup(node, method_name)
152
158
 
153
159
  add_offense(node, location: loc, message: message)
@@ -174,6 +180,7 @@ module RuboCop
174
180
  args.each do |arg|
175
181
  name = sym_name(arg)
176
182
  next unless name
183
+
177
184
  found_instance_method(node, name) if readable
178
185
  found_instance_method(node, "#{name}=") if writable
179
186
  end
@@ -193,6 +200,7 @@ module RuboCop
193
200
  end
194
201
 
195
202
  break if namespace.nil?
203
+
196
204
  namespace, mod_name = *namespace
197
205
  end
198
206
  end
@@ -48,6 +48,7 @@ module RuboCop
48
48
  num_of_format_args, num_of_expected_fields = count_matches(node)
49
49
 
50
50
  return false if num_of_format_args == :unknown
51
+
51
52
  matched_arguments_count?(num_of_expected_fields, num_of_format_args)
52
53
  end
53
54
 
@@ -104,6 +104,7 @@ module RuboCop
104
104
  modifier = child if access_modifier?(child)
105
105
  when :defs
106
106
  next if correct_visibility?(child, modifier, ignored_methods)
107
+
107
108
  yield child, modifier
108
109
  when :kwbegin
109
110
  ineffective_modifier(child, ignored_methods, modifier, &block)
@@ -22,9 +22,11 @@ module RuboCop
22
22
 
23
23
  def on_str(node)
24
24
  return if heredoc?(node)
25
+
25
26
  parent = node.parent
26
27
  return if parent && (parent.dstr_type? || parent.regexp_type?)
27
28
  return unless node.source.scrub =~ /(?<!\\)#\{.*\}/
29
+
28
30
  add_offense(node)
29
31
  end
30
32
 
@@ -67,6 +67,7 @@ module RuboCop
67
67
 
68
68
  def on_send(node)
69
69
  return unless node.negation_method?
70
+
70
71
  check_for_literal(node)
71
72
  end
72
73
 
@@ -98,12 +99,8 @@ module RuboCop
98
99
  end
99
100
 
100
101
  def check_node(node)
101
- return unless node
102
-
103
- if node.keyword_bang?
104
- receiver, = *node
105
-
106
- handle_node(receiver)
102
+ if node.send_type? && node.prefix_bang?
103
+ handle_node(node.receiver)
107
104
  elsif LOGICAL_OPERATOR_NODES.include?(node.type)
108
105
  node.each_child_node { |op| handle_node(op) }
109
106
  elsif node.begin_type? && node.children.one?
@@ -57,6 +57,7 @@ module RuboCop
57
57
  # This has to remain a strict inequality to handle
58
58
  # the case when max_range is Float::INFINITY
59
59
  next if line_range.max - line_range.min < max_range + 2
60
+
60
61
  range = source_range(processed_source.buffer,
61
62
  line_range.min,
62
63
  (0..0))
@@ -74,6 +74,7 @@ module RuboCop
74
74
  elsif child.defs_type?
75
75
  subject, = *child
76
76
  next if subject.lvar_type?
77
+
77
78
  yield child
78
79
  elsif !scoping_method_call?(child)
79
80
  find_nested_defs(child, &block)
@@ -30,6 +30,7 @@ module RuboCop
30
30
 
31
31
  def on_resbody(node)
32
32
  return unless node.children.first
33
+
33
34
  rescue_args = node.children.first.children
34
35
  return unless rescue_args.any? { |a| targets_exception?(a) }
35
36
 
@@ -44,6 +44,7 @@ module RuboCop
44
44
  def on_resbody(node)
45
45
  rescued, _, _body = *node
46
46
  return if rescued.nil?
47
+
47
48
  exceptions = *rescued
48
49
  invalid_exceptions = invalid_exceptions(exceptions)
49
50
  return if invalid_exceptions.empty?
@@ -4,8 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  # The safe navigation operator returns nil if the receiver is
7
- # nil. If you chain an ordinary method call after a safe
8
- # navigation operator, it raises NoMethodError. We should use a
7
+ # nil. If you chain an ordinary method call after a safe
8
+ # navigation operator, it raises NoMethodError. We should use a
9
9
  # safe navigation operator after a safe navigation operator.
10
10
  # This cop checks for the problem outlined above.
11
11
  #
@@ -36,6 +36,7 @@ module RuboCop
36
36
  def on_csend(node)
37
37
  return unless node.parent &&
38
38
  AST::Node::OPERATOR_KEYWORDS.include?(node.parent.type)
39
+
39
40
  check(node)
40
41
  end
41
42
 
@@ -77,6 +78,7 @@ module RuboCop
77
78
  AST::Node::OPERATOR_KEYWORDS.include?(parent.parent.type)))
78
79
  return node
79
80
  end
81
+
80
82
  top_conditional_ancestor(parent)
81
83
  end
82
84
 
@@ -39,6 +39,7 @@ module RuboCop
39
39
  return if Platform.windows?
40
40
  return unless processed_source.start_with?(SHEBANG)
41
41
  return if executable?(processed_source)
42
+
42
43
  comment = processed_source.comments[0]
43
44
  message = format_message_from(processed_source)
44
45
  add_offense(comment, message: message)
@@ -83,6 +83,9 @@ module RuboCop
83
83
 
84
84
  def check_argument(argument)
85
85
  return unless argument.method_argument? || argument.block_argument?
86
+ # Block local variables, i.e., variables declared after ; inside
87
+ # |...| aren't really arguments.
88
+ return if argument.explicit_block_local_variable?
86
89
 
87
90
  shadowing_assignment(argument) do |node|
88
91
  message = format(MSG, argument: argument.name)
@@ -51,6 +51,7 @@ module RuboCop
51
51
 
52
52
  def on_rescue(node)
53
53
  return if rescue_modifier?(node)
54
+
54
55
  _body, *rescues, _else = *node
55
56
  rescued_groups = rescues.each_with_object([]) do |group, exceptions|
56
57
  rescue_group, = *group
@@ -151,6 +152,7 @@ module RuboCop
151
152
  klasses = *rescue_group
152
153
  klasses.map do |klass|
153
154
  next unless klass.const_type?
155
+
154
156
  klass.source
155
157
  end.compact
156
158
  end
@@ -215,6 +215,7 @@ module RuboCop
215
215
  def matching_range(haystack, needle)
216
216
  offset = (haystack.source =~ Regexp.new(Regexp.escape(needle)))
217
217
  return unless offset
218
+
218
219
  offset += haystack.begin_pos
219
220
  Parser::Source::Range.new(haystack.source_buffer, offset,
220
221
  offset + needle.size)
@@ -40,6 +40,7 @@ module RuboCop
40
40
 
41
41
  def investigate(processed_source)
42
42
  return if processed_source.blank?
43
+
43
44
  offenses = processed_source.comment_config.extra_enabled_comments
44
45
  offenses.each do |comment, name|
45
46
  add_offense(
@@ -33,6 +33,7 @@ module RuboCop
33
33
 
34
34
  def on_send(node)
35
35
  return unless unnecessary_require_statement?(node)
36
+
36
37
  add_offense(node)
37
38
  end
38
39
 
@@ -50,7 +50,7 @@ module RuboCop
50
50
  # baz
51
51
  # end
52
52
  class UnneededSplatExpansion < Cop
53
- MSG = 'Unnecessary splat expansion.'.freeze
53
+ MSG = 'Replace splat expansion with comma separated values.'.freeze
54
54
  ARRAY_PARAM_MSG = 'Pass array contents as separate arguments.'.freeze
55
55
  PERCENT_W = '%w'.freeze
56
56
  PERCENT_CAPITAL_W = '%W'.freeze
@@ -63,6 +63,7 @@ module RuboCop
63
63
 
64
64
  def flow_expression?(node)
65
65
  return true if flow_command?(node)
66
+
66
67
  case node.type
67
68
  when :begin, :kwbegin
68
69
  expressions = *node
@@ -87,6 +88,7 @@ module RuboCop
87
88
  else_branch = node.else_branch
88
89
  return false unless else_branch
89
90
  return false unless flow_expression?(else_branch)
91
+
90
92
  node.when_branches.all? do |branch|
91
93
  branch.body && flow_expression?(branch.body)
92
94
  end
@@ -123,6 +123,7 @@ module RuboCop
123
123
 
124
124
  def variable_like_method_invocation?(node)
125
125
  return false unless node.send_type?
126
+
126
127
  receiver, _method_name, *args = *node
127
128
  receiver.nil? && args.empty?
128
129
  end
@@ -127,6 +127,7 @@ module RuboCop
127
127
  def process_logical_operator_assignment(asgn_node)
128
128
  lhs_node, rhs_node = *asgn_node
129
129
  return unless ASSIGNMENT_TYPES.include?(lhs_node.type)
130
+
130
131
  process_assignment(lhs_node, rhs_node)
131
132
 
132
133
  throw :skip_children
@@ -135,6 +136,7 @@ module RuboCop
135
136
  def process_binary_operator_assignment(op_asgn_node)
136
137
  lhs_node, = *op_asgn_node
137
138
  return unless ASSIGNMENT_TYPES.include?(lhs_node.type)
139
+
138
140
  lhs_variable_name, = *lhs_node
139
141
  @local[lhs_variable_name] = true
140
142
 
@@ -155,6 +157,7 @@ module RuboCop
155
157
  def constructor?(node)
156
158
  return true if node.literal?
157
159
  return false unless node.send_type?
160
+
158
161
  _receiver, method = *node
159
162
  method == :new
160
163
  end
@@ -83,6 +83,7 @@ module RuboCop
83
83
  def on_block(node)
84
84
  return unless node.body && !node.body.begin_type?
85
85
  return unless in_void_context?(node.body)
86
+
86
87
  check_expression(node.body)
87
88
  end
88
89
 
@@ -106,6 +106,7 @@ module RuboCop
106
106
  return true if debug?
107
107
  return false if options[:display_cop_names] == false
108
108
  return true if options[:display_cop_names]
109
+
109
110
  config.for_all_cops['DisplayCopNames']
110
111
  end
111
112
 
@@ -14,6 +14,7 @@ module RuboCop
14
14
 
15
15
  def on_block(node)
16
16
  return if excluded_method?(node)
17
+
17
18
  check_code_length(node)
18
19
  end
19
20
 
@@ -21,6 +21,7 @@ module RuboCop
21
21
 
22
22
  def investigate(processed_source)
23
23
  return if processed_source.blank?
24
+
24
25
  max = cop_config['Max']
25
26
  check_nesting_level(processed_source.ast, max, 0)
26
27
  end
@@ -38,6 +38,7 @@ module RuboCop
38
38
 
39
39
  def highligh_start(line)
40
40
  return max unless tab_indentation_width
41
+
41
42
  max - (tab_indentation_width - 1) * line.count("\t")
42
43
  end
43
44
 
@@ -76,7 +77,7 @@ module RuboCop
76
77
  excessive_position = if uri_range && uri_range.begin < max
77
78
  uri_range.end
78
79
  else
79
- max
80
+ highligh_start(line)
80
81
  end
81
82
 
82
83
  source_range(processed_source.buffer, index + 1,
@@ -97,6 +98,7 @@ module RuboCop
97
98
 
98
99
  def extract_heredocs(ast)
99
100
  return [] unless ast
101
+
100
102
  ast.each_node(:str, :dstr, :xstr).select(&:heredoc?).map do |node|
101
103
  body = node.location.heredoc_body
102
104
  delimiter = node.location.heredoc_end.source.strip
@@ -128,8 +130,10 @@ module RuboCop
128
130
  def find_excessive_uri_range(line)
129
131
  last_uri_match = match_uris(line).last
130
132
  return nil unless last_uri_match
133
+
131
134
  begin_position, end_position = last_uri_match.offset(0)
132
135
  return nil if begin_position < max && end_position < max
136
+
133
137
  begin_position...end_position
134
138
  end
135
139
 
@@ -175,6 +179,7 @@ module RuboCop
175
179
  .detect { |e| e.location.line == source_line_number }
176
180
 
177
181
  return false unless comment
182
+
178
183
  comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
179
184
  end
180
185
 
@@ -18,6 +18,7 @@ module RuboCop
18
18
 
19
19
  def on_block(node)
20
20
  return unless node.send_node.method_name == :define_method
21
+
21
22
  check_code_length(node)
22
23
  end
23
24
 
@@ -16,6 +16,7 @@ module RuboCop
16
16
  def split_comment(comment)
17
17
  match = comment.text.match(/^(# ?)([A-Za-z]+)(\s*:)?(\s+)?(\S+)?/)
18
18
  return false unless match
19
+
19
20
  match.captures
20
21
  end
21
22
 
@@ -17,6 +17,7 @@ module RuboCop
17
17
  target_line_numbers.reduce(0) do |length, line_number|
18
18
  source_line = processed_source[line_number]
19
19
  next length if irrelevant_line(source_line)
20
+
20
21
  length + 1
21
22
  end
22
23
  end