rubocop 0.76.0 → 0.80.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +4 -4
  4. data/config/default.yml +325 -283
  5. data/lib/rubocop.rb +43 -23
  6. data/lib/rubocop/ast/builder.rb +43 -42
  7. data/lib/rubocop/ast/node.rb +1 -13
  8. data/lib/rubocop/ast/node/block_node.rb +2 -0
  9. data/lib/rubocop/ast/node/def_node.rb +11 -0
  10. data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
  11. data/lib/rubocop/ast/node/regexp_node.rb +2 -4
  12. data/lib/rubocop/ast/traversal.rb +20 -3
  13. data/lib/rubocop/cli.rb +11 -230
  14. data/lib/rubocop/cli/command.rb +21 -0
  15. data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
  16. data/lib/rubocop/cli/command/base.rb +33 -0
  17. data/lib/rubocop/cli/command/execute_runner.rb +76 -0
  18. data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
  19. data/lib/rubocop/cli/command/show_cops.rb +80 -0
  20. data/lib/rubocop/cli/command/version.rb +17 -0
  21. data/lib/rubocop/cli/environment.rb +21 -0
  22. data/lib/rubocop/comment_config.rb +6 -1
  23. data/lib/rubocop/config.rb +28 -10
  24. data/lib/rubocop/config_loader.rb +19 -19
  25. data/lib/rubocop/config_obsoletion.rb +65 -11
  26. data/lib/rubocop/config_validator.rb +56 -98
  27. data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
  28. data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
  29. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
  30. data/lib/rubocop/cop/cop.rb +21 -0
  31. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
  32. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  33. data/lib/rubocop/cop/generator.rb +3 -4
  34. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  35. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  36. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
  37. data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
  38. data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
  39. data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
  40. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
  41. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  42. data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +5 -5
  43. data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
  44. data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +3 -3
  45. data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
  46. data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +10 -6
  47. data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
  48. data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -2
  49. data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
  50. data/lib/rubocop/cop/{metrics → layout}/line_length.rb +67 -108
  51. data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
  52. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
  53. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
  54. data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
  55. data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
  56. data/lib/rubocop/cop/layout/space_around_operators.rb +50 -7
  57. data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
  58. data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
  59. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
  60. data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
  61. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  62. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
  63. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
  64. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  65. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  66. data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
  67. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
  68. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +3 -3
  69. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +13 -8
  70. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  71. data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
  72. data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
  73. data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
  74. data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
  75. data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
  76. data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
  77. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  78. data/lib/rubocop/cop/migration/department_name.rb +30 -2
  79. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  80. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
  81. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
  82. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
  83. data/lib/rubocop/cop/mixin/hash_transform_method.rb +171 -0
  84. data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
  85. data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
  86. data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
  87. data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
  88. data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -12
  89. data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
  90. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
  91. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  92. data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
  93. data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
  94. data/lib/rubocop/cop/offense.rb +11 -0
  95. data/lib/rubocop/cop/registry.rb +7 -2
  96. data/lib/rubocop/cop/style/alias.rb +1 -1
  97. data/lib/rubocop/cop/style/array_join.rb +1 -1
  98. data/lib/rubocop/cop/style/attr.rb +8 -0
  99. data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
  100. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
  101. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  102. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  103. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -11
  104. data/lib/rubocop/cop/style/guard_clause.rb +3 -2
  105. data/lib/rubocop/cop/style/hash_each_methods.rb +87 -0
  106. data/lib/rubocop/cop/style/hash_transform_keys.rb +79 -0
  107. data/lib/rubocop/cop/style/hash_transform_values.rb +79 -0
  108. data/lib/rubocop/cop/style/if_unless_modifier.rb +38 -3
  109. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  110. data/lib/rubocop/cop/style/inverse_methods.rb +8 -4
  111. data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
  112. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
  113. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +169 -0
  114. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
  115. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  116. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  117. data/lib/rubocop/cop/style/multiline_when_then.rb +5 -1
  118. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +7 -7
  119. data/lib/rubocop/cop/style/next.rb +5 -5
  120. data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
  121. data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
  122. data/lib/rubocop/cop/style/option_hash.rb +3 -3
  123. data/lib/rubocop/cop/style/or_assignment.rb +3 -2
  124. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
  125. data/lib/rubocop/cop/style/redundant_condition.rb +17 -4
  126. data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
  127. data/lib/rubocop/cop/style/redundant_return.rb +2 -8
  128. data/lib/rubocop/cop/style/redundant_sort.rb +1 -1
  129. data/lib/rubocop/cop/style/symbol_array.rb +2 -2
  130. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  131. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +0 -22
  132. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
  133. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
  134. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  135. data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
  136. data/lib/rubocop/cop/team.rb +5 -0
  137. data/lib/rubocop/cop/variable_force.rb +4 -1
  138. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  139. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
  140. data/lib/rubocop/formatter/formatter_set.rb +1 -0
  141. data/lib/rubocop/formatter/json_formatter.rb +6 -5
  142. data/lib/rubocop/formatter/junit_formatter.rb +63 -0
  143. data/lib/rubocop/formatter/tap_formatter.rb +1 -3
  144. data/lib/rubocop/node_pattern.rb +97 -11
  145. data/lib/rubocop/options.rb +8 -8
  146. data/lib/rubocop/processed_source.rb +1 -1
  147. data/lib/rubocop/rake_task.rb +1 -0
  148. data/lib/rubocop/result_cache.rb +23 -7
  149. data/lib/rubocop/rspec/shared_contexts.rb +5 -0
  150. data/lib/rubocop/runner.rb +18 -2
  151. data/lib/rubocop/target_ruby.rb +151 -0
  152. data/lib/rubocop/version.rb +1 -1
  153. metadata +60 -27
  154. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
  155. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ class MethodCallWithArgsParentheses
