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
@@ -22,6 +22,7 @@ module RuboCop
22
22
 
23
23
  def investigate(processed_source)
24
24
  return if processed_source.blank?
25
+
25
26
  @processed_source = processed_source
26
27
 
27
28
  check_for_line_terminator_or_opener
@@ -29,6 +30,7 @@ module RuboCop
29
30
 
30
31
  def on_begin(node)
31
32
  return if cop_config['AllowAsExpressionSeparator']
33
+
32
34
  exprs = node.children
33
35
 
34
36
  return if exprs.size < 2
@@ -40,6 +42,7 @@ module RuboCop
40
42
  # every line with more than 1 expression on it is an offense
41
43
  lines.each do |line, expr_on_line|
42
44
  next unless expr_on_line.size > 1
45
+
43
46
  # TODO: Find the correct position of the semicolon. We don't know
44
47
  # if the first semicolon on the line is a separator of
45
48
  # expressions. It's just a guess.
@@ -50,6 +53,7 @@ module RuboCop
50
53
 
51
54
  def autocorrect(range)
52
55
  return unless range
56
+
53
57
  ->(corrector) { corrector.remove(range) }
54
58
  end
55
59
 
@@ -138,6 +138,7 @@ module RuboCop
138
138
  check_send(:raise, node) unless ignored_node?(node)
139
139
  when :only_raise
140
140
  return if @custom_fail_defined
141
+
141
142
  check_send(:fail, node)
142
143
  when :only_fail
143
144
  check_send(:raise, node)
@@ -33,6 +33,7 @@ module RuboCop
33
33
  def on_pair(node)
34
34
  return unless string_hash_key?(node)
35
35
  return if receive_environments_method?(node)
36
+
36
37
  add_offense(node.key)
37
38
  end
38
39
 
@@ -13,6 +13,7 @@ module RuboCop
13
13
  # something.map(&:upcase)
14
14
  class SymbolProc < Cop
15
15
  include RangeHelp
16
+ include IgnoredMethods
16
17
 
17
18
  MSG = 'Pass `&:%<method>s` as an argument to `%<block_method>s` ' \
18
19
  'instead of a block.'.freeze
@@ -120,14 +121,6 @@ module RuboCop
120
121
  end
121
122
  end
122
123
 
123
- def ignored_methods
124
- cop_config['IgnoredMethods']
125
- end
126
-
127
- def ignored_method?(name)
128
- ignored_methods.include?(name.to_s)
129
- end
130
-
131
124
  def super?(node)
132
125
  SUPER_TYPES.include?(node.type)
133
126
  end
@@ -45,6 +45,7 @@ module RuboCop
45
45
 
46
46
  def on_array(node)
47
47
  return unless node.square_brackets?
48
+
48
49
  check_literal(node, 'item of %<article>s array')
49
50
  end
50
51
 
@@ -84,6 +84,7 @@ module RuboCop
84
84
 
85
85
  def remove_semicolon(node, corrector)
86
86
  return unless token_before_end(node).semicolon?
87
+
87
88
  corrector.remove(token_before_end(node).pos)
88
89
  end
89
90
  end
@@ -66,6 +66,7 @@ module RuboCop
66
66
  def find_first_possible_offense(variables)
67
67
  variables.reduce(nil) do |offense, variable|
68
68
  break offense unless %i[lvasgn splat].include?(variable.type)
69
+
69
70
  var, = *variable
70
71
  var, = *var
71
72
  if allow_named_underscore_variables
@@ -50,8 +50,7 @@ module RuboCop
50
50
  elsif node.modifier_form?
51
51
  corrector.replace(node.source_range, node.if_branch.source)
52
52
  else
53
- corrected = [node.if_branch.source,
54
- else_source(node.else_branch)].join(' || ')
53
+ corrected = make_ternary_form(node)
55
54
 
56
55
  corrector.replace(node.source_range, corrected)
57
56
  end
@@ -70,6 +69,7 @@ module RuboCop
70
69
 
71
70
  def range_of_offense(node)
72
71
  return :expression unless node.ternary?
72
+
73
73
  range_between(node.loc.question.begin_pos, node.loc.colon.end_pos)
74
74
  end
75
75
 
