rubocop 0.67.2 → 0.68.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +86 -233
  4. data/exe/rubocop +0 -12
  5. data/lib/rubocop.rb +13 -30
  6. data/lib/rubocop/ast/builder.rb +4 -0
  7. data/lib/rubocop/ast/node/alias_node.rb +24 -0
  8. data/lib/rubocop/ast/node/class_node.rb +31 -0
  9. data/lib/rubocop/ast/node/module_node.rb +24 -0
  10. data/lib/rubocop/ast/node/range_node.rb +7 -0
  11. data/lib/rubocop/ast/node/resbody_node.rb +12 -0
  12. data/lib/rubocop/ast/node/self_class_node.rb +24 -0
  13. data/lib/rubocop/cli.rb +40 -4
  14. data/lib/rubocop/config.rb +9 -7
  15. data/lib/rubocop/config_loader.rb +48 -7
  16. data/lib/rubocop/config_loader_resolver.rb +5 -4
  17. data/lib/rubocop/cop/commissioner.rb +24 -0
  18. data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +18 -6
  19. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +12 -14
  20. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +9 -20
  21. data/lib/rubocop/cop/layout/align_arguments.rb +93 -0
  22. data/lib/rubocop/cop/layout/align_parameters.rb +57 -33
  23. data/lib/rubocop/cop/layout/class_structure.rb +5 -5
  24. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +6 -8
  25. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +3 -6
  26. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +1 -2
  27. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -0
  28. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +292 -0
  29. data/lib/rubocop/cop/layout/{first_parameter_indentation.rb → indent_first_argument.rb} +11 -12
  30. data/lib/rubocop/cop/layout/{indent_array.rb → indent_first_array_element.rb} +2 -2
  31. data/lib/rubocop/cop/layout/{indent_hash.rb → indent_first_hash_element.rb} +2 -2
  32. data/lib/rubocop/cop/layout/indent_first_parameter.rb +96 -0
  33. data/lib/rubocop/cop/layout/indentation_width.rb +4 -16
  34. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -4
  35. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -16
  36. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -2
  37. data/lib/rubocop/cop/lint/duplicate_methods.rb +6 -8
  38. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +4 -8
  39. data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +157 -0
  40. data/lib/rubocop/cop/lint/inherit_exception.rb +3 -4
  41. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +18 -1
  42. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -5
  43. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +25 -5
  44. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -6
  45. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -2
  46. data/lib/rubocop/cop/message_annotator.rb +1 -0
  47. data/lib/rubocop/cop/metrics/line_length.rb +139 -28
  48. data/lib/rubocop/cop/metrics/perceived_complexity.rb +3 -4
  49. data/lib/rubocop/cop/mixin/check_line_breakable.rb +190 -0
  50. data/lib/rubocop/cop/mixin/{array_hash_indentation.rb → multiline_element_indentation.rb} +3 -2
  51. data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -7
  52. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +33 -4
  53. data/lib/rubocop/cop/rails/active_record_override.rb +23 -8
  54. data/lib/rubocop/cop/rails/delegate.rb +5 -8
  55. data/lib/rubocop/cop/rails/environment_comparison.rb +5 -3
  56. data/lib/rubocop/cop/rails/find_each.rb +1 -1
  57. data/lib/rubocop/cop/rails/redundant_allow_nil.rb +3 -3
  58. data/lib/rubocop/cop/rails/reflection_class_name.rb +1 -1
  59. data/lib/rubocop/cop/rails/skips_model_validations.rb +6 -7
  60. data/lib/rubocop/cop/rails/time_zone.rb +3 -10
  61. data/lib/rubocop/cop/rails/validation.rb +3 -0
  62. data/lib/rubocop/cop/registry.rb +3 -3
  63. data/lib/rubocop/cop/style/alias.rb +13 -7
  64. data/lib/rubocop/cop/style/block_delimiters.rb +20 -0
  65. data/lib/rubocop/cop/style/class_and_module_children.rb +19 -21
  66. data/lib/rubocop/cop/style/class_methods.rb +16 -24
  67. data/lib/rubocop/cop/style/conditional_assignment.rb +20 -49
  68. data/lib/rubocop/cop/style/documentation.rb +3 -7
  69. data/lib/rubocop/cop/style/format_string.rb +18 -21
  70. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  71. data/lib/rubocop/cop/style/inverse_methods.rb +4 -0
  72. data/lib/rubocop/cop/style/lambda.rb +12 -8
  73. data/lib/rubocop/cop/style/mixin_grouping.rb +8 -10
  74. data/lib/rubocop/cop/style/module_function.rb +2 -3
  75. data/lib/rubocop/cop/style/next.rb +10 -14
  76. data/lib/rubocop/cop/style/one_line_conditional.rb +5 -3
  77. data/lib/rubocop/cop/style/optional_arguments.rb +1 -4
  78. data/lib/rubocop/cop/style/random_with_offset.rb +44 -47
  79. data/lib/rubocop/cop/style/redundant_return.rb +6 -14
  80. data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -1
  81. data/lib/rubocop/cop/style/safe_navigation.rb +3 -0
  82. data/lib/rubocop/cop/style/struct_inheritance.rb +2 -3
  83. data/lib/rubocop/cop/style/symbol_proc.rb +20 -40
  84. data/lib/rubocop/cop/style/unless_else.rb +1 -2
  85. data/lib/rubocop/cop/style/yoda_condition.rb +8 -7
  86. data/lib/rubocop/cop/util.rb +2 -4
  87. data/lib/rubocop/file_finder.rb +5 -10
  88. data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -0
  89. data/lib/rubocop/node_pattern.rb +304 -170
  90. data/lib/rubocop/options.rb +4 -1
  91. data/lib/rubocop/rspec/shared_contexts.rb +3 -0
  92. data/lib/rubocop/version.rb +1 -1
  93. data/lib/rubocop/yaml_duplication_checker.rb +1 -1
  94. metadata +26 -50
  95. data/lib/rubocop/cop/performance/caller.rb +0 -69
  96. data/lib/rubocop/cop/performance/case_when_splat.rb +0 -177
  97. data/lib/rubocop/cop/performance/casecmp.rb +0 -108
  98. data/lib/rubocop/cop/performance/chain_array_allocation.rb +0 -78
  99. data/lib/rubocop/cop/performance/compare_with_block.rb +0 -122
  100. data/lib/rubocop/cop/performance/count.rb +0 -102
  101. data/lib/rubocop/cop/performance/detect.rb +0 -110
  102. data/lib/rubocop/cop/performance/double_start_end_with.rb +0 -94
  103. data/lib/rubocop/cop/performance/end_with.rb +0 -56
  104. data/lib/rubocop/cop/performance/fixed_size.rb +0 -97
  105. data/lib/rubocop/cop/performance/flat_map.rb +0 -78
  106. data/lib/rubocop/cop/performance/inefficient_hash_search.rb +0 -99
  107. data/lib/rubocop/cop/performance/open_struct.rb +0 -46
  108. data/lib/rubocop/cop/performance/range_include.rb +0 -50
  109. data/lib/rubocop/cop/performance/redundant_block_call.rb +0 -93
  110. data/lib/rubocop/cop/performance/redundant_match.rb +0 -56
  111. data/lib/rubocop/cop/performance/redundant_merge.rb +0 -183
  112. data/lib/rubocop/cop/performance/regexp_match.rb +0 -265
  113. data/lib/rubocop/cop/performance/reverse_each.rb +0 -42
  114. data/lib/rubocop/cop/performance/size.rb +0 -77
  115. data/lib/rubocop/cop/performance/start_with.rb +0 -59
  116. data/lib/rubocop/cop/performance/string_replacement.rb +0 -173
  117. data/lib/rubocop/cop/performance/times_map.rb +0 -71
  118. data/lib/rubocop/cop/performance/unfreeze_string.rb +0 -50
  119. data/lib/rubocop/cop/performance/uri_default_parser.rb +0 -47
