rubocop 0.24.1 → 0.25.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/.rubocop_todo.yml +12 -8
- data/.travis.yml +1 -1
- data/CHANGELOG.md +42 -0
- data/Gemfile +2 -0
- data/README.md +27 -6
- data/bin/rubocop +10 -15
- data/config/default.yml +72 -25
- data/config/enabled.yml +57 -25
- data/lib/rubocop.rb +15 -8
- data/lib/rubocop/config_loader.rb +11 -7
- data/lib/rubocop/cop/cop.rb +16 -16
- data/lib/rubocop/cop/ignored_node.rb +11 -4
- data/lib/rubocop/cop/lint/block_alignment.rb +29 -4
- data/lib/rubocop/cop/lint/debugger.rb +8 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +5 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +5 -5
- data/lib/rubocop/cop/lint/end_in_method.rb +2 -2
- data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -2
- data/lib/rubocop/cop/{style → metrics}/block_nesting.rb +1 -1
- data/lib/rubocop/cop/{style → metrics}/class_length.rb +4 -4
- data/lib/rubocop/cop/{style → metrics}/cyclomatic_complexity.rb +5 -16
- data/lib/rubocop/cop/{style → metrics}/line_length.rb +1 -1
- data/lib/rubocop/cop/{style → metrics}/method_length.rb +8 -4
- data/lib/rubocop/cop/{style → metrics}/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +61 -0
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +10 -2
- data/lib/rubocop/cop/mixin/code_length.rb +2 -3
- data/lib/rubocop/cop/mixin/configurable_naming.rb +6 -20
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/if_node.rb +1 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +32 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -1
- data/lib/rubocop/cop/mixin/{check_methods.rb → on_method.rb} +3 -3
- data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +24 -0
- data/lib/rubocop/cop/mixin/percent_literal.rb +2 -1
- data/lib/rubocop/cop/mixin/space_inside.rb +33 -4
- data/lib/rubocop/cop/mixin/statement_modifier.rb +14 -14
- data/lib/rubocop/cop/mixin/string_help.rb +4 -0
- data/lib/rubocop/cop/mixin/surrounding_space.rb +1 -0
- data/lib/rubocop/cop/rails/delegate.rb +2 -2
- data/lib/rubocop/cop/rails/output.rb +4 -2
- data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
- data/lib/rubocop/cop/style/align_hash.rb +9 -1
- data/lib/rubocop/cop/style/and_or.rb +37 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +46 -0
- data/lib/rubocop/cop/style/block_end_newline.rb +56 -0
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/def_with_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +31 -3
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +6 -2
- data/lib/rubocop/cop/style/end_of_line.rb +3 -14
- data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -6
- data/lib/rubocop/cop/style/if_with_semicolon.rb +6 -7
- data/lib/rubocop/cop/style/indentation_width.rb +3 -8
- data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/method_name.rb +4 -18
- data/lib/rubocop/cop/style/multiline_block_layout.rb +73 -0
- data/lib/rubocop/cop/style/multiline_if_then.rb +4 -4
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_while.rb +2 -2
- data/lib/rubocop/cop/style/next.rb +12 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +6 -6
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +22 -8
- data/lib/rubocop/cop/style/percent_q_literals.rb +53 -0
- data/lib/rubocop/cop/style/predicate_name.rb +2 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -2
- data/lib/rubocop/cop/style/redundant_return.rb +2 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +7 -3
- data/lib/rubocop/cop/style/single_line_methods.rb +2 -2
- data/lib/rubocop/cop/style/space_after_method_name.rb +2 -2
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +14 -10
- data/lib/rubocop/cop/style/space_inside_brackets.rb +5 -1
- data/lib/rubocop/cop/style/string_literals.rb +5 -8
- data/lib/rubocop/cop/style/trailing_comma.rb +15 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +2 -2
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +2 -4
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +13 -0
- data/lib/rubocop/cop/style/variable_interpolation.rb +14 -2
- data/lib/rubocop/cop/style/variable_name.rb +17 -17
- data/lib/rubocop/cop/style/while_until_modifier.rb +2 -5
- data/lib/rubocop/cop/util.rb +5 -0
- data/lib/rubocop/cop/variable_force.rb +7 -6
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/processed_source.rb +5 -22
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.25.0.md +91 -0
- data/rubocop.gemspec +2 -3
- data/spec/project_spec.rb +1 -1
- data/spec/rubocop/cli_spec.rb +70 -44
- data/spec/rubocop/comment_config_spec.rb +6 -6
- data/spec/rubocop/config_loader_spec.rb +19 -13
- data/spec/rubocop/config_spec.rb +3 -3
- data/spec/rubocop/cop/commissioner_spec.rb +1 -1
- data/spec/rubocop/cop/cop_spec.rb +3 -3
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +113 -6
- data/spec/rubocop/cop/lint/debugger_spec.rb +10 -6
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +12 -0
- data/spec/rubocop/cop/{style → metrics}/block_nesting_spec.rb +1 -1
- data/spec/rubocop/cop/{style → metrics}/class_length_spec.rb +1 -1
- data/spec/rubocop/cop/{style → metrics}/cyclomatic_complexity_spec.rb +1 -1
- data/spec/rubocop/cop/{style → metrics}/if_unless_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/{style → metrics}/line_length_spec.rb +7 -7
- data/spec/rubocop/cop/{style → metrics}/method_length_spec.rb +1 -1
- data/spec/rubocop/cop/{style → metrics}/parameter_lists_spec.rb +1 -1
- data/spec/rubocop/cop/metrics/perceived_complexity_spec.rb +222 -0
- data/spec/rubocop/cop/{style → metrics}/while_until_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/rails/output_spec.rb +8 -2
- data/spec/rubocop/cop/style/align_hash_spec.rb +7 -0
- data/spec/rubocop/cop/style/and_or_spec.rb +245 -43
- data/spec/rubocop/cop/style/bare_percent_literals_spec.rb +132 -0
- data/spec/rubocop/cop/style/block_end_newline_spec.rb +61 -0
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +34 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +8 -0
- data/spec/rubocop/cop/style/guard_clause_spec.rb +1 -1
- data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +138 -0
- data/spec/rubocop/cop/style/next_spec.rb +32 -3
- data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +34 -0
- data/spec/rubocop/cop/style/percent_q_literals_spec.rb +122 -0
- data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +20 -0
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +26 -2
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +112 -0
- data/spec/rubocop/cop/style/unneeded_percent_q_spec.rb +86 -31
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +21 -1
- data/spec/rubocop/cop/team_spec.rb +14 -9
- data/spec/spec_helper.rb +1 -0
- metadata +47 -50
- data/lib/rubocop/cop/mixin/if_then_else.rb +0 -23
data/lib/rubocop.rb
CHANGED
@@ -41,15 +41,16 @@ require 'rubocop/cop/mixin/array_syntax'
|
|
41
41
|
require 'rubocop/cop/mixin/autocorrect_alignment'
|
42
42
|
require 'rubocop/cop/mixin/autocorrect_unless_changing_ast'
|
43
43
|
require 'rubocop/cop/mixin/check_assignment'
|
44
|
-
require 'rubocop/cop/mixin/check_methods'
|
45
44
|
require 'rubocop/cop/mixin/configurable_max'
|
46
45
|
require 'rubocop/cop/mixin/code_length'
|
47
46
|
require 'rubocop/cop/mixin/configurable_enforced_style'
|
48
47
|
require 'rubocop/cop/mixin/configurable_naming'
|
49
48
|
require 'rubocop/cop/mixin/end_keyword_alignment'
|
50
49
|
require 'rubocop/cop/mixin/if_node'
|
51
|
-
require 'rubocop/cop/mixin/if_then_else'
|
52
50
|
require 'rubocop/cop/mixin/negative_conditional'
|
51
|
+
require 'rubocop/cop/mixin/on_method'
|
52
|
+
require 'rubocop/cop/mixin/method_complexity'
|
53
|
+
require 'rubocop/cop/mixin/on_normal_if_unless'
|
53
54
|
require 'rubocop/cop/mixin/parser_diagnostic'
|
54
55
|
require 'rubocop/cop/mixin/percent_literal'
|
55
56
|
require 'rubocop/cop/mixin/safe_assignment'
|
@@ -99,6 +100,14 @@ require 'rubocop/cop/lint/useless_else_without_rescue'
|
|
99
100
|
require 'rubocop/cop/lint/useless_setter_call'
|
100
101
|
require 'rubocop/cop/lint/void'
|
101
102
|
|
103
|
+
require 'rubocop/cop/metrics/block_nesting'
|
104
|
+
require 'rubocop/cop/metrics/class_length'
|
105
|
+
require 'rubocop/cop/metrics/cyclomatic_complexity'
|
106
|
+
require 'rubocop/cop/metrics/line_length'
|
107
|
+
require 'rubocop/cop/metrics/method_length'
|
108
|
+
require 'rubocop/cop/metrics/parameter_lists'
|
109
|
+
require 'rubocop/cop/metrics/perceived_complexity'
|
110
|
+
|
102
111
|
require 'rubocop/cop/style/access_modifier_indentation'
|
103
112
|
require 'rubocop/cop/style/accessor_method_name'
|
104
113
|
require 'rubocop/cop/style/alias'
|
@@ -110,9 +119,10 @@ require 'rubocop/cop/style/array_join'
|
|
110
119
|
require 'rubocop/cop/style/ascii_comments'
|
111
120
|
require 'rubocop/cop/style/ascii_identifiers'
|
112
121
|
require 'rubocop/cop/style/attr'
|
122
|
+
require 'rubocop/cop/style/bare_percent_literals'
|
113
123
|
require 'rubocop/cop/style/begin_block'
|
114
124
|
require 'rubocop/cop/style/block_comments'
|
115
|
-
require 'rubocop/cop/style/
|
125
|
+
require 'rubocop/cop/style/block_end_newline'
|
116
126
|
require 'rubocop/cop/style/blocks'
|
117
127
|
require 'rubocop/cop/style/braces_around_hash_parameters'
|
118
128
|
require 'rubocop/cop/style/case_equality'
|
@@ -121,7 +131,6 @@ require 'rubocop/cop/style/character_literal'
|
|
121
131
|
require 'rubocop/cop/style/class_and_module_camel_case'
|
122
132
|
require 'rubocop/cop/style/class_and_module_children'
|
123
133
|
require 'rubocop/cop/style/class_check'
|
124
|
-
require 'rubocop/cop/style/class_length'
|
125
134
|
require 'rubocop/cop/style/class_methods'
|
126
135
|
require 'rubocop/cop/style/class_vars'
|
127
136
|
require 'rubocop/cop/style/collection_methods'
|
@@ -129,7 +138,6 @@ require 'rubocop/cop/style/colon_method_call'
|
|
129
138
|
require 'rubocop/cop/style/comment_annotation'
|
130
139
|
require 'rubocop/cop/style/comment_indentation'
|
131
140
|
require 'rubocop/cop/style/constant_name'
|
132
|
-
require 'rubocop/cop/style/cyclomatic_complexity'
|
133
141
|
require 'rubocop/cop/style/def_with_parentheses'
|
134
142
|
require 'rubocop/cop/style/deprecated_hash_methods'
|
135
143
|
require 'rubocop/cop/style/documentation'
|
@@ -163,14 +171,13 @@ require 'rubocop/cop/style/lambda'
|
|
163
171
|
require 'rubocop/cop/style/lambda_call'
|
164
172
|
require 'rubocop/cop/style/leading_comment_space'
|
165
173
|
require 'rubocop/cop/style/line_end_concatenation'
|
166
|
-
require 'rubocop/cop/style/line_length'
|
167
174
|
require 'rubocop/cop/style/method_call_parentheses'
|
168
175
|
require 'rubocop/cop/style/method_called_on_do_end_block'
|
169
176
|
require 'rubocop/cop/style/method_def_parentheses'
|
170
|
-
require 'rubocop/cop/style/method_length'
|
171
177
|
require 'rubocop/cop/style/method_name'
|
172
178
|
require 'rubocop/cop/style/module_function'
|
173
179
|
require 'rubocop/cop/style/multiline_block_chain'
|
180
|
+
require 'rubocop/cop/style/multiline_block_layout'
|
174
181
|
require 'rubocop/cop/style/multiline_if_then'
|
175
182
|
require 'rubocop/cop/style/multiline_ternary_operator'
|
176
183
|
require 'rubocop/cop/style/negated_if'
|
@@ -183,9 +190,9 @@ require 'rubocop/cop/style/not'
|
|
183
190
|
require 'rubocop/cop/style/numeric_literals'
|
184
191
|
require 'rubocop/cop/style/one_line_conditional'
|
185
192
|
require 'rubocop/cop/style/op_method'
|
186
|
-
require 'rubocop/cop/style/parameter_lists'
|
187
193
|
require 'rubocop/cop/style/parentheses_around_condition'
|
188
194
|
require 'rubocop/cop/style/percent_literal_delimiters'
|
195
|
+
require 'rubocop/cop/style/percent_q_literals'
|
189
196
|
require 'rubocop/cop/style/perl_backrefs'
|
190
197
|
require 'rubocop/cop/style/predicate_name'
|
191
198
|
require 'rubocop/cop/style/proc'
|
@@ -3,13 +3,6 @@
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
# Psych can give an error when reading an empty file, so we use syck in Ruby
|
7
|
-
# versions where it's available. Also, the problem with empty files does not
|
8
|
-
# appear in Ruby 2 or in JRuby 1.9 mode.
|
9
|
-
if RUBY_VERSION < '2.0.0' && RUBY_PLATFORM != 'java'
|
10
|
-
YAML::ENGINE.yamler = 'syck'
|
11
|
-
end
|
12
|
-
|
13
6
|
module RuboCop
|
14
7
|
# This class represents the configuration of the RuboCop application
|
15
8
|
# and all its cops. A Config is associated with a YAML configuration
|
@@ -31,7 +24,18 @@ module RuboCop
|
|
31
24
|
|
32
25
|
def load_file(path)
|
33
26
|
path = File.absolute_path(path)
|
27
|
+
|
28
|
+
# Psych can give an error when reading an empty file, so we use syck in
|
29
|
+
# Ruby versions where it's available. Also, the problem with empty
|
30
|
+
# files does not appear in Ruby 2 or in JRuby 1.9 mode.
|
31
|
+
if RUBY_VERSION < '2.0.0' && RUBY_PLATFORM != 'java'
|
32
|
+
original_yamler = YAML::ENGINE.yamler
|
33
|
+
YAML::ENGINE.yamler = 'syck'
|
34
|
+
end
|
34
35
|
hash = YAML.load_file(path) || {}
|
36
|
+
# Restore yamler for applications using RuboCop as a library.
|
37
|
+
YAML::ENGINE.yamler = original_yamler if original_yamler
|
38
|
+
|
35
39
|
puts "configuration from #{path}" if debug?
|
36
40
|
|
37
41
|
resolve_inheritance(path, hash)
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -58,15 +58,23 @@ module RuboCop
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.qualified_cop_name(name, origin)
|
61
|
-
|
61
|
+
@cop_names ||= Set.new(@all.map(&:cop_name))
|
62
|
+
basename = File.basename(name)
|
62
63
|
found_ns = @all.types.map(&:capitalize).select do |ns|
|
63
|
-
@
|
64
|
+
@cop_names.include?("#{ns}/#{basename}")
|
64
65
|
end
|
65
66
|
|
66
67
|
case found_ns.size
|
67
|
-
when 0
|
68
|
-
|
69
|
-
|
68
|
+
when 0
|
69
|
+
name # No namespace found. Deal with it later in caller.
|
70
|
+
when 1
|
71
|
+
if name != basename && found_ns.first != File.dirname(name).to_sym
|
72
|
+
warn "#{origin}: #{name} has the wrong namespace - " \
|
73
|
+
"should be #{found_ns.first}"
|
74
|
+
end
|
75
|
+
"#{found_ns.first}/#{basename}"
|
76
|
+
else
|
77
|
+
fail AmbiguousCopName, "`#{basename}` used in #{origin}"
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
@@ -168,16 +176,9 @@ module RuboCop
|
|
168
176
|
|
169
177
|
alias_method :name, :cop_name
|
170
178
|
|
171
|
-
def include_file?(file)
|
172
|
-
file_name_matches_any?(file, 'Include', true)
|
173
|
-
end
|
174
|
-
|
175
|
-
def exclude_file?(file)
|
176
|
-
file_name_matches_any?(file, 'Exclude', false)
|
177
|
-
end
|
178
|
-
|
179
179
|
def relevant_file?(file)
|
180
|
-
|
180
|
+
file_name_matches_any?(file, 'Include', true) &&
|
181
|
+
!file_name_matches_any?(file, 'Exclude', false)
|
181
182
|
end
|
182
183
|
|
183
184
|
private
|
@@ -193,8 +194,7 @@ module RuboCop
|
|
193
194
|
|
194
195
|
def enabled_line?(line_number)
|
195
196
|
return true unless @processed_source
|
196
|
-
@processed_source.comment_config
|
197
|
-
.cop_enabled_at_line?(self, line_number)
|
197
|
+
@processed_source.comment_config.cop_enabled_at_line?(self, line_number)
|
198
198
|
end
|
199
199
|
|
200
200
|
def default_severity
|
@@ -9,10 +9,17 @@ module RuboCop
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def part_of_ignored_node?(node)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
ignored_nodes.map(&:loc).any? do |ignored_loc|
|
13
|
+
if ignored_loc.expression.begin_pos > node.loc.expression.begin_pos
|
14
|
+
next false
|
15
|
+
end
|
16
|
+
|
17
|
+
ignored_end_pos = if ignored_loc.respond_to?(:heredoc_body)
|
18
|
+
ignored_loc.heredoc_end.end_pos
|
19
|
+
else
|
20
|
+
ignored_loc.expression.end_pos
|
21
|
+
end
|
22
|
+
ignored_end_pos >= node.loc.expression.end_pos
|
16
23
|
end
|
17
24
|
end
|
18
25
|
|
@@ -102,12 +102,14 @@ module RuboCop
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def check_block_alignment(start_node, block_node)
|
105
|
-
start_loc = start_node.loc.expression
|
106
105
|
end_loc = block_node.loc.end
|
107
|
-
|
108
|
-
|
106
|
+
return unless begins_its_line?(end_loc)
|
107
|
+
|
108
|
+
start_loc = start_node.loc.expression
|
109
109
|
return unless start_loc.column != end_loc.column
|
110
110
|
|
111
|
+
do_loc = block_node.loc.begin # Actually it's either do or {.
|
112
|
+
|
111
113
|
# We've found that "end" is not aligned with the start node (which
|
112
114
|
# can be a block, a variable assignment, etc). But we also allow
|
113
115
|
# the "end" to be aligned with the start of the line where the "do"
|
@@ -117,7 +119,7 @@ module RuboCop
|
|
117
119
|
indentation_of_do_line = match.begin(0)
|
118
120
|
return unless end_loc.column != indentation_of_do_line
|
119
121
|
|
120
|
-
add_offense(
|
122
|
+
add_offense(block_node,
|
121
123
|
end_loc,
|
122
124
|
format(MSG, end_loc.line, end_loc.column,
|
123
125
|
start_loc.source.lines.to_a.first.chomp,
|
@@ -145,6 +147,29 @@ module RuboCop
|
|
145
147
|
def block_is_on_next_line?(begin_node, block_node)
|
146
148
|
begin_node.loc.line != block_node.loc.line
|
147
149
|
end
|
150
|
+
|
151
|
+
def autocorrect(node)
|
152
|
+
key = node.children.first
|
153
|
+
source = node.loc.expression.source_buffer
|
154
|
+
|
155
|
+
@corrections << lambda do |corrector|
|
156
|
+
start_col = key.loc.expression.column
|
157
|
+
starting_position_of_block_end = node.loc.end.begin_pos
|
158
|
+
end_col = node.loc.end.column
|
159
|
+
|
160
|
+
if end_col < start_col
|
161
|
+
delta = start_col - end_col
|
162
|
+
corrector.insert_before(node.loc.end, ' ' * delta)
|
163
|
+
elsif end_col > start_col
|
164
|
+
delta = start_col - end_col
|
165
|
+
range_start = starting_position_of_block_end + delta
|
166
|
+
range_end = range_start - delta
|
167
|
+
|
168
|
+
range = Parser::Source::Range.new(source, range_start, range_end)
|
169
|
+
corrector.remove(range)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
148
173
|
end
|
149
174
|
end
|
150
175
|
end
|
@@ -29,11 +29,18 @@ module RuboCop
|
|
29
29
|
# (send nil :binding) :remote_pry)
|
30
30
|
REMOTE_PRY_NODE = s(:send, s(:send, nil, :binding), :remote_pry)
|
31
31
|
|
32
|
+
# binding.pry_remote node
|
33
|
+
#
|
34
|
+
# (send
|
35
|
+
# (send nil :binding) :pry_remote)
|
36
|
+
PRY_REMOTE_NODE = s(:send, s(:send, nil, :binding), :pry_remote)
|
37
|
+
|
32
38
|
DEBUGGER_NODES = [
|
33
39
|
DEBUGGER_NODE,
|
34
40
|
BYEBUG_NODE,
|
35
41
|
PRY_NODE,
|
36
|
-
REMOTE_PRY_NODE
|
42
|
+
REMOTE_PRY_NODE,
|
43
|
+
PRY_REMOTE_NODE
|
37
44
|
]
|
38
45
|
|
39
46
|
def on_send(node)
|
@@ -17,11 +17,15 @@ module RuboCop
|
|
17
17
|
# private def foo
|
18
18
|
# end
|
19
19
|
class DefEndAlignment < Cop
|
20
|
-
include
|
20
|
+
include OnMethod
|
21
21
|
include EndKeywordAlignment
|
22
22
|
|
23
23
|
MSG = '`end` at %d, %d is not aligned with `%s` at %d, %d'
|
24
24
|
|
25
|
+
def on_method(node, _method_name, _args, _body)
|
26
|
+
check_offset_of_node(node)
|
27
|
+
end
|
28
|
+
|
25
29
|
def on_send(node)
|
26
30
|
receiver, method_name, *args = *node
|
27
31
|
return unless visibility_and_def_on_same_line?(receiver, method_name,
|
@@ -23,23 +23,23 @@ module RuboCop
|
|
23
23
|
MSG = '`end` at %d, %d is not aligned with `%s` at %d, %d'
|
24
24
|
|
25
25
|
def on_class(node)
|
26
|
-
|
26
|
+
check_offset_of_node(node)
|
27
27
|
end
|
28
28
|
|
29
29
|
def on_module(node)
|
30
|
-
|
30
|
+
check_offset_of_node(node)
|
31
31
|
end
|
32
32
|
|
33
33
|
def on_if(node)
|
34
|
-
|
34
|
+
check_offset_of_node(node) unless ternary_op?(node)
|
35
35
|
end
|
36
36
|
|
37
37
|
def on_while(node)
|
38
|
-
|
38
|
+
check_offset_of_node(node)
|
39
39
|
end
|
40
40
|
|
41
41
|
def on_until(node)
|
42
|
-
|
42
|
+
check_offset_of_node(node)
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
@@ -5,13 +5,13 @@ module RuboCop
|
|
5
5
|
module Lint
|
6
6
|
# This cop checks for END blocks in method definitions.
|
7
7
|
class EndInMethod < Cop
|
8
|
-
include
|
8
|
+
include OnMethod
|
9
9
|
|
10
10
|
MSG = '`END` found in method definition. Use `at_exit` instead.'
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
def
|
14
|
+
def on_method(node, _method_name, _args, _body)
|
15
15
|
on_node(:postexe, node) do |end_node|
|
16
16
|
add_offense(end_node, :keyword)
|
17
17
|
end
|
@@ -13,7 +13,7 @@ module RuboCop
|
|
13
13
|
# x.attr = 5
|
14
14
|
# end
|
15
15
|
class UselessSetterCall < Cop
|
16
|
-
include
|
16
|
+
include OnMethod
|
17
17
|
|
18
18
|
MSG = 'Useless setter call to local variable `%s`.'
|
19
19
|
ASSIGNMENT_TYPES = [:lvasgn, :ivasgn, :cvasgn, :gvasgn].freeze
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def
|
30
|
+
def on_method(_node, _method_name, _args, body)
|
31
31
|
return unless body
|
32
32
|
|
33
33
|
if body.type == :begin
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
module
|
5
|
+
module Metrics
|
6
6
|
# This cop checks if the length a class exceeds some maximum value.
|
7
7
|
# Comment lines can optionally be ignored.
|
8
8
|
# The maximum allowed length is configurable.
|
@@ -10,13 +10,13 @@ module RuboCop
|
|
10
10
|
include CodeLength
|
11
11
|
|
12
12
|
def on_class(node)
|
13
|
-
|
13
|
+
check_code_length(node)
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def message
|
19
|
-
'Class definition is too long. [%d/%d]'
|
18
|
+
def message(length, max_length)
|
19
|
+
format('Class definition is too long. [%d/%d]', length, max_length)
|
20
20
|
end
|
21
21
|
|
22
22
|
def code_length(node)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
module
|
5
|
+
module Metrics
|
6
6
|
# This cop checks that the cyclomatic complexity of methods is not higher
|
7
7
|
# than the configured maximum. The cyclomatic complexity is the number of
|
8
8
|
# linearly independent paths through a method. The algorithm counts
|
@@ -14,26 +14,15 @@ module RuboCop
|
|
14
14
|
# and ||/or is shorthand for a sequence of ifs, so they also add one.
|
15
15
|
# Loops can be said to have an exit condition, so they add one.
|
16
16
|
class CyclomaticComplexity < Cop
|
17
|
-
include
|
18
|
-
include ConfigurableMax
|
17
|
+
include MethodComplexity
|
19
18
|
|
20
19
|
MSG = 'Cyclomatic complexity for %s is too high. [%d/%d]'
|
21
|
-
|
22
|
-
:and, :or]
|
20
|
+
COUNTED_NODES = [:if, :while, :until, :for, :rescue, :when, :and, :or]
|
23
21
|
|
24
22
|
private
|
25
23
|
|
26
|
-
def
|
27
|
-
|
28
|
-
on_node(DECISION_POINT_NODES, node) { complexity += 1 }
|
29
|
-
|
30
|
-
max = cop_config['Max']
|
31
|
-
return unless complexity > max
|
32
|
-
|
33
|
-
add_offense(node, :keyword,
|
34
|
-
format(MSG, method_name, complexity, max)) do
|
35
|
-
self.max = complexity
|
36
|
-
end
|
24
|
+
def complexity_score_for(_node)
|
25
|
+
1
|
37
26
|
end
|
38
27
|
end
|
39
28
|
end
|
@@ -2,18 +2,22 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
module
|
5
|
+
module Metrics
|
6
6
|
# This cop checks if the length a method exceeds some maximum value.
|
7
7
|
# Comment lines can optionally be ignored.
|
8
8
|
# The maximum allowed length is configurable.
|
9
9
|
class MethodLength < Cop
|
10
|
-
include
|
10
|
+
include OnMethod
|
11
11
|
include CodeLength
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def on_method(node, _method_name, _args, _body)
|
16
|
+
check_code_length(node)
|
17
|
+
end
|
18
|
+
|
19
|
+
def message(length, max_length)
|
20
|
+
format('Method has too many lines. [%d/%d]', length, max_length)
|
17
21
|
end
|
18
22
|
|
19
23
|
def code_length(node)
|