7
+ # Style require_parentheses
8
+ module RequireParentheses
9
+ def on_send(node)
10
+ return if ignored_method?(node.method_name)
11
+ return if matches_ignored_pattern?(node.method_name)
12
+ return if eligible_for_parentheses_omission?(node)
13
+ return unless node.arguments? && !node.parenthesized?
14
+
15
+ add_offense(node)
16
+ end
17
+ alias on_csend on_send
18
+ alias on_super on_send
19
+ alias on_yield on_send
20
+
21
+ def autocorrect(node)
22
+ lambda do |corrector|
23
+ corrector.replace(args_begin(node), '(')
24
+
25
+ unless args_parenthesized?(node)
26
+ corrector.insert_after(args_end(node), ')')
27
+ end
28
+ end
29
+ end
30
+
31
+ def message(_node = nil)
32
+ 'Use parentheses for method calls with arguments.'
33
+ end
34
+
35
+ private
36
+
37
+ def eligible_for_parentheses_omission?(node)
38
+ node.operator_method? || node.setter_method? || ignored_macro?(node)
39
+ end
40
+
41
+ def included_macros_list
42
+ cop_config.fetch('IncludedMacros', []).map(&:to_sym)
43
+ end
44
+
45
+ def ignored_macro?(node)
46
+ cop_config['IgnoreMacros'] &&
47
+ node.macro? &&
48
+ !included_macros_list.include?(node.method_name)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -103,7 +103,7 @@ module RuboCop
103
103
  .select(&:macro?)
104
104
 
105
105
  siblings.select do |sibling_node|
106
- sibling_node.method_name == send_node.method_name
106
+ sibling_node.method?(send_node.method_name)
107
107
  end
108
108
  end
109
109
 
@@ -53,7 +53,7 @@ module RuboCop
53
53
  end
54
54
 
55
55
  def max_line_length
56
- config.for_cop('Metrics/LineLength')['Max'] || 80
56
+ config.for_cop('Layout/LineLength')['Max'] || 80
57
57
  end
58
58
  end
59
59
  end
@@ -35,7 +35,7 @@ module RuboCop
35
35
  return if !node.children.last.nil? && !node.multiline? && node.then?
36
36
 
37
37
  # With more than one statements after then, there's not offense
38
- return if node.children.last&.begin_type?
38
+ return if accept_node_type?(node.body)
39
39
 
40
40
  add_offense(node, location: :begin)
41
41
  end
@@ -49,6 +49,10 @@ module RuboCop
49
49
  )
50
50
  end
51
51
  end
52
+
53
+ def accept_node_type?(node)
54
+ node&.begin_type? || node&.array_type? || node&.hash_type?
55
+ end
52
56
  end
53
57
  end
54
58
  end
@@ -35,8 +35,8 @@ module RuboCop
35
35
  last_arg = nested.last_argument.source_range
36
36
 
37
37
  leading_space =
38
- range_with_surrounding_space(range: first_arg,
39
- side: :left).begin.resize(1)
38
+ range_with_surrounding_space(range: first_arg.begin,
39
+ side: :left)
40
40
 
41
41
  lambda do |corrector|
42
42
  corrector.replace(leading_space, '(')
@@ -49,17 +49,17 @@ module RuboCop
49
49
  def allowed_omission?(send_node)