@@ -71,9 +71,8 @@ module RuboCop
71
71
  config = handle_disabled_by_default(config, default_configuration)
72
72
  end
73
73
 
74
- Config.new(merge(default_configuration, config,
75
- inherit_mode: config['inherit_mode'] || {}),
76
- config_file)
74
+ opts = { inherit_mode: config['inherit_mode'] || {}, unset_nil: true }
75
+ Config.new(merge(default_configuration, config, opts), config_file)
77
76
  end
78
77
 
79
78
  # Return a recursive merge of two hashes. That is, a normal hash merge,
@@ -85,7 +84,9 @@ module RuboCop
85
84
  result = base_hash.merge(derived_hash)
86
85
  keys_appearing_in_both = base_hash.keys & derived_hash.keys
87
86
  keys_appearing_in_both.each do |key|
88
- if base_hash[key].is_a?(Hash)
87
+ if opts[:unset_nil] && derived_hash[key].nil?
88
+ result.delete(key)
89
+ elsif base_hash[key].is_a?(Hash)
89
90
  result[key] = merge(base_hash[key], derived_hash[key], **opts)
90
91
  elsif should_union?(base_hash, key, opts[:inherit_mode])
91
92
  result[key] = base_hash[key] | derived_hash[key]
@@ -44,6 +44,7 @@ module RuboCop
44
44
  invoke_custom_processing(@cops, processed_source)
