rubocop 0.39.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/config/default.yml +65 -2
- data/config/disabled.yml +0 -28
- data/config/enabled.yml +40 -0
- data/lib/rubocop.rb +3 -0
- data/lib/rubocop/ast_node.rb +28 -13
- data/lib/rubocop/cached_data.rb +15 -2
- data/lib/rubocop/cli.rb +24 -8
- data/lib/rubocop/config.rb +3 -3
- data/lib/rubocop/config_loader.rb +0 -7
- data/lib/rubocop/cop/cop.rb +2 -2
- data/lib/rubocop/cop/lint/condition_position.rb +3 -1
- data/lib/rubocop/cop/lint/else_layout.rb +3 -2
- data/lib/rubocop/cop/lint/end_alignment.rb +2 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +15 -9
- data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +2 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +86 -20
- data/lib/rubocop/cop/lint/useless_array_splat.rb +56 -0
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +11 -25
- data/lib/rubocop/cop/mixin/if_node.rb +4 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +14 -12
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +75 -9
- data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +1 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +15 -5
- data/lib/rubocop/cop/performance/case_when_splat.rb +71 -44
- data/lib/rubocop/cop/performance/detect.rb +28 -18
- data/lib/rubocop/cop/performance/end_with.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_merge.rb +29 -11
- data/lib/rubocop/cop/performance/start_with.rb +1 -1
- data/lib/rubocop/cop/performance/string_replacement.rb +39 -20
- data/lib/rubocop/cop/rails/action_filter.rb +1 -2
- data/lib/rubocop/cop/rails/date.rb +2 -5
- data/lib/rubocop/cop/rails/time_zone.rb +3 -6
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +57 -0
- data/lib/rubocop/cop/style/alias.rb +10 -3
- data/lib/rubocop/cop/style/align_parameters.rb +8 -2
- data/lib/rubocop/cop/style/and_or.rb +29 -21
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +1 -2
- data/lib/rubocop/cop/style/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +13 -7
- data/lib/rubocop/cop/style/empty_case_condition.rb +96 -0
- data/lib/rubocop/cop/style/encoding.rb +9 -5
- data/lib/rubocop/cop/style/extra_spacing.rb +22 -7
- data/lib/rubocop/cop/style/file_name.rb +7 -2
- data/lib/rubocop/cop/style/guard_clause.rb +18 -10
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -1
- data/lib/rubocop/cop/style/indentation_width.rb +7 -4
- data/lib/rubocop/cop/style/lambda.rb +98 -30
- data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -0
- data/lib/rubocop/cop/style/multiline_array_brace_layout.rb +34 -9
- data/lib/rubocop/cop/style/multiline_assignment_layout.rb +2 -1
- data/lib/rubocop/cop/style/multiline_hash_brace_layout.rb +42 -17
- data/lib/rubocop/cop/style/multiline_method_call_brace_layout.rb +39 -14
- data/lib/rubocop/cop/style/multiline_method_definition_brace_layout.rb +36 -15
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +8 -6
- data/lib/rubocop/cop/style/negated_while.rb +2 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +15 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +5 -8
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +5 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
- data/lib/rubocop/cop/style/raise_args.rb +70 -7
- data/lib/rubocop/cop/style/redundant_exception.rb +34 -20
- data/lib/rubocop/cop/style/redundant_parentheses.rb +27 -1
- data/lib/rubocop/cop/style/space_after_colon.rb +14 -10
- data/lib/rubocop/cop/style/space_after_comma.rb +5 -0
- data/lib/rubocop/cop/style/space_after_not.rb +3 -4
- data/lib/rubocop/cop/style/space_after_semicolon.rb +5 -0
- data/lib/rubocop/cop/style/space_around_operators.rb +2 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +4 -2
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_methods.rb +1 -2
- data/lib/rubocop/cop/style/symbol_proc.rb +7 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +25 -0
- data/lib/rubocop/cop/style/word_array.rb +50 -22
- data/lib/rubocop/cop/util.rb +0 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +38 -22
- data/lib/rubocop/options.rb +45 -10
- data/lib/rubocop/path_util.rb +2 -34
- data/lib/rubocop/result_cache.rb +10 -4
- data/lib/rubocop/runner.rb +5 -3
- data/lib/rubocop/version.rb +1 -1
- metadata +7 -4
data/lib/rubocop/cli.rb
CHANGED
@@ -97,6 +97,8 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def print_available_cops
|
100
|
+
# Load the configs so the require()s are done for custom cops
|
101
|
+
@config_store.for(Dir.pwd)
|
100
102
|
cops = Cop::Cop.all
|
101
103
|
show_all = @options[:show_cops].empty?
|
102
104
|
|
@@ -108,25 +110,39 @@ module RuboCop
|
|
108
110
|
end
|
109
111
|
|
110
112
|
def print_cops_of_type(cops, type, show_all)
|
111
|
-
|
113
|
+
selected_cops = if show_all
|
114
|
+
cops_of_type(cops, type)
|
115
|
+
else
|
116
|
+
selected_cops_of_type(cops, type)
|
117
|
+
end
|
112
118
|
|
113
119
|
if show_all
|
114
|
-
puts "# Type '#{type.to_s.capitalize}' (#{
|
115
|
-
end
|
116
|
-
|
117
|
-
selected_cops = cops_of_this_type.select do |cop|
|
118
|
-
show_all || @options[:show_cops].include?(cop.cop_name)
|
120
|
+
puts "# Type '#{type.to_s.capitalize}' (#{selected_cops.size}):"
|
119
121
|
end
|
120
122
|
|
121
123
|
selected_cops.each do |cop|
|
122
124
|
puts '# Supports --auto-correct' if cop.new.support_autocorrect?
|
123
125
|
puts "#{cop.cop_name}:"
|
124
|
-
|
125
|
-
puts cnf.to_yaml.lines.to_a.butfirst.map { |line| ' ' + line }
|
126
|
+
puts config_lines(cop)
|
126
127
|
puts
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
131
|
+
def selected_cops_of_type(cops, type)
|
132
|
+
cops_of_type(cops, type).select do |cop|
|
133
|
+
@options[:show_cops].include?(cop.cop_name)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def cops_of_type(cops, type)
|
138
|
+
cops.with_type(type).sort_by!(&:cop_name)
|
139
|
+
end
|
140
|
+
|
141
|
+
def config_lines(cop)
|
142
|
+
cnf = @config_store.for(Dir.pwd).for_cop(cop)
|
143
|
+
cnf.to_yaml.lines.to_a.butfirst.map { |line| ' ' + line }
|
144
|
+
end
|
145
|
+
|
130
146
|
def display_warning_summary(warnings)
|
131
147
|
return if warnings.empty?
|
132
148
|
|
data/lib/rubocop/config.rb
CHANGED
@@ -146,8 +146,8 @@ module RuboCop
|
|
146
146
|
absolute_file_path = File.expand_path(file)
|
147
147
|
|
148
148
|
patterns_to_include.any? do |pattern|
|
149
|
-
match_path?(pattern, relative_file_path
|
150
|
-
match_path?(pattern, absolute_file_path
|
149
|
+
match_path?(pattern, relative_file_path) ||
|
150
|
+
match_path?(pattern, absolute_file_path)
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -162,7 +162,7 @@ module RuboCop
|
|
162
162
|
def file_to_exclude?(file)
|
163
163
|
file = File.expand_path(file)
|
164
164
|
patterns_to_exclude.any? do |pattern|
|
165
|
-
match_path?(pattern, file
|
165
|
+
match_path?(pattern, file)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -73,7 +73,6 @@ module RuboCop
|
|
73
73
|
|
74
74
|
if auto_gen_config?
|
75
75
|
next if f.include?(AUTO_GENERATED_FILE)
|
76
|
-
old_auto_config_file_warning if f.include?('rubocop-todo.yml')
|
77
76
|
end
|
78
77
|
|
79
78
|
print 'Inheriting ' if debug?
|
@@ -193,12 +192,6 @@ module RuboCop
|
|
193
192
|
dirs_to_search << Dir.home if ENV.key? 'HOME'
|
194
193
|
dirs_to_search
|
195
194
|
end
|
196
|
-
|
197
|
-
def old_auto_config_file_warning
|
198
|
-
raise RuboCop::Error,
|
199
|
-
'rubocop-todo.yml is obsolete; it must be called' \
|
200
|
-
" #{AUTO_GENERATED_FILE} instead"
|
201
|
-
end
|
202
195
|
end
|
203
196
|
end
|
204
197
|
end
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -248,11 +248,11 @@ module RuboCop
|
|
248
248
|
path = nil
|
249
249
|
patterns.any? do |pattern|
|
250
250
|
# Try to match the absolute path, as Exclude properties are absolute.
|
251
|
-
next true if match_path?(pattern, file
|
251
|
+
next true if match_path?(pattern, file)
|
252
252
|
|
253
253
|
# Try with relative path.
|
254
254
|
path ||= config.path_relative_to_config(file)
|
255
|
-
match_path?(pattern, path
|
255
|
+
match_path?(pattern, path)
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
@@ -16,9 +16,10 @@ module RuboCop
|
|
16
16
|
# do_that
|
17
17
|
# end
|
18
18
|
class ElseLayout < Cop
|
19
|
+
include IfNode
|
20
|
+
|
19
21
|
def on_if(node)
|
20
|
-
|
21
|
-
return if node.loc.respond_to?(:question)
|
22
|
+
return if ternary?(node)
|
22
23
|
# ignore modifier ops & elsif nodes
|
23
24
|
return unless node.loc.end
|
24
25
|
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def on_if(node)
|
48
|
-
check_other_alignment(node) unless
|
48
|
+
check_other_alignment(node) unless ternary?(node)
|
49
49
|
end
|
50
50
|
|
51
51
|
def on_while(node)
|
@@ -69,7 +69,7 @@ module RuboCop
|
|
69
69
|
# we check if it's an if/unless/while/until.
|
70
70
|
return unless (rhs = first_part_of_call_chain(rhs))
|
71
71
|
return unless [:if, :while, :until, :case].include?(rhs.type)
|
72
|
-
return if
|
72
|
+
return if ternary?(rhs)
|
73
73
|
|
74
74
|
check_asgn_alignment(node, rhs)
|
75
75
|
end
|
@@ -22,14 +22,6 @@ module RuboCop
|
|
22
22
|
MSG = 'Method definitions must not be nested. ' \
|
23
23
|
'Use `lambda` instead.'.freeze
|
24
24
|
|
25
|
-
def_node_matcher :eval_call?, <<-PATTERN
|
26
|
-
(block (send _ {:instance_eval :class_eval :module_eval} ...) ...)
|
27
|
-
PATTERN
|
28
|
-
|
29
|
-
def_node_matcher :class_or_module_new_call?, <<-PATTERN
|
30
|
-
(block (send (const nil {:Class :Module}) :new ...) ...)
|
31
|
-
PATTERN
|
32
|
-
|
33
25
|
def on_method_def(node, _method_name, _args, _body)
|
34
26
|
find_nested_defs(node) do |nested_def_node|
|
35
27
|
add_offense(nested_def_node, :expression)
|
@@ -44,11 +36,25 @@ module RuboCop
|
|
44
36
|
subject, = *child
|
45
37
|
next if subject.lvar_type?
|
46
38
|
yield child
|
47
|
-
elsif !
|
39
|
+
elsif !ignored_child?(child)
|
48
40
|
find_nested_defs(child, &block)
|
49
41
|
end
|
50
42
|
end
|
51
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def ignored_child?(child)
|
48
|
+
eval_call?(child) || class_or_module_or_struct_new_call?(child)
|
49
|
+
end
|
50
|
+
|
51
|
+
def_node_matcher :eval_call?, <<-PATTERN
|
52
|
+
(block (send _ {:instance_eval :class_eval :module_eval} ...) ...)
|
53
|
+
PATTERN
|
54
|
+
|
55
|
+
def_node_matcher :class_or_module_or_struct_new_call?, <<-PATTERN
|
56
|
+
(block (send (const nil {:Class :Module :Struct}) :new ...) ...)
|
57
|
+
PATTERN
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
return if parentheses?(node)
|
31
31
|
return if args.empty?
|
32
32
|
|
33
|
-
if
|
33
|
+
if ternary?(args.first)
|
34
34
|
check_ternary(args.first, node)
|
35
35
|
elsif predicate?(method_name)
|
36
36
|
# We're only checking predicate methods. There would be false
|
@@ -16,6 +16,8 @@ module RuboCop
|
|
16
16
|
|
17
17
|
def check_argument(variable)
|
18
18
|
return unless variable.block_argument?
|
19
|
+
return if variable.keyword_argument? &&
|
20
|
+
cop_config && cop_config['AllowUnusedKeywordArguments']
|
19
21
|
|
20
22
|
if cop_config['IgnoreEmptyBlocks']
|
21
23
|
_send, _args, body = *variable.scope.node
|
@@ -4,35 +4,61 @@
|
|
4
4
|
module RuboCop
|
5
5
|
module Cop
|
6
6
|
module Lint
|
7
|
-
# This cop checks for redundant access modifiers, including those with
|
8
|
-
#
|
9
|
-
#
|
7
|
+
# This cop checks for redundant access modifiers, including those with no
|
8
|
+
# code, those which are repeated, and leading `public` modifiers in a
|
9
|
+
# class or module body. Conditionally-defined methods are considered as
|
10
|
+
# always being defined, and thus access modifiers guarding such methods
|
11
|
+
# are not redundant.
|
10
12
|
#
|
11
13
|
# @example
|
12
14
|
#
|
13
15
|
# class Foo
|
14
|
-
# public # this is redundant
|
16
|
+
# public # this is redundant (default access is public)
|
15
17
|
#
|
16
18
|
# def method
|
17
19
|
# end
|
18
20
|
#
|
19
|
-
# private # this is not redundant
|
21
|
+
# private # this is not redundant (a method is defined)
|
20
22
|
# def method2
|
21
23
|
# end
|
22
24
|
#
|
23
|
-
# private # this is redundant
|
25
|
+
# private # this is redundant (no following methods are defined)
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
#
|
30
|
+
# class Foo
|
31
|
+
# # The following is not redundant (conditionally defined methods are
|
32
|
+
# # considered as always defining a method)
|
33
|
+
# private
|
34
|
+
#
|
35
|
+
# if condition?
|
36
|
+
# def method
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# protected # this is not redundant (method is defined)
|
41
|
+
#
|
42
|
+
# define_method(:method2) do
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# protected # this is redundant (repeated from previous modifier)
|
46
|
+
#
|
47
|
+
# [1,2,3].each do |i|
|
48
|
+
# define_method("foo#{i}") do
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# # The following is redundant (methods defined on the class'
|
53
|
+
# # singleton class are not affected by the public modifier)
|
54
|
+
# public
|
55
|
+
#
|
56
|
+
# def self.method3
|
57
|
+
# end
|
24
58
|
# end
|
25
59
|
class UselessAccessModifier < Cop
|
26
60
|
MSG = 'Useless `%s` access modifier.'.freeze
|
27
61
|
|
28
|
-
def_node_matcher :access_modifier, <<-PATTERN
|
29
|
-
(send nil ${:public :protected :private})
|
30
|
-
PATTERN
|
31
|
-
|
32
|
-
def_node_matcher :method_definition?, <<-PATTERN
|
33
|
-
{def (send nil {:attr :attr_reader :attr_writer :attr_accessor} ...)}
|
34
|
-
PATTERN
|
35
|
-
|
36
62
|
def on_class(node)
|
37
63
|
check_node(node.children[2]) # class body
|
38
64
|
end
|
@@ -41,10 +67,37 @@ module RuboCop
|
|
41
67
|
check_node(node.children[1]) # module body
|
42
68
|
end
|
43
69
|
|
70
|
+
def on_block(node)
|
71
|
+
return unless class_or_instance_eval?(node)
|
72
|
+
|
73
|
+
check_node(node.children[2]) # block body
|
74
|
+
end
|
75
|
+
|
76
|
+
def on_sclass(node)
|
77
|
+
check_node(node.children[1]) # singleton class body
|
78
|
+
end
|
79
|
+
|
44
80
|
private
|
45
81
|
|
82
|
+
def_node_matcher :access_modifier, <<-PATTERN
|
83
|
+
(send nil ${:public :protected :private})
|
84
|
+
PATTERN
|
85
|
+
|
86
|
+
def_node_matcher :static_method_definition?, <<-PATTERN
|
87
|
+
{def (send nil {:attr :attr_reader :attr_writer :attr_accessor} ...)}
|
88
|
+
PATTERN
|
89
|
+
|
90
|
+
def_node_matcher :dynamic_method_definition?, <<-PATTERN
|
91
|
+
{(send nil :define_method ...) (block (send nil :define_method ...) ...)}
|
92
|
+
PATTERN
|
93
|
+
|
94
|
+
def_node_matcher :class_or_instance_eval?, <<-PATTERN
|
95
|
+
(block (send _ {:class_eval :instance_eval}) ...)
|
96
|
+
PATTERN
|
97
|
+
|
46
98
|
def check_node(node)
|
47
99
|
return if node.nil?
|
100
|
+
|
48
101
|
if node.begin_type?
|
49
102
|
check_scope(node)
|
50
103
|
elsif (vis = access_modifier(node))
|
@@ -52,9 +105,13 @@ module RuboCop
|
|
52
105
|
end
|
53
106
|
end
|
54
107
|
|
55
|
-
def check_scope(node
|
56
|
-
unused = nil
|
108
|
+
def check_scope(node)
|
109
|
+
cur_vis, unused = check_child_nodes(node, nil, :public)
|
110
|
+
|
111
|
+
add_offense(unused, :expression, format(MSG, cur_vis)) if unused
|
112
|
+
end
|
57
113
|
|
114
|
+
def check_child_nodes(node, unused, cur_vis)
|
58
115
|
node.child_nodes.each do |child|
|
59
116
|
if (new_vis = access_modifier(child))
|
60
117
|
# does this modifier just repeat the existing visibility?
|
@@ -70,15 +127,24 @@ module RuboCop
|
|
70
127
|
cur_vis = new_vis
|
71
128
|
elsif method_definition?(child)
|
72
129
|
unused = nil
|
73
|
-
elsif
|
74
|
-
|
130
|
+
elsif start_of_new_scope?(child)
|
131
|
+
check_scope(child)
|
132
|
+
elsif !child.defs_type?
|
133
|
+
cur_vis, unused = check_child_nodes(child, unused, cur_vis)
|
75
134
|
end
|
76
135
|
end
|
77
136
|
|
78
|
-
add_offense(unused, :expression, format(MSG, cur_vis)) if unused
|
79
|
-
|
80
137
|
[cur_vis, unused]
|
81
138
|
end
|
139
|
+
|
140
|
+
def method_definition?(child)
|
141
|
+
static_method_definition?(child) || dynamic_method_definition?(child)
|
142
|
+
end
|
143
|
+
|
144
|
+
def start_of_new_scope?(child)
|
145
|
+
child.module_type? || child.class_type? ||
|
146
|
+
child.sclass_type? || class_or_instance_eval?(child)
|
147
|
+
end
|
82
148
|
end
|
83
149
|
end
|
84
150
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Lint
|
7
|
+
# This cop checks for unncessary array splats.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad:
|
12
|
+
#
|
13
|
+
# a, b = *[1, 2, 3]
|
14
|
+
#
|
15
|
+
# # good:
|
16
|
+
#
|
17
|
+
# a, b = [1, 2, 3]
|
18
|
+
#
|
19
|
+
# # bad:
|
20
|
+
#
|
21
|
+
# a = *[1, 2, 3]
|
22
|
+
#
|
23
|
+
# # good:
|
24
|
+
#
|
25
|
+
# a = [1, 2, 3]
|
26
|
+
class UselessArraySplat < Cop
|
27
|
+
MSG = 'Unnecessary array splat.'.freeze
|
28
|
+
ARRAY_NEW_PATTERN = '(send (const nil :Array) :new ...)'.freeze
|
29
|
+
|
30
|
+
%w(m lv cv iv c gv).each do |var_type|
|
31
|
+
define_method("on_#{var_type}asgn") do |node|
|
32
|
+
*, rhs = *node
|
33
|
+
|
34
|
+
return unless rhs.is_a?(Node) && rhs.array_type?
|
35
|
+
|
36
|
+
add_offense(rhs, splat_source_range(rhs)) if array_splat?(rhs)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def_node_matcher :array_splat?, <<-PATTERN
|
43
|
+
(array (splat {(array ...) (block #{ARRAY_NEW_PATTERN} ...) #{ARRAY_NEW_PATTERN}} ...))
|
44
|
+
PATTERN
|
45
|
+
|
46
|
+
def splat_source_range(node)
|
47
|
+
node.loc.expression.begin.resize(1)
|
48
|
+
end
|
49
|
+
|
50
|
+
def autocorrect(node)
|
51
|
+
->(corrector) { corrector.remove(splat_source_range(node)) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
module RuboCop
|
5
5
|
module Cop
|
6
6
|
module Metrics
|
7
|
-
# This cop checks if the length a method exceeds some maximum value.
|
7
|
+
# This cop checks if the length of a method exceeds some maximum value.
|
8
8
|
# Comment lines can optionally be ignored.
|
9
9
|
# The maximum allowed length is configurable.
|
10
10
|
class MethodLength < Cop
|
@@ -22,25 +22,18 @@ module RuboCop
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def style_detected(detected)
|
25
|
-
# `detected` can be a single style, or an Array of possible styles
|
26
|
-
# (if there is more than one which matches the observed code)
|
27
|
-
|
28
25
|
return if no_acceptable_style?
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
detected = detected.to_s
|
34
|
-
end
|
27
|
+
# `detected` can be a single style, or an Array of possible styles
|
28
|
+
# (if there is more than one which matches the observed code)
|
29
|
+
detected_as_strings = Array(detected).map(&:to_s)
|
35
30
|
|
36
31
|
if !detected_style # we haven't observed any specific style yet
|
37
|
-
self.detected_style =
|
32
|
+
self.detected_style = detected_as_strings
|
38
33
|
elsif detected_style.is_a?(Array)
|
39
|
-
self.detected_style &=
|
40
|
-
elsif detected.
|
41
|
-
no_acceptable_style!
|
42
|
-
else
|
43
|
-
no_acceptable_style! unless detected_style == detected
|
34
|
+
self.detected_style &= detected_as_strings
|
35
|
+
elsif !detected.include?(detected_style)
|
36
|
+
no_acceptable_style!
|
44
37
|
end
|
45
38
|
end
|
46
39
|
|
@@ -60,17 +53,10 @@ module RuboCop
|
|
60
53
|
def detected_style=(style)
|
61
54
|
Formatter::DisabledConfigFormatter.detected_styles[cop_name] = style
|
62
55
|
|
63
|
-
if style.nil?
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
no_acceptable_style!
|
68
|
-
else
|
69
|
-
config_to_allow_offenses[parameter_name] = style[0]
|
70
|
-
end
|
71
|
-
else
|
72
|
-
config_to_allow_offenses[parameter_name] = style
|
73
|
-
end
|
56
|
+
return no_acceptable_style! if style.nil?
|
57
|
+
return no_acceptable_style! if style.empty?
|
58
|
+
|
59
|
+
config_to_allow_offenses[parameter_name] = style.first
|
74
60
|
end
|
75
61
|
|
76
62
|
alias conflicting_styles_detected no_acceptable_style!
|