@@ -94,6 +94,17 @@ module RuboCop
94
94
  else_branch.modifier_form?
95
95
  wrap_else ? "(#{else_branch.source})" : else_branch.source
96
96
  end
97
+
98
+ def make_ternary_form(node)
99
+ ternary_form = [node.if_branch.source,
100
+ else_source(node.else_branch)].join(' || ')
101
+
102
+ if node.parent && node.parent.send_type?
103
+ "(#{ternary_form})"
104
+ else
105
+ ternary_form
106
+ end
107
+ end
97
108
  end
98
109
  end
99
110
  end
@@ -32,6 +32,7 @@ module RuboCop
32
32
 
33
33
  def on_dstr(node)
34
34
  return unless string_literal?(node)
35
+
35
36
  check(node)
36
37
  end
37
38
 
@@ -40,6 +41,7 @@ module RuboCop
40
41
  # will call `on_dstr` for the entire string and `on_str` for the
41
42
  # non interpolated portion of the string
42
43
  return unless string_literal?(node)
44
+
43
45
  check(node)
44
46
  end
45
47
 
@@ -81,12 +81,24 @@ module RuboCop
81
81
  end
82
82
 
83
83
  def correct_bracketed(node)
84
- words = node.children.map { |w| to_string_literal(w.children[0]) }
84
+ words = node.children.map do |word|
85
+ if word.dstr_type?
86
+ string_literal = to_string_literal(word.source)
87
+
88
+ trim_string_interporation_escape_character(string_literal)
89
+ else
90
+ to_string_literal(word.children[0])
91
+ end
92
+ end
85
93
 
86
94
  lambda do |corrector|
87
95
  corrector.replace(node.source_range, "[#{words.join(', ')}]")
88
96
  end
89
97
  end