45
45
  invoke_custom_processing(@forces, processed_source)
46
46
  walk(processed_source.ast) unless processed_source.blank?
47
+ invoke_custom_post_walk_processing(@cops, processed_source)
47
48
  @cops.flat_map(&:offenses)
48
49
  end
49
50
 
@@ -89,6 +90,10 @@ module RuboCop
89
90
  # If they define the #investigate method, all input parameters passed
90
91
  # to the commissioner will be passed to the cop too in order to do
91
92
  # its own processing.
93
+ #
94
+ # These custom processors are invoked before the AST traversal,
95
+ # so they can build initial state that is later used by callbacks
96
+ # during the AST traversal.
92
97
  def invoke_custom_processing(cops_or_forces, processed_source)
93
98
  cops_or_forces.each do |cop|
94
99
  next unless cop.respond_to?(:investigate)
@@ -99,6 +104,25 @@ module RuboCop
99
104
  end
100
105
  end
101
106
 
107
+ # There are cops that require their own custom processing **after**
108
+ # the AST traversal. By performing the walk before invoking these
109
+ # custom processors, we allow these cops to build their own
110
+ # state during the primary AST traversal instead of performing their
111
+ # own AST traversals. Minimizing the number of walks is more efficient.
112
+ #
113
+ # If they define the #investigate_post_walk method, all input parameters
114
+ # passed to the commissioner will be passed to the cop too in order to do
115
+ # its own processing.
116
+ def invoke_custom_post_walk_processing(cops, processed_source)
117
+ cops.each do |cop|
118
+ next unless cop.respond_to?(:investigate_post_walk)
119
+
120
+ with_cop_error_handling(cop) do
121
+ cop.investigate_post_walk(processed_source)
122
+ end
123
+ end
124
+ end
125
+
102
126
  # Allow blind rescues here, since we're absorbing and packaging or
103
127
  # re-raising exceptions that can be raised from within the individual
104
128
  # cops' `#investigate` methods.
@@ -15,14 +15,26 @@ module RuboCop
15
15
  @processed_source = processed_source
16
16
 
17
17
  if node.blockarg_type?
18
+ correct_for_blockarg_type(node)
19
+ else
18
20
  lambda do |corrector|
19
- range = range_with_surrounding_space(range: node.source_range,
20
- side: :left)
21
- range = range_with_surrounding_comma(range, :left)
22
- corrector.remove(range)
21
+ variable_name = if node.optarg_type?
22
+ node.node_parts[0]
23
+ else
24
+ # Extract only a var name without splat (`*`)
25
+ node.source.gsub(/\A\*+/, '')
26
+ end
27
+ corrector.replace(node.loc.name, "_#{variable_name}")
23
28
  end