50
50
  !send_node.arguments? || send_node.parenthesized? ||
51
51
  send_node.setter_method? || send_node.operator_method? ||
52
- whitelisted?(send_node)
52
+ allowed?(send_node)
53
53
  end
54
54
 
55
- def whitelisted?(send_node)
55
+ def allowed?(send_node)
56
56
  send_node.parent.arguments.one? &&
57
- whitelisted_methods.include?(send_node.method_name.to_s) &&
57
+ allowed_methods.include?(send_node.method_name.to_s) &&
58
58
  send_node.arguments.one?
59
59
  end
60
60
 
61
- def whitelisted_methods
62
- cop_config['Whitelist'] || []
61
+ def allowed_methods
62
+ cop_config['AllowedMethods'] || []
63
63
  end
64
64
  end
65
65
  end
@@ -20,18 +20,18 @@ module RuboCop
20
20
  # end
21
21
  #
22
22
  # # good
23
- # [1, 2].each do |o|
24
- # puts o unless o == 1
23
+ # [1, 2].each do |a|
24
+ # puts a if a == 1
25
25
  # end
26
26
  #
27
27
  # @example EnforcedStyle: always
28
28
  # # With `always` all conditions at the end of an iteration needs to be
29
29
  # # replaced by next - with `skip_modifier_ifs` the modifier if like
30
- # # this one are ignored: `[1, 2].each { |a| return 'yes' if a == 1 }`
30
+ # # this one are ignored: `[1, 2].each { |a| puts a if a == 1 }`
31
31
  #
32
32
  # # bad
33
- # [1, 2].each do |o|
34
- # puts o unless o == 1
33
+ # [1, 2].each do |a|
34
+ # puts a if a == 1
35
35
  # end
36
36
  #
37
37
  # # bad
@@ -9,18 +9,22 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # 1000000
14
13
  # 1_00_000
15
14
  # 1_0000
16
15
  #
17
16
  # # good
18
- #
19
17
  # 1_000_000
20
18
  # 1000
21
19
  #
22
- # # good unless Strict is set
20
+ # @example Strict: false (default)
23
21
  #
22
+ # # good
23
+ # 10_000_00 # typical representation of $10,000 in cents
24
+ #
25
+ # @example Strict: true
26
+ #
27
+ # # bad
24
28
  # 10_000_00 # typical representation of $10,000 in cents
25
29
  #
26
30
  class NumericLiterals < Cop
@@ -54,9 +54,10 @@ module RuboCop
54
54
  }.freeze
55
55
 
56
56
  def on_send(node)
57
- return if node.each_ancestor(:send, :block).any? do |ancestor|
58
- ignored_method?(ancestor.method_name)
59
- end
57
+ return if ignored_method?(node.method_name) ||
58
+ node.each_ancestor(:send, :block).any? do |ancestor|
59
+ ignored_method?(ancestor.method_name)
60
+ end
60
61
 
61
62
  numeric, replacement = check(node)
62
63
 
@@ -28,7 +28,7 @@ module RuboCop
28
28
 
29
29
  def on_args(node)
30
30
  return if super_used?(node)
31
- return if whitelist.include?(node.parent.method_name.to_s)
31
+ return if allowlist.include?(node.parent.method_name.to_s)
32
32
 
33
33
  option_hash(node) do |options|
34
34
  add_offense(options)
@@ -37,8 +37,8 @@ module RuboCop
37
37
 
38
38
  private
39
39
 
40
- def whitelist
41
- cop_config['Whitelist'] || []
40
+ def allowlist
41
+ cop_config['Allowlist'] || []
42
42
  end
43
43
 
44
44
  def suspicious_name?(arg_name)
@@ -34,7 +34,7 @@ module RuboCop
34
34
  (if
35
35
  ({lvar ivar cvar gvar} _var)
36
36
  ({lvar ivar cvar gvar} _var)
37
- _))
37
+ $_))
38
38
  PATTERN
39
39
 
40
40
  def_node_matcher :unless_assignment?, <<~PATTERN
@@ -51,7 +51,8 @@ module RuboCop
51
51
  end
52
52
 
53
53
  def on_lvasgn(node)
54
- return unless ternary_assignment?(node)
54
+ return unless (else_branch = ternary_assignment?(node))
55
+ return if else_branch.if_type?
55
56
 
56
57
  add_offense(node)
57
58
  end
@@ -88,27 +88,27 @@ module RuboCop
88
88
  end
89
89
 
90
90
  def contains_preferred_delimiter?(node, type)
