rubocop 0.67.2 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +86 -233
- data/exe/rubocop +0 -12
- data/lib/rubocop.rb +13 -30
- data/lib/rubocop/ast/builder.rb +4 -0
- data/lib/rubocop/ast/node/alias_node.rb +24 -0
- data/lib/rubocop/ast/node/class_node.rb +31 -0
- data/lib/rubocop/ast/node/module_node.rb +24 -0
- data/lib/rubocop/ast/node/range_node.rb +7 -0
- data/lib/rubocop/ast/node/resbody_node.rb +12 -0
- data/lib/rubocop/ast/node/self_class_node.rb +24 -0
- data/lib/rubocop/cli.rb +40 -4
- data/lib/rubocop/config.rb +9 -7
- data/lib/rubocop/config_loader.rb +48 -7
- data/lib/rubocop/config_loader_resolver.rb +5 -4
- data/lib/rubocop/cop/commissioner.rb +24 -0
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +18 -6
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +12 -14
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +9 -20
- data/lib/rubocop/cop/layout/align_arguments.rb +93 -0
- data/lib/rubocop/cop/layout/align_parameters.rb +57 -33
- data/lib/rubocop/cop/layout/class_structure.rb +5 -5
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +6 -8
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +3 -6
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +1 -2
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -0
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +292 -0
- data/lib/rubocop/cop/layout/{first_parameter_indentation.rb → indent_first_argument.rb} +11 -12
- data/lib/rubocop/cop/layout/{indent_array.rb → indent_first_array_element.rb} +2 -2
- data/lib/rubocop/cop/layout/{indent_hash.rb → indent_first_hash_element.rb} +2 -2
- data/lib/rubocop/cop/layout/indent_first_parameter.rb +96 -0
- data/lib/rubocop/cop/layout/indentation_width.rb +4 -16
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -4
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -16
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -2
- data/lib/rubocop/cop/lint/duplicate_methods.rb +6 -8
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +4 -8
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +157 -0
- data/lib/rubocop/cop/lint/inherit_exception.rb +3 -4
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +18 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -5
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +25 -5
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -6
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -2
- data/lib/rubocop/cop/message_annotator.rb +1 -0
- data/lib/rubocop/cop/metrics/line_length.rb +139 -28
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +3 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +190 -0
- data/lib/rubocop/cop/mixin/{array_hash_indentation.rb → multiline_element_indentation.rb} +3 -2
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -7
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +33 -4
- data/lib/rubocop/cop/rails/active_record_override.rb +23 -8
- data/lib/rubocop/cop/rails/delegate.rb +5 -8
- data/lib/rubocop/cop/rails/environment_comparison.rb +5 -3
- data/lib/rubocop/cop/rails/find_each.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_allow_nil.rb +3 -3
- data/lib/rubocop/cop/rails/reflection_class_name.rb +1 -1
- data/lib/rubocop/cop/rails/skips_model_validations.rb +6 -7
- data/lib/rubocop/cop/rails/time_zone.rb +3 -10
- data/lib/rubocop/cop/rails/validation.rb +3 -0
- data/lib/rubocop/cop/registry.rb +3 -3
- data/lib/rubocop/cop/style/alias.rb +13 -7
- data/lib/rubocop/cop/style/block_delimiters.rb +20 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +19 -21
- data/lib/rubocop/cop/style/class_methods.rb +16 -24
- data/lib/rubocop/cop/style/conditional_assignment.rb +20 -49
- data/lib/rubocop/cop/style/documentation.rb +3 -7
- data/lib/rubocop/cop/style/format_string.rb +18 -21
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +4 -0
- data/lib/rubocop/cop/style/lambda.rb +12 -8
- data/lib/rubocop/cop/style/mixin_grouping.rb +8 -10
- data/lib/rubocop/cop/style/module_function.rb +2 -3
- data/lib/rubocop/cop/style/next.rb +10 -14
- data/lib/rubocop/cop/style/one_line_conditional.rb +5 -3
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -4
- data/lib/rubocop/cop/style/random_with_offset.rb +44 -47
- data/lib/rubocop/cop/style/redundant_return.rb +6 -14
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +3 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +2 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +20 -40
- data/lib/rubocop/cop/style/unless_else.rb +1 -2
- data/lib/rubocop/cop/style/yoda_condition.rb +8 -7
- data/lib/rubocop/cop/util.rb +2 -4
- data/lib/rubocop/file_finder.rb +5 -10
- data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -0
- data/lib/rubocop/node_pattern.rb +304 -170
- data/lib/rubocop/options.rb +4 -1
- data/lib/rubocop/rspec/shared_contexts.rb +3 -0
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop/yaml_duplication_checker.rb +1 -1
- metadata +26 -50
- data/lib/rubocop/cop/performance/caller.rb +0 -69
- data/lib/rubocop/cop/performance/case_when_splat.rb +0 -177
- data/lib/rubocop/cop/performance/casecmp.rb +0 -108
- data/lib/rubocop/cop/performance/chain_array_allocation.rb +0 -78
- data/lib/rubocop/cop/performance/compare_with_block.rb +0 -122
- data/lib/rubocop/cop/performance/count.rb +0 -102
- data/lib/rubocop/cop/performance/detect.rb +0 -110
- data/lib/rubocop/cop/performance/double_start_end_with.rb +0 -94
- data/lib/rubocop/cop/performance/end_with.rb +0 -56
- data/lib/rubocop/cop/performance/fixed_size.rb +0 -97
- data/lib/rubocop/cop/performance/flat_map.rb +0 -78
- data/lib/rubocop/cop/performance/inefficient_hash_search.rb +0 -99
- data/lib/rubocop/cop/performance/open_struct.rb +0 -46
- data/lib/rubocop/cop/performance/range_include.rb +0 -50
- data/lib/rubocop/cop/performance/redundant_block_call.rb +0 -93
- data/lib/rubocop/cop/performance/redundant_match.rb +0 -56
- data/lib/rubocop/cop/performance/redundant_merge.rb +0 -183
- data/lib/rubocop/cop/performance/regexp_match.rb +0 -265
- data/lib/rubocop/cop/performance/reverse_each.rb +0 -42
- data/lib/rubocop/cop/performance/size.rb +0 -77
- data/lib/rubocop/cop/performance/start_with.rb +0 -59
- data/lib/rubocop/cop/performance/string_replacement.rb +0 -173
- data/lib/rubocop/cop/performance/times_map.rb +0 -71
- data/lib/rubocop/cop/performance/unfreeze_string.rb +0 -50
- 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
|
-
|
75
|
-
|
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
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
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
|
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
|
-
#
|
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
|
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
|
26
|
-
'
|
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 :
|
29
|
-
(masgn (mlhs ...) (send (
|
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
|
-
|
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
|
-
#
|
7
|
-
# as
|
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
|
-
|
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
|
-
|
68
|
-
|
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
|
13
|
-
#
|
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
|
18
|
-
#
|
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
|
24
|
-
#
|
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
|
29
|
-
#
|
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
|
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
|
78
|
+
'following the first line of a multi-line method definition.'.freeze
|
38
79
|
|
39
|
-
def
|
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
|
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(
|
56
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
277
|
+
return :initializer if node.method?(:initialize)
|
278
278
|
|
279
279
|
return "#{node_visibility(node)}_methods"
|
280
280
|
end
|