24
- else
25
- ->(corrector) { corrector.insert_before(node.loc.name, '_') }
29
+ end
30
+ end
31
+
32
+ def correct_for_blockarg_type(node)
33
+ lambda do |corrector|
34
+ range = range_with_surrounding_space(range: node.source_range,
35
+ side: :left)
36
+ range = range_with_surrounding_comma(range, :left)
37
+ corrector.remove(range)
26
38
  end
27
39
  end
28
40
  end
@@ -3,34 +3,32 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module InternalAffairs
6
- # Checks that node destructuring is done either using the node
7
- # extensions or using a splat.
6
+ # Checks that node destructuring is using the node extensions.
8
7
  #
9
8
  # @example Using splat expansion
10
9
  #
11
10
  # # bad
12
- # receiver, method_name, arguments = send_node.children
13
- #
14
- # # good
15
- # receiver, method_name, arguments = *send_node
16
- #
17
- # @example Using node extensions
11
+ # _receiver, method_name, _arguments = send_node.children
18
12
  #
19
13
  # # bad
20
- # _receiver, method_name, _arguments = send_node.children
14
+ # _receiver, method_name, _arguments = *send_node
21
15
  #
22
16
  # # good
23
17
  # method_name = send_node.method_name
24
18
  class NodeDestructuring < Cop