91
- preferred_delimiters = preferred_delimiters_for(type)
92
- node
93
- .children.map { |n| string_source(n) }.compact
94
- .any? { |s| preferred_delimiters.any? { |d| s.include?(d) } }
91
+ contains_delimiter?(node, preferred_delimiters_for(type))
95
92
  end
96
93
 
97
94
  def include_same_character_as_used_for_delimiter?(node, type)
98
95
  return false unless %w[%w %i].include?(type)
99
96
 
100
97
  used_delimiters = matchpairs(begin_source(node)[-1])
101
- escaped_delimiters = used_delimiters.map { |d| "\\#{d}" }.join('|')
98
+ contains_delimiter?(node, used_delimiters)
99
+ end
102
100
 
101
+ def contains_delimiter?(node, delimiters)
102
+ delimiters_regexp = Regexp.union(delimiters)
103
103
  node
104
104
  .children.map { |n| string_source(n) }.compact
105
- .any? { |s| Regexp.new(escaped_delimiters) =~ s }
105
+ .any? { |s| delimiters_regexp =~ s }
106
106
  end
107
107
 
108
108
  def string_source(node)
109
109
  if node.is_a?(String)
110
110
  node
111
- elsif node.respond_to?(:type) && node.str_type?
111
+ elsif node.respond_to?(:type) && (node.str_type? || node.sym_type?)
112
112
  node.source
113
113
  end
114
114
  end
@@ -46,7 +46,7 @@ module RuboCop
46
46
  def autocorrect(node)
47
47
  lambda do |corrector|
48
48
  if node.ternary?
49
- corrector.replace(range_of_offense(node), '||')
49
+ correct_ternary(corrector, node)
50
50
  elsif node.modifier_form? || !node.else_branch
51
51
  corrector.replace(node.source_range, node.if_branch.source)
52
52
  else
@@ -90,9 +90,13 @@ module RuboCop
90
90
  end
91
91
 
92
92
  def else_source(else_branch)
93
- wrap_else =
94
- else_branch.basic_conditional? && else_branch.modifier_form?
95
- wrap_else ? "(#{else_branch.source})" : else_branch.source
93
+ if else_branch.basic_conditional? &&
94
+ else_branch.modifier_form? ||
95
+ else_branch.range_type?
96
+ "(#{else_branch.source})"
97
+ else
98
+ else_branch.source
99
+ end
96
100
  end
97
101
 
98
102
  def make_ternary_form(node)
@@ -106,6 +110,15 @@ module RuboCop
106
110
  ternary_form
107
111
  end
108
112
  end
113
+
114
+ def correct_ternary(corrector, node)
115
+ corrector.replace(range_of_offense(node), '||')
116
+
117
+ return unless node.else_branch.range_type?
118
+
119
+ corrector.insert_before(node.else_branch.loc.expression, '(')
120
+ corrector.insert_after(node.else_branch.loc.expression, ')')
121
+ end
109
122
  end
110
123
  end
111
124
  end
@@ -19,7 +19,7 @@ module RuboCop
19
19
  def_node_matcher :square_brackets?,
20
20
  '(send {(send _recv _msg) str array hash} :[] ...)'
21
21
  def_node_matcher :range_end?, '^^{irange erange}'
22
- def_node_matcher :method_node_and_args, '$(send _recv _msg $...)'
22
+ def_node_matcher :method_node_and_args, '$(call _recv _msg $...)'
23
23
  def_node_matcher :rescue?, '{^resbody ^^resbody}'
24
24
  def_node_matcher :arg_in_call_with_block?,
25
25
  '^^(block (send _ _ equal?(%0) ...) ...)'
@@ -102,7 +102,7 @@ module RuboCop
102
102
  return offense(begin_node, 'a variable') if node.variable?
103
103
  return offense(begin_node, 'a constant') if node.const_type?
104
104
 
105
- check_send(begin_node, node) if node.send_type?
105
+ check_send(begin_node, node) if node.call_type?
106
106
  end
107
107
 
108
108
  def check_send(begin_node, node)
@@ -195,7 +195,7 @@ module RuboCop
195
195
  end
196
196
 
197
197
  def method_call_with_redundant_parentheses?(node)
198
- return false unless node.send_type?
198
+ return false unless node.call_type?
199
199
  return false if node.prefix_not?
200
200
  return false if range_end?(node)
201
201
 
@@ -54,8 +54,6 @@ module RuboCop
54
54
  MULTI_RETURN_MSG = 'To return multiple values, use an array.'
55
55
 
56
56
  def on_def(node)
57
- return unless node.body
58
-
59
57
  check_branch(node.body)
60
58
  end
61
59
  alias on_defs on_def
