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
@@ -56,7 +56,8 @@ module RuboCop
|
|
56
56
|
|
57
57
|
def correction(node)
|
58
58
|
lambda do |corrector|
|
59
|
-
b
|
59
|
+
b = node.loc.begin
|
60
|
+
e = node.loc.end
|
60
61
|
if b.is?('{')
|
61
62
|
# If the left brace is not preceded by a whitespace character,
|
62
63
|
# then we need a space before `do` to get valid Ruby code.
|
@@ -82,14 +83,6 @@ module RuboCop
|
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
85
|
-
def parentheses?(send_node)
|
86
|
-
send_node.loc.begin
|
87
|
-
end
|
88
|
-
|
89
|
-
def operator?(method_name)
|
90
|
-
method_name =~ /^\W/
|
91
|
-
end
|
92
|
-
|
93
86
|
def proper_block_style?(node)
|
94
87
|
case style
|
95
88
|
when :line_count_based
|
@@ -101,7 +101,7 @@ module RuboCop
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def autocorrect(node)
|
104
|
-
|
104
|
+
return if contains_backtick?(node)
|
105
105
|
|
106
106
|
if backtick_literal?(node)
|
107
107
|
replacement = ['%x', ''].zip(preferred_delimiters).map(&:join)
|
@@ -109,7 +109,7 @@ module RuboCop
|
|
109
109
|
replacement = %w(` `)
|
110
110
|
end
|
111
111
|
|
112
|
-
|
112
|
+
lambda do |corrector|
|
113
113
|
corrector.replace(node.loc.begin, replacement.first)
|
114
114
|
corrector.replace(node.loc.end, replacement.last)
|
115
115
|
end
|
@@ -18,16 +18,23 @@ module RuboCop
|
|
18
18
|
!correct_annotation?(first_word, colon, space, note)
|
19
19
|
|
20
20
|
start = comment.loc.expression.begin_pos + margin.length
|
21
|
-
length = first_word.length +
|
21
|
+
length = first_word.length + colon.to_s.length + space.to_s.length
|
22
22
|
range = Parser::Source::Range.new(processed_source.buffer,
|
23
23
|
start,
|
24
24
|
start + length)
|
25
|
-
add_offense(
|
25
|
+
add_offense(range, range)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
+
def autocorrect(range)
|
32
|
+
lambda do |corrector|
|
33
|
+
annotation_keyword = range.source.split(/:?\s+/).first
|
34
|
+
corrector.replace(range, annotation_keyword.upcase << ': ')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
31
38
|
def correct_annotation?(first_word, colon, space, note)
|
32
39
|
keyword?(first_word) && (colon && space && note || !colon && !note)
|
33
40
|
end
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
72
72
|
'your RuboCop config' if autocorrect_notice.empty?
|
73
73
|
fail "AutocorrectNotice '#{autocorrect_notice}' must match " \
|
74
74
|
"Notice /#{notice}/" unless autocorrect_notice =~ Regexp.new(notice)
|
75
|
-
|
75
|
+
lambda do |corrector|
|
76
76
|
if token.nil?
|
77
77
|
range = Parser::Source::Range.new('', 0, 0)
|
78
78
|
else
|
@@ -36,9 +36,7 @@ module RuboCop
|
|
36
36
|
|
37
37
|
def autocorrect(node)
|
38
38
|
range = range_with_surrounding_space(node.loc.expression, :left)
|
39
|
-
|
40
|
-
corrector.insert_before(range, "\n")
|
41
|
-
end
|
39
|
+
->(corrector) { corrector.insert_before(range, "\n") }
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
@@ -51,16 +51,12 @@ module RuboCop
|
|
51
51
|
# because the braces are interpreted as a block, so we avoid
|
52
52
|
# the correction. Parentheses around the arguments would
|
53
53
|
# solve the problem, but we let the user add those manually.
|
54
|
-
if first_arg_in_method_call_without_parentheses?(node)
|
55
|
-
fail CorrectionNotPossible
|
56
|
-
end
|
54
|
+
return if first_arg_in_method_call_without_parentheses?(node)
|
57
55
|
'{}'
|
58
56
|
when STR_NODE
|
59
57
|
"''"
|
60
58
|
end
|
61
|
-
|
62
|
-
corrector.replace(node.loc.expression, name)
|
63
|
-
end
|
59
|
+
->(corrector) { corrector.replace(node.loc.expression, name) }
|
64
60
|
end
|
65
61
|
|
66
62
|
def first_arg_in_method_call_without_parentheses?(node)
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
def autocorrect(node)
|
34
34
|
encoding = cop_config['AutoCorrectEncodingComment']
|
35
35
|
if encoding && encoding =~ ENCODING_PATTERN
|
36
|
-
|
36
|
+
lambda do |corrector|
|
37
37
|
corrector.replace(node.pos, "#{encoding}\n#{node.pos.source}")
|
38
38
|
end
|
39
39
|
else
|
@@ -26,10 +26,8 @@ module RuboCop
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def autocorrect(node)
|
29
|
-
|
30
|
-
|
31
|
-
corrector.replace(node.loc.expression, correction)
|
32
|
-
end
|
29
|
+
correction = "#{base_number(node)}.#{offense_type(node)}?"
|
30
|
+
->(corrector) { corrector.replace(node.loc.expression, correction) }
|
33
31
|
end
|
34
32
|
|
35
33
|
private
|
@@ -27,6 +27,7 @@ module RuboCop
|
|
27
27
|
class GuardClause < Cop
|
28
28
|
include ConfigurableEnforcedStyle
|
29
29
|
include IfNode
|
30
|
+
include MinBodyLength
|
30
31
|
|
31
32
|
MSG = 'Use a guard clause instead of wrapping the code inside a ' \
|
32
33
|
'conditional expression.'
|
@@ -62,17 +63,6 @@ module RuboCop
|
|
62
63
|
|
63
64
|
add_offense(node, :keyword, MSG)
|
64
65
|
end
|
65
|
-
|
66
|
-
def min_body_length?(node)
|
67
|
-
(node.loc.end.line - node.loc.keyword.line) > min_body_length
|
68
|
-
end
|
69
|
-
|
70
|
-
def min_body_length
|
71
|
-
length = cop_config['MinBodyLength'] || 1
|
72
|
-
return length if length.is_a?(Integer) && length > 0
|
73
|
-
|
74
|
-
fail 'MinBodyLength needs to be a positive integer!'
|
75
|
-
end
|
76
66
|
end
|
77
67
|
end
|
78
68
|
end
|
@@ -25,18 +25,23 @@ module RuboCop
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def autocorrect(node)
|
28
|
-
if node.loc.keyword.
|
28
|
+
if node.loc.keyword.is?('if')
|
29
29
|
cond, body = *node
|
30
30
|
else
|
31
31
|
cond, _else, body = *node
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
oneline =
|
35
|
+
"#{body.loc.expression.source} #{node.loc.keyword.source} " +
|
36
|
+
cond.loc.expression.source
|
37
|
+
first_line_comment = processed_source.comments.find do |c|
|
38
|
+
c.loc.line == node.loc.line
|
39
39
|
end
|
40
|
+
if first_line_comment
|
41
|
+
oneline << ' ' << first_line_comment.loc.expression.source
|
42
|
+
end
|
43
|
+
|
44
|
+
->(corrector) { corrector.replace(node.loc.expression, oneline) }
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
@@ -86,7 +86,15 @@ module RuboCop
|
|
86
86
|
args)
|
87
87
|
|
88
88
|
_method_name, _args, body = *args.first
|
89
|
-
|
89
|
+
def_end_config = config.for_cop('Lint/DefEndAlignment')
|
90
|
+
style = if def_end_config['Enabled']
|
91
|
+
def_end_config['AlignWith']
|
92
|
+
else
|
93
|
+
'start_of_line'
|
94
|
+
end
|
95
|
+
base = style == 'def' ? args.first : node
|
96
|
+
|
97
|
+
check_indentation(base.loc.expression, body)
|
90
98
|
ignore_node(args.first)
|
91
99
|
end
|
92
100
|
|
@@ -232,7 +240,8 @@ module RuboCop
|
|
232
240
|
|
233
241
|
def offending_range(body_node, indentation)
|
234
242
|
expr = body_node.loc.expression
|
235
|
-
begin_pos
|
243
|
+
begin_pos = expr.begin_pos
|
244
|
+
ind = expr.begin_pos - indentation
|
236
245
|
pos = indentation >= 0 ? ind..begin_pos : begin_pos..ind
|
237
246
|
Parser::Source::Range.new(expr.source_buffer, pos.begin, pos.end)
|
238
247
|
end
|
@@ -40,14 +40,14 @@ module RuboCop
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def autocorrect(node)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
condition_node, = *node
|
44
|
+
start_range = node.loc.keyword.begin
|
45
|
+
end_range = if node.loc.begin
|
46
|
+
node.loc.begin.end
|
47
|
+
else
|
48
|
+
condition_node.loc.expression.end
|
49
|
+
end
|
50
|
+
lambda do |corrector|
|
51
51
|
corrector.replace(start_range.join(end_range), 'loop do')
|
52
52
|
end
|
53
53
|
end
|
@@ -23,9 +23,7 @@ module RuboCop
|
|
23
23
|
expr = comment.loc.expression
|
24
24
|
b = expr.begin_pos
|
25
25
|
hash_mark = Parser::Source::Range.new(expr.source_buffer, b, b + 1)
|
26
|
-
|
27
|
-
corrector.insert_after(hash_mark, ' ')
|
28
|
-
end
|
26
|
+
->(corrector) { corrector.insert_after(hash_mark, ' ') }
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
@@ -35,13 +35,11 @@ module RuboCop
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def autocorrect(operator_range)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
corrector.replace(operator_range, '\\')
|
44
|
-
end
|
38
|
+
# Include any trailing whitespace so we don't create a syntax error.
|
39
|
+
operator_range = range_with_surrounding_space(operator_range,
|
40
|
+
:right, nil,
|
41
|
+
!:with_newline)
|
42
|
+
->(corrector) { corrector.replace(operator_range, '\\') }
|
45
43
|
end
|
46
44
|
|
47
45
|
private
|
@@ -17,14 +17,7 @@ module RuboCop
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def autocorrect(node)
|
20
|
-
|
21
|
-
if config.for_cop('Style/EmptyLiteral')['Enabled'] &&
|
22
|
-
[EmptyLiteral::HASH_NODE,
|
23
|
-
EmptyLiteral::ARRAY_NODE,
|
24
|
-
EmptyLiteral::STR_NODE].include?(node)
|
25
|
-
return
|
26
|
-
end
|
27
|
-
@corrections << lambda do |corrector|
|
20
|
+
lambda do |corrector|
|
28
21
|
corrector.remove(node.loc.begin)
|
29
22
|
corrector.remove(node.loc.end)
|
30
23
|
end
|
@@ -24,7 +24,7 @@ module RuboCop
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def autocorrect(node)
|
27
|
-
|
27
|
+
lambda do |corrector|
|
28
28
|
if style == :require_parentheses
|
29
29
|
args_expr = args_node(node).loc.expression
|
30
30
|
args_with_space = range_with_surrounding_space(args_expr, :left)
|