25
- MSG = 'Use the methods provided with the node extensions or ' \
26
- 'destructure the node using `*`.'.freeze
19
+ MSG = 'Use the methods provided with the node extensions instead ' \
20
+ 'of manually destructuring nodes.'.freeze
21
+
22
+ def_node_matcher :node_variable?, <<-PATTERN
23
+ {(lvar [#node_suffix? _]) (send nil? [#node_suffix? _])}
24
+ PATTERN
27
25
 
28
- def_node_matcher :node_children_destructuring?, <<-PATTERN
29
- (masgn (mlhs ...) (send (send nil? [#node_suffix? _]) :children))
26
+ def_node_matcher :node_destructuring?, <<-PATTERN
27
+ {(masgn (mlhs ...) {(send #node_variable? :children) (array (splat #node_variable?))})}
30
28
  PATTERN
31
29
 
32
30
  def on_masgn(node)
33
- node_children_destructuring?(node) do
31
+ node_destructuring?(node) do
34
32
  add_offense(node)
35
33
  end
36
34
  end
@@ -3,8 +3,9 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Layout
6
- # Modifiers should be indented as deep as method definitions, or as deep
7
- # as the class/module keyword, depending on configuration.
6
+ # Bare access modifiers (those not applying to specific methods) should be
7
+ # indented as deep as method definitions, or as deep as the class/module
8
+ # keyword, depending on configuration.
8
9
  #
9
10
  # @example EnforcedStyle: indent (default)
10
11
  # # bad
@@ -39,23 +40,13 @@ module RuboCop
39
40
  MSG = '%<style>s access modifiers like `%<node>s`.'.freeze
40
41
 
41
42
  def on_class(node)
42
- _name, _base_class, body = *node
43
- check_body(body, node)
44
- end
45
-
46
- def on_sclass(node)
47
- _name, body = *node
48
- check_body(body, node)
49
- end
43
+ return unless node.body && node.body.begin_type?
50
44
 
51
- def on_module(node)
52
- _name, body = *node
53
- check_body(body, node)
54
- end
55
-
56
- def on_block(node)
57
45
  check_body(node.body, node)
58
46
  end
47
+ alias on_sclass on_class
48
+ alias on_module on_class
49
+ alias on_block on_class
59
50
 
60
51
  def autocorrect(node)
61
52
  AlignmentCorrector.correct(processed_source, node, @column_delta)
@@ -64,10 +55,8 @@ module RuboCop
64
55
  private
65
56
 
66
57
  def check_body(body, node)
67
- return if body.nil? # Empty class etc.
68
- return unless body.begin_type?
69
-
70
- modifiers = body.each_child_node(:send).select(&:access_modifier?)
58
+ modifiers = body.each_child_node(:send)
59
+ .select(&:bare_access_modifier?)
71
60
  end_range = node.loc.end
72
61
 
73
62
  modifiers.each { |modifier| check_modifier(modifier, end_range) }
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Layout
6
+ # Here we check if the arguments on a multi-line method
7
+ # definition are aligned.
8
+ #
9
+ # @example EnforcedStyle: with_first_argument (default)
10
+ # # good
11
+ #
12
+ # foo :bar,
13
+ # :baz
14
+ #
15
+ # foo(
16
+ # :bar,
17
+ # :baz
18
+ # )
19
+ #
20
+ # # bad
21
+ #
22
+ # foo :bar,
23
+ # :baz
24
+ #
25
+ # foo(
26
+ # :bar,
27
+ # :baz
28
+ # )
29
+ #
30
+ # @example EnforcedStyle: with_fixed_indentation
31
+ # # good
32
+ #
33
+ # foo :bar,
34
+ # :baz
35
+ #
36
+ # # bad
37
+ #
38
+ # foo :bar,
39
+ # :baz
40
+ class AlignArguments < Cop
41
+ include Alignment
42
+
43
+ ALIGN_PARAMS_MSG = 'Align the arguments of a method call if ' \
44
+ 'they span more than one line.'.freeze
45
+
46
+ FIXED_INDENT_MSG = 'Use one level of indentation for arguments ' \
47
+ 'following the first line of a multi-line method call.'.freeze
48
+
49
+ def on_send(node)
50
+ return if node.arguments.size < 2 ||
51
+ node.send_type? && node.method?(:[]=)
52
+
53
+ check_alignment(node.arguments, base_column(node, node.arguments))
54
+ end
55
+ alias on_csend on_send
56
+
57
+ def autocorrect(node)
58
+ AlignmentCorrector.correct(processed_source, node, column_delta)
59
+ end
60
+
61
+ private
62
+
63
+ def message(_node)
64
+ fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
65
+ end
66
+
67
+ def fixed_indentation?
68
+ cop_config['EnforcedStyle'] == 'with_fixed_indentation'
69
+ end
70
+
71
+ def base_column(node, args)
72
+ if fixed_indentation?
73
+ lineno = target_method_lineno(node)
74
+ line = node.source_range.source_buffer.source_line(lineno)
75
+ indentation_of_line = /\S.*/.match(line).begin(0)
76
+ indentation_of_line + configured_indentation_width
77
+ else
78
+ display_column(args.first.source_range)
79
+ end
80
+ end
81
+
82
+ def target_method_lineno(node)
83
+ if node.loc.selector
84
+ node.loc.selector.line
85
+ else
86
+ # l.(1) has no selector, so we use the opening parenthesis instead
87
+ node.loc.begin.line
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -6,45 +6,83 @@ module RuboCop
6
6
  # Here we check if the parameters on a multi-line method call or
7
7
  # definition are aligned.
8
8
  #
9
+ # To set the alignment of the first argument, use the cop
10
+ # FirstParameterIndentation.
11
+ #
9
12
  # @example EnforcedStyle: with_first_parameter (default)
10
13
  # # good
11
14
  #
12
- # foo :bar,
13
- # :baz
15
+ # def foo(bar,
16
+ # baz)
17
+ # 123
18
+ # end
19
+ #
20
+ # def foo(
21
+ # bar,
22
+ # baz
23
+ # )
24
+ # 123
25
+ # end
26
+ #
27
+ # # bad
28
+ #
29
+ # def foo(bar,
30
+ # baz)
31
+ # 123
32
+ # end
14
33
  #
15
34
  # # bad
16
35
  #
17
- # foo :bar,
18
- # :baz
36
+ # def foo(
37
+ # bar,
38
+ # baz)
39
+ # 123
40
+ # end
19
41
  #
20
42
  # @example EnforcedStyle: with_fixed_indentation
21
43
  # # good
22
44
  #
23
- # foo :bar,
24
- # :baz
45
+ # def foo(bar,
46
+ # baz)
47
+ # 123
48
+ # end
49
+ #
50
+ # def foo(
51
+ # bar,
52
+ # baz
53
+ # )
54
+ # 123
55
+ # end
25
56
  #
26
57
  # # bad
27
58
  #
28
- # foo :bar,
29
- # :baz
59
+ # def foo(bar,
60
+ # baz)
61
+ # 123
62
+ # end
63
+ #
64
+ # # bad
65
+ #
66
+ # def foo(
67
+ # bar,
68
+ # baz)
69
+ # 123
70
+ # end
30
71
  class AlignParameters < Cop
31
72
  include Alignment
32
73
 
33
- ALIGN_PARAMS_MSG = 'Align the parameters of a method %<type>s if ' \
74
+ ALIGN_PARAMS_MSG = 'Align the parameters of a method definition if ' \
34
75
  'they span more than one line.'.freeze
35
76
 
36
77
  FIXED_INDENT_MSG = 'Use one level of indentation for parameters ' \
37
- 'following the first line of a multi-line method %<type>s.'.freeze
78
+ 'following the first line of a multi-line method definition.'.freeze
38
79
 
39
- def on_send(node)
40
- return if node.arguments.size < 2 ||
41
- node.send_type? && node.method?(:[]=)
80
+ def on_def(node)
81
+ return if node.arguments.size < 2
42
82
 
43
83
  check_alignment(node.arguments, base_column(node, node.arguments))
44
84
  end
45
- alias on_csend on_send
46
- alias on_def on_send
47
- alias on_defs on_send
85
+ alias on_defs on_def
48
86
 
49
87
  def autocorrect(node)
50
88
  AlignmentCorrector.correct(processed_source, node, column_delta)
@@ -52,15 +90,8 @@ module RuboCop
52
90
 
53
91
  private
54
92
 
55
- def message(node)
56
- type = if node && (node.parent.send_type? || node.parent.csend_type?)
57
- 'call'
58
- else
59
- 'definition'
60
- end
61
- msg = fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
62
-
63
- format(msg, type: type)
93
+ def message(_node)
94
+ fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
64
95
  end
65
96
 
66
97
  def fixed_indentation?
@@ -79,14 +110,7 @@ module RuboCop
79
110
  end
80
111
 
81
112
  def target_method_lineno(node)
82
- if node.def_type? || node.defs_type?
83
- node.loc.keyword.line
84
- elsif node.loc.selector
85
- node.loc.selector.line
86
- else
87
- # l.(1) has no selector, so we use the opening parenthesis instead
88
- node.loc.begin.line
89
- end
113
+ node.loc.keyword.line
90
114
  end
91
115
  end
92
116
  end
@@ -223,7 +223,8 @@ module RuboCop
223
223
  end
224
224
 
225
225
  def class_elements(class_node)
226
- *, class_def = class_node.children
226
+ class_def = class_node.body
227
+
227
228
  return [] unless class_def
228
229
 
229
230
  if class_def.def_type? || class_def.send_type?
@@ -240,8 +241,8 @@ module RuboCop
240
241
  end
241
242
 
242
243
  def node_visibility(node)
243
- _, method_name, = *find_visibility_start(node)
244
- method_name || :public
244
+ scope = find_visibility_start(node)
245
+ scope && scope.method_name || :public
245
246
  end
246
247
 
247
248
  def find_visibility_start(node)
@@ -272,9 +273,8 @@ module RuboCop
272
273
  end
273
274
 
274
275
  def humanize_node(node)
275
- method_name, = *node
276
276
  if node.def_type?
277
- return :initializer if method_name == :initialize
277
+ return :initializer if node.method?(:initialize)
278
278
 
279
279
  return "#{node_visibility(node)}_methods"
280
280
  end