@@ -152,12 +150,8 @@ module RuboCop
152
150
  end
153
151
 
154
152
  def check_begin_node(node)
155
- expressions = *node
156
- last_expr = expressions.last
157
-
158
- return unless last_expr&.return_type?
159
-
160
- check_return_node(last_expr)
153
+ last_expr = node.children.last
154
+ check_branch(last_expr)
161
155
  end
162
156
 
163
157
  def allow_multiple_return_values?
@@ -127,7 +127,7 @@ module RuboCop
127
127
  end
128
128
 
129
129
  def base(accessor, arg)
130
- if accessor == :first || (arg&.zero?)
130
+ if accessor == :first || arg&.zero?
131
131
  'min'
132
132
  elsif accessor == :last || arg == -1
133
133
  'max'
@@ -11,8 +11,8 @@ module RuboCop
11
11
  #
12
12
  # Configuration option: MinSize
13
13
  # If set, arrays with fewer elements than this value will not trigger the
14
- # cop. For example, a `MinSize of `3` will not enforce a style on an array
15
- # of 2 or fewer elements.
14
+ # cop. For example, a `MinSize` of `3` will not enforce a style on an
15
+ # array of 2 or fewer elements.
16
16
  #
17
17
  # @example EnforcedStyle: percent (default)
18
18
  # # good
@@ -162,7 +162,7 @@ module RuboCop
162
162
  # `RedundantParentheses` cop is enabled, it will cause an infinite loop
163
163
  # as they compete to add and remove the parentheses respectively.
164
164
  def infinite_loop?
165
- require_parentheses? &&
165
+ (require_parentheses? || require_parentheses_when_complex?) &&
166
166
  redundant_parentheses_enabled?
167
167
  end
168
168
 
@@ -68,28 +68,6 @@ module RuboCop
68
68
  def self.autocorrect_incompatible_with
69
69
  [Layout::HeredocArgumentClosingParenthesis]
70
70
  end
71
-
72
- private
73
-
74
- def avoid_autocorrect?(args)
75
- args.last.hash_type? && args.last.braces? &&
76
- braces_will_be_removed?(args)
77
- end
78
-
79
- # Returns true if running with --auto-correct would remove the braces
80
- # of the last argument.
81
- def braces_will_be_removed?(args)
82
- brace_config = config.for_cop('Style/BracesAroundHashParameters')
83
- return false unless brace_config.fetch('Enabled')
84
- return false if brace_config['AutoCorrect'] == false
85
-
86
- brace_style = brace_config['EnforcedStyle']
87
- return true if brace_style == 'no_braces'
88
-
89
- return false unless brace_style == 'context_dependent'
90
-
91
- args.one? || !args[-2].hash_type?
92
- end
93
71
  end
94
72
  end
95
73
  end
@@ -20,8 +20,14 @@ module RuboCop
20
20
  # a, *b, _ = foo()
21
21
  # # => The correction `a, *b, = foo()` is a syntax error
22
22
  #
23
- # # good if AllowNamedUnderscoreVariables is true
23
+ # @example AllowNamedUnderscoreVariables: true (default)
24
+ # # good
24
25
  # a, b, _something = foo()
26
+ #
27
+ # @example AllowNamedUnderscoreVariables: false
28
+ # # bad
29
+ # a, b, _something = foo()
30
+ #
25
31
  class TrailingUnderscoreVariable < Cop
26
32
  include SurroundingSpace
27
33
  include RangeHelp
@@ -60,7 +60,7 @@ module RuboCop
60
60
  when :module
61
61
  return true
62
62
  else
63
- return true if pnode.method_name == :instance_eval
63
+ return true if pnode.method?(:instance_eval)
64
64
  end
65
65
  end
66
66
  false
@@ -95,9 +95,9 @@ module RuboCop
95
95
  cop_config['IgnoreClassMethods']
96
96
  end
97
97
 
98
- def whitelist
99
- whitelist = cop_config['Whitelist']
100
- Array(whitelist).map(&:to_sym) + [:initialize]
98
+ def allowed_methods
99
+ allowed_methods = cop_config['AllowedMethods']
100
+ Array(allowed_methods).map(&:to_sym) + [:initialize]
101
101
  end
102
102
 
103
103
  def dsl_writer?(method_name)
@@ -124,7 +124,7 @@ module RuboCop
124
124
  PATTERN
125
125
 
126
126
  def allowed_method?(node)
127
- whitelist.include?(node.method_name) ||
127
+ allowed_methods.include?(node.method_name) ||
128
128
  exact_name_match? && !names_match?(node)
129
129
  end
130
130