rubocop 0.30.1 → 0.31.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/CHANGELOG.md +38 -0
- data/README.md +10 -0
- data/config/default.yml +8 -1
- data/config/enabled.yml +28 -0
- data/lib/rubocop.rb +7 -0
- data/lib/rubocop/cli.rb +3 -2
- data/lib/rubocop/config.rb +12 -18
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/cop.rb +35 -23
- data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +6 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +29 -0
- data/lib/rubocop/cop/lint/end_alignment.rb +5 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -25
- data/lib/rubocop/cop/metrics/module_length.rb +24 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +2 -2
- data/lib/rubocop/cop/mixin/classish_length.rb +37 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +14 -1
- data/lib/rubocop/cop/mixin/min_body_length.rb +19 -0
- data/lib/rubocop/cop/mixin/on_method_def.rb +1 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -4
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/space_inside.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +14 -7
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/unused_argument.rb +1 -3
- data/lib/rubocop/cop/performance/count.rb +84 -0
- data/lib/rubocop/cop/performance/detect.rb +1 -1
- data/lib/rubocop/cop/performance/flat_map.rb +2 -1
- data/lib/rubocop/cop/performance/parallel_assignment.rb +79 -0
- data/lib/rubocop/cop/performance/reverse_each.rb +1 -3
- data/lib/rubocop/cop/performance/sample.rb +25 -18
- data/lib/rubocop/cop/performance/size.rb +1 -3
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/delegate.rb +2 -5
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/find_each.rb +1 -3
- data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -3
- data/lib/rubocop/cop/rails/time_zone.rb +29 -7
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/align_hash.rb +11 -14
- data/lib/rubocop/cop/style/array_join.rb +11 -0
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -9
- data/lib/rubocop/cop/style/block_end_newline.rb +1 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/class_check.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +1 -3
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -3
- data/lib/rubocop/cop/style/command_literal.rb +2 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +9 -2
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/deprecated_hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +1 -1
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -3
- data/lib/rubocop/cop/style/empty_lines.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +2 -6
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +2 -4
- data/lib/rubocop/cop/style/extra_spacing.rb +1 -3
- data/lib/rubocop/cop/style/guard_clause.rb +1 -11
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -6
- data/lib/rubocop/cop/style/indentation_width.rb +11 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +8 -8
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -3
- data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -7
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -8
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
- data/lib/rubocop/cop/style/multiline_block_layout.rb +11 -8
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +3 -2
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -1
- 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 +1 -11
- data/lib/rubocop/cop/style/nil_comparison.rb +3 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
- data/lib/rubocop/cop/style/not.rb +3 -5
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -5
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -3
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +6 -8
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +2 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +2 -2
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +2 -2
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/single_space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/style/space_after_colon.rb +1 -3
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -3
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -3
- data/lib/rubocop/cop/style/space_after_not.rb +1 -1
- data/lib/rubocop/cop/style/space_around_block_parameters.rb +34 -16
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -3
- data/lib/rubocop/cop/style/space_around_operators.rb +3 -2
- data/lib/rubocop/cop/style/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/style/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -3
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +5 -3
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/style/space_inside_range_literal.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/tab.rb +1 -1
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +72 -0
- data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -10
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +2 -4
- data/lib/rubocop/cop/style/when_then.rb +1 -3
- data/lib/rubocop/cop/style/while_until_do.rb +5 -7
- data/lib/rubocop/cop/style/while_until_modifier.rb +4 -6
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/util.rb +6 -3
- data/lib/rubocop/formatter/progress_formatter.rb +3 -2
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/rake_task.rb +2 -2
- data/lib/rubocop/runner.rb +2 -11
- data/lib/rubocop/string_util.rb +4 -2
- data/lib/rubocop/token.rb +3 -1
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.31.0.md +120 -0
- metadata +10 -2
@@ -62,9 +62,7 @@ module RuboCop
|
|
62
62
|
m = range.source.match(/=\s*(\S+)/)
|
63
63
|
rest = m ? m.captures[0] : ''
|
64
64
|
replacement = style == :space ? ' = ' : '='
|
65
|
-
|
66
|
-
corrector.replace(range, replacement + rest)
|
67
|
-
end
|
65
|
+
->(corrector) { corrector.replace(range, replacement + rest) }
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
@@ -41,7 +41,8 @@ module RuboCop
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def unary_operation?(node)
|
44
|
-
whole
|
44
|
+
whole = node.loc.expression
|
45
|
+
selector = node.loc.selector
|
45
46
|
return unless selector
|
46
47
|
operator?(selector) && whole.begin_pos == selector.begin_pos
|
47
48
|
end
|
@@ -79,7 +80,7 @@ module RuboCop
|
|
79
80
|
end
|
80
81
|
|
81
82
|
def autocorrect(range)
|
82
|
-
|
83
|
+
lambda do |corrector|
|
83
84
|
case range.source
|
84
85
|
when /\*\*/
|
85
86
|
corrector.replace(range, '**')
|
@@ -23,7 +23,8 @@ module RuboCop
|
|
23
23
|
return
|
24
24
|
end
|
25
25
|
|
26
|
-
left_brace
|
26
|
+
left_brace = node.loc.begin
|
27
|
+
right_brace = node.loc.end
|
27
28
|
|
28
29
|
check_inside(node, left_brace, right_brace)
|
29
30
|
end
|
@@ -58,7 +59,8 @@ module RuboCop
|
|
58
59
|
|
59
60
|
def braces_with_contents_inside(node, inner, sb)
|
60
61
|
_method, args, _body = *node
|
61
|
-
left_brace
|
62
|
+
left_brace = node.loc.begin
|
63
|
+
right_brace = node.loc.end
|
62
64
|
args_delimiter = args.loc.begin # Can be ( | or nil.
|
63
65
|
|
64
66
|
if inner =~ /^\S/
|
@@ -148,7 +150,7 @@ module RuboCop
|
|
148
150
|
end
|
149
151
|
|
150
152
|
def autocorrect(range)
|
151
|
-
|
153
|
+
lambda do |corrector|
|
152
154
|
case range.source
|
153
155
|
when /\s/ then corrector.remove(range)
|
154
156
|
when '{}' then corrector.replace(range, '{ }')
|
@@ -68,7 +68,7 @@ module RuboCop
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def autocorrect(range)
|
71
|
-
|
71
|
+
lambda do |corrector|
|
72
72
|
# It is possible that BracesAroundHashParameters will remove the
|
73
73
|
# braces while this cop inserts spaces. This can lead to unwanted
|
74
74
|
# changes to the inspected code. If we replace the brace with a
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
return false if processed_source.tokens.empty?
|
44
44
|
|
45
45
|
extra = sb.source[processed_source.tokens.last.pos.end_pos..-1]
|
46
|
-
extra.strip.start_with?('__END__')
|
46
|
+
extra && extra.strip.start_with?('__END__')
|
47
47
|
end
|
48
48
|
|
49
49
|
def message(wanted_blank_lines, blank_lines)
|
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def autocorrect(range)
|
67
|
-
|
67
|
+
lambda do |corrector|
|
68
68
|
corrector.replace(range, style == :final_newline ? "\n" : "\n\n")
|
69
69
|
end
|
70
70
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks for extra underscores in variable assignment.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# a, b, _ = foo()
|
11
|
+
# a, b, _, = foo()
|
12
|
+
# a, _, _ = foo()
|
13
|
+
# a, _, _, = foo()
|
14
|
+
#
|
15
|
+
# #good
|
16
|
+
# a, b, = foo()
|
17
|
+
# a, = foo()
|
18
|
+
class TrailingUnderscoreVariable < Cop
|
19
|
+
include SurroundingSpace
|
20
|
+
|
21
|
+
MSG = 'Do not use trailing `_`s in parallel assignment.'
|
22
|
+
|
23
|
+
def on_masgn(node)
|
24
|
+
left, = *node
|
25
|
+
variables = *left
|
26
|
+
first_offense = find_first_offense(variables)
|
27
|
+
|
28
|
+
return if first_offense.nil?
|
29
|
+
|
30
|
+
range =
|
31
|
+
Parser::Source::Range.new(node.loc.expression.source_buffer,
|
32
|
+
first_offense.loc.expression.begin_pos,
|
33
|
+
variables.last.loc.expression.end_pos)
|
34
|
+
add_offense(node, range)
|
35
|
+
end
|
36
|
+
|
37
|
+
def autocorrect(node)
|
38
|
+
left, right = *node
|
39
|
+
variables = *left
|
40
|
+
first_offense = find_first_offense(variables)
|
41
|
+
|
42
|
+
end_position =
|
43
|
+
if first_offense.loc.expression == variables.first.loc.expression
|
44
|
+
right.loc.expression.begin_pos
|
45
|
+
else
|
46
|
+
node.loc.operator.begin_pos
|
47
|
+
end
|
48
|
+
|
49
|
+
range =
|
50
|
+
Parser::Source::Range.new(node.loc.expression.source_buffer,
|
51
|
+
first_offense.loc.expression.begin_pos,
|
52
|
+
end_position)
|
53
|
+
|
54
|
+
->(corrector) { corrector.remove(range) unless range.nil? }
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def find_first_offense(variables)
|
60
|
+
first_offense = nil
|
61
|
+
|
62
|
+
variables.reverse_each do |variable|
|
63
|
+
break unless variable.children.first == :_
|
64
|
+
first_offense = variable
|
65
|
+
end
|
66
|
+
|
67
|
+
first_offense
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -121,8 +121,6 @@ module RuboCop
|
|
121
121
|
autocorrect_instance(node)
|
122
122
|
elsif node.type == :defs && node.children.first.type == :self
|
123
123
|
autocorrect_class(node)
|
124
|
-
else
|
125
|
-
fail CorrectionNotPossible
|
126
124
|
end
|
127
125
|
end
|
128
126
|
|
@@ -130,14 +128,11 @@ module RuboCop
|
|
130
128
|
method_name, args, body = *node
|
131
129
|
unless names_match?(method_name, body) &&
|
132
130
|
(kind = trivial_accessor_kind(method_name, args, body))
|
133
|
-
|
131
|
+
return
|
134
132
|
end
|
135
133
|
|
136
|
-
|
137
|
-
corrector.replace(
|
138
|
-
node.loc.expression,
|
139
|
-
accessor(kind, method_name)
|
140
|
-
)
|
134
|
+
lambda do |corrector|
|
135
|
+
corrector.replace(node.loc.expression, accessor(kind, method_name))
|
141
136
|
end
|
142
137
|
end
|
143
138
|
|
@@ -145,10 +140,10 @@ module RuboCop
|
|
145
140
|
_, method_name, args, body = *node
|
146
141
|
unless names_match?(method_name, body) &&
|
147
142
|
(kind = trivial_accessor_kind(method_name, args, body))
|
148
|
-
|
143
|
+
return
|
149
144
|
end
|
150
145
|
|
151
|
-
|
146
|
+
lambda do |corrector|
|
152
147
|
indent = ' ' * node.loc.column
|
153
148
|
corrector.replace(
|
154
149
|
node.loc.expression,
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
|
48
48
|
def autocorrect(node)
|
49
49
|
delimiter = node.loc.expression.source =~ /^%Q[^"]+$|'/ ? '"' : "'"
|
50
|
-
|
50
|
+
lambda do |corrector|
|
51
51
|
corrector.replace(node.loc.begin, delimiter)
|
52
52
|
corrector.replace(node.loc.end, delimiter)
|
53
53
|
end
|
@@ -30,10 +30,8 @@ module RuboCop
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def autocorrect(node)
|
33
|
-
|
34
|
-
|
35
|
-
corrector.replace(expr, "{#{expr.source}}")
|
36
|
-
end
|
33
|
+
expr = node.loc.expression
|
34
|
+
->(corrector) { corrector.replace(expr, "{#{expr.source}}") }
|
37
35
|
end
|
38
36
|
|
39
37
|
def var_nodes(nodes)
|
@@ -28,13 +28,11 @@ module RuboCop
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def autocorrect(node)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
corrector.remove(whitespaces_and_do_range)
|
37
|
-
end
|
31
|
+
condition_node, = *node
|
32
|
+
end_of_condition_range = condition_node.loc.expression.end
|
33
|
+
do_range = node.loc.begin
|
34
|
+
whitespaces_and_do_range = end_of_condition_range.join(do_range)
|
35
|
+
->(corrector) { corrector.remove(whitespaces_and_do_range) }
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -19,12 +19,10 @@ module RuboCop
|
|
19
19
|
|
20
20
|
def autocorrect(node)
|
21
21
|
cond, body = *node
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
corrector.replace(node.loc.expression, oneline)
|
27
|
-
end
|
22
|
+
oneline = "#{body.loc.expression.source} " \
|
23
|
+
"#{node.loc.keyword.source} " +
|
24
|
+
cond.loc.expression.source
|
25
|
+
->(corrector) { corrector.replace(node.loc.expression, oneline) }
|
28
26
|
end
|
29
27
|
|
30
28
|
private
|
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
contents = node.children.map { |n| source_for(n) }.join(' ')
|
65
65
|
char = @interpolated ? 'W' : 'w'
|
66
66
|
|
67
|
-
|
67
|
+
lambda do |corrector|
|
68
68
|
corrector.replace(node.loc.expression, "%#{char}(#{contents})")
|
69
69
|
end
|
70
70
|
end
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -147,7 +147,8 @@ module RuboCop
|
|
147
147
|
|
148
148
|
go_left, go_right = directions(side)
|
149
149
|
|
150
|
-
begin_pos
|
150
|
+
begin_pos = range.begin_pos
|
151
|
+
end_pos = range.end_pos
|
151
152
|
begin_pos = move_pos(src, begin_pos, -1, go_left, /,/)
|
152
153
|
end_pos = move_pos(src, end_pos, 1, go_right, /,/)
|
153
154
|
|
@@ -161,7 +162,8 @@ module RuboCop
|
|
161
162
|
|
162
163
|
go_left, go_right = directions(side)
|
163
164
|
|
164
|
-
begin_pos
|
165
|
+
begin_pos = range.begin_pos
|
166
|
+
end_pos = range.end_pos
|
165
167
|
begin_pos = move_pos(src, begin_pos, -1, go_left, /[ \t]/)
|
166
168
|
begin_pos = move_pos(src, begin_pos, -1, go_left && with_newline, /\n/)
|
167
169
|
end_pos = move_pos(src, end_pos, 1, go_right, /[ \t]/)
|
@@ -189,7 +191,8 @@ module RuboCop
|
|
189
191
|
end
|
190
192
|
|
191
193
|
def within_node?(inner, outer)
|
192
|
-
o
|
194
|
+
o = outer.loc.expression
|
195
|
+
i = inner.loc.expression
|
193
196
|
i.begin_pos >= o.begin_pos && i.end_pos <= o.end_pos
|
194
197
|
end
|
195
198
|
|
@@ -6,11 +6,12 @@ module RuboCop
|
|
6
6
|
# letters for files with problems in the them. In the end it
|
7
7
|
# appends the regular report data in the clang style format.
|
8
8
|
class ProgressFormatter < ClangStyleFormatter
|
9
|
+
include TextUtil
|
10
|
+
|
9
11
|
def started(target_files)
|
10
12
|
super
|
11
13
|
@offenses_for_files = {}
|
12
|
-
|
13
|
-
output.puts "Inspecting #{target_files.count} #{file_phrase}"
|
14
|
+
output.puts "Inspecting #{pluralize(target_files.size, 'file')}"
|
14
15
|
end
|
15
16
|
|
16
17
|
def file_finished(file, offenses)
|