98
+
99
+ def trim_string_interporation_escape_character(str)
100
+ str.gsub(/\\\#{(.*?)\}/) { "\#{#{Regexp.last_match(1)}}" }
101
+ end
90
102
  end
91
103
  end
92
104
  end
@@ -59,6 +59,7 @@ module RuboCop
59
59
  Force.all.each_with_object([]) do |force_class, forces|
60
60
  joining_cops = cops.select { |cop| cop.join_force?(force_class) }
61
61
  next if joining_cops.empty?
62
+
62
63
  forces << force_class.new(joining_cops)
63
64
  end
64
65
  end
@@ -99,6 +99,7 @@ module RuboCop
99
99
  def process_children(origin_node)
100
100
  origin_node.each_child_node do |child_node|
101
101
  next if scanned_node?(child_node)
102
+
102
103
  process_node(child_node)
103
104
  end
104
105
  end
@@ -174,6 +175,7 @@ module RuboCop
174
175
 
175
176
  variable_names.each do |name|
176
177
  next if variable_table.variable_exist?(name)
178
+
177
179
  variable_table.declare_variable(name, node)
178
180
  end
179
181
 
@@ -272,6 +274,7 @@ module RuboCop
272
274
  def process_zero_arity_super(node)
273
275
  variable_table.accessible_variables.each do |variable|
274
276
  next unless variable.method_argument?
277
+
275
278
  variable.reference!(node)
276
279
  end
277
280
  end
@@ -315,10 +318,12 @@ module RuboCop
315
318
  # Non related references which are caught in the above scan
316
319
  # would be skipped here.
317
320
  next unless variable
321
+
318
322
  variable.assignments.each do |assignment|
319
323
  next if assignment_nodes_in_loop.none? do |assignment_node|
320
324
  assignment_node.equal?(assignment.node)
321
325
  end
326
+
322
327
  assignment.reference!(node)
323
328
  end
324
329
  end
@@ -48,11 +48,13 @@ module RuboCop
48
48
 
49
49
  def operator_assignment?
50
50
  return false unless meta_assignment_node
51
+
51
52
  OPERATOR_ASSIGNMENT_TYPES.include?(meta_assignment_node.type)
52
53
  end
53
54
 
54
55
  def multiple_assignment?
55
56
  return false unless meta_assignment_node
57
+
56
58
  meta_assignment_node.type == MULTIPLE_ASSIGNMENT_TYPE
57
59
  end
58
60
 
@@ -76,6 +78,7 @@ module RuboCop
76
78
  return nil unless node.parent
77
79
  return nil unless OPERATOR_ASSIGNMENT_TYPES.include?(node.parent.type)
78
80
  return nil unless node.sibling_index.zero?
81
+
79
82
  node.parent
80
83
  end
81
84
 
@@ -84,6 +87,7 @@ module RuboCop
84
87
  return nil unless grandparent_node
85
88
  return nil unless grandparent_node.type == MULTIPLE_ASSIGNMENT_TYPE
86
89
  return nil unless node.parent.type == MULTIPLE_LEFT_HAND_SIDE_TYPE
90
+
87
91
  grandparent_node
88
92
  end
89
93
  end
@@ -9,8 +9,10 @@ module RuboCop
9
9
  ([target_node] + target_node.ancestors).each do |node|
10
10
  return nil unless node.parent
11
11
  return nil unless scope.include?(node)
12
+
12
13
  klass = CLASSES_BY_TYPE[node.parent.type]
13
14
  next unless klass
15
+
14
16
  branch = klass.new(node, scope)
15
17
  return branch if branch.branched?
16
18
  end
@@ -74,6 +76,7 @@ module RuboCop
74
76
 
75
77
  def parent
76
78
  return @parent if instance_variable_defined?(:@parent)
79
+
77
80
  @branch = Branch.of(control_node, scope: scope)
78
81
  end
79
82
 
@@ -122,6 +125,7 @@ module RuboCop
122
125
 
123
126
  def ==(other)
124
127
  return false unless other
128
+
125
129
  control_node.equal?(other.control_node) &&
126
130
  child_node.equal?(other.child_node)
127
131
  end
@@ -8,11 +8,13 @@ module RuboCop
8
8
  module Branchable
9
9
  def branch
10
10
  return @branch if instance_variable_defined?(:@branch)
11
+
11
12
  @branch = Branch.of(node, scope: scope)
12
13
  end
13
14
 
14
15
  def run_exclusively_with?(other)
15
16
  return false if !branch || !other.branch
17
+
16
18
  branch.exclusive_with?(other.branch)
17
19
  end
18
20
  end
@@ -61,6 +61,7 @@ module RuboCop
61
61
 
62
62
  def each_node(&block)
63
63
  return to_enum(__method__) unless block_given?
64
+
64
65
  yield node if naked_top_level?
65
66
  scan_node(node, &block)
66
67
  end
@@ -70,6 +71,7 @@ module RuboCop
70
71
  def scan_node(node, &block)
71
72
  node.each_child_node do |child_node|
72
73
  next unless include?(child_node)
74
+
73
75
  yield child_node
74
76
  scan_node(child_node, &block)
75
77
  end
@@ -79,16 +81,20 @@ module RuboCop
79
81
  return true if !naked_top_level? && target_node.equal?(node)
80
82
  return true if ancestor_node?(target_node)
81
83
  return false unless target_node.parent.equal?(node)
84
+
82
85
  indices = OUTER_SCOPE_CHILD_INDICES[target_node.parent.type]
83
86
  return false unless indices
87
+
84
88
  indices.include?(target_node.sibling_index)
85
89
  end
86
90
 
87
91
  def belong_to_inner_scope?(target_node)
88
92
  return false if !target_node.parent || target_node.parent.equal?(node)
89
93
  return false unless SCOPE_TYPES.include?(target_node.parent.type)
94
+
90
95
  indices = OUTER_SCOPE_CHILD_INDICES[target_node.parent.type]
91
96
  return true unless indices
97
+
92
98
  !indices.include?(target_node.sibling_index)
93
99
  end
94
100
 
@@ -120,6 +120,7 @@ module RuboCop
120
120
  def mark_variable_as_captured_by_block_if_so(variable)
121
121
  return unless current_scope.node.block_type?
122
122
  return if variable.scope == current_scope
123
+
123
124
  variable.capture_with_block!
124
125
  end
125
126
  end
@@ -33,11 +33,13 @@ module RuboCop
33
33
  def traverse_files_upwards(filename, start_dir, use_home)
34
34
  Pathname.new(start_dir).expand_path.ascend do |dir|
35
35
  break if FileFinder.root_level?(dir)
36
+
36
37
  file = dir + filename
37
38
  yield(file.to_s) if file.exist?
38
39
  end
39
40
 
40
41
  return unless use_home && ENV.key?('HOME')
42
+
41
43
  file = File.join(Dir.home, filename)
42
44
  yield(file) if File.exist?(file)
43
45
  end
@@ -128,10 +128,10 @@ module RuboCop
128
128
 
129
129
  params.each do |param|
130
130
  value = default_cfg[param]
131
- if value.is_a?(Array)
132
- next if value.empty?
133
- output_buffer.puts "# #{param}: #{value.join(', ')}"
134
- end
131
+ next unless value.is_a?(Array)
132
+ next if value.empty?
133
+
134
+ output_buffer.puts "# #{param}: #{value.join(', ')}"
135
135
  end
136
136
  end
137
137
 
@@ -12,6 +12,7 @@ module RuboCop
12
12
  class FileListFormatter < BaseFormatter
13
13
  def file_finished(file, offenses)
14
14
  return if offenses.empty?
15
+
15
16
  output.printf("%s\n", file)
16
17
  end
17
18
  end
@@ -27,6 +27,7 @@ module RuboCop
27
27
 
28
28
  def file_finished(file, offenses)
29
29
  return if offenses.empty?
30
+
30
31
  count_stats(offenses)
31
32
  report_file(file, offenses)
32
33
  end
@@ -29,6 +29,7 @@ module RuboCop
29
29
  if args.any?
30
30
  raise OptionArgumentError, '-s/--stdin requires exactly one path.'
31
31
  end
32
+
32
33
  # We want the STDIN contents in @options[:stdin] and the file name in
33
34
  # args to simplify the rest of the processing.
34
35
  args = [@options[:stdin]]
@@ -136,6 +137,7 @@ module RuboCop
136
137
  table) do |severity|
137
138
  @options[:fail_level] = severity
138
139
  end
140
+ option(opts, '--display-only-fail-level-offenses')
139
141
  end
140
142
 
141
143
  def add_flags_with_optional_args(opts)
@@ -251,10 +253,16 @@ module RuboCop
251
253
  unless boolean_or_empty_cache?
252
254
  raise OptionArgumentError, '-C/--cache argument must be true or false'
253
255
  end
256
+
257
+ if display_only_fail_level_offenses_with_autocorrect?
258
+ raise OptionArgumentError, '--autocorrect can not be used with ' \
259
+ '--display-only-fail-level-offenses'
260
+ end
254
261
  validate_auto_gen_config
255
262
  validate_parallel
256
263
 
257
264
  return if incompatible_options.size <= 1
265
+
258
266
  raise OptionArgumentError, 'Incompatible cli options: ' \
259
267
  "#{incompatible_options.inspect}"
260
268
  end
@@ -304,6 +312,10 @@ module RuboCop
304
312
  UnneededCopDisableDirective]).any?
305
313
  end
306
314
 
315
+ def display_only_fail_level_offenses_with_autocorrect?
316
+ @options[:display_only_fail_level_offenses] && @options[:autocorrect]
317
+ end
318
+
307
319
  def except_syntax?
308
320
  @options.key?(:except) &&
309
321
  (@options[:except] & %w[Lint/Syntax Syntax]).any?
@@ -319,6 +331,7 @@ module RuboCop
319
331
 
320
332
  def validate_exclude_limit_option
321
333
  return if @options[:exclude_limit] =~ /^\d+$/
334
+
322
335
  # Emulate OptionParser's behavior to make failures consistent regardless
323
336
  # of option order.
324
337
  raise OptionParser::MissingArgument
@@ -378,6 +391,9 @@ module RuboCop
378
391
  'if no format is specified.'],
379
392
  fail_level: ['Minimum severity (A/R/C/W/E/F) for exit',
380
393
  'with error code.'],
394
+ display_only_fail_level_offenses:
395
+ ['Only output offense messages at',
396
+ 'the specified --fail-level or above'],
381
397
  show_cops: ['Shows the given cops, or all cops by',
382
398
  'default, and their configurations for the',
383
399
  'current directory.'],