rubocop 0.31.0 → 0.32.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 +50 -0
- data/README.md +13 -0
- data/config/disabled.yml +4 -0
- data/config/enabled.yml +34 -8
- data/lib/rubocop.rb +4 -1
- data/lib/rubocop/cop/cop.rb +18 -12
- data/lib/rubocop/cop/lint/debugger.rb +7 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +10 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +31 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +9 -0
- data/lib/rubocop/cop/lint/unneeded_disable.rb +53 -0
- data/lib/rubocop/cop/metrics/class_length.rb +1 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -1
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/if_node.rb +10 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +8 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +8 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -5
- data/lib/rubocop/cop/mixin/string_help.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -3
- data/lib/rubocop/cop/performance/count.rb +33 -30
- data/lib/rubocop/cop/performance/sample.rb +103 -59
- data/lib/rubocop/cop/performance/size.rb +2 -1
- data/lib/rubocop/cop/rails/time_zone.rb +14 -6
- data/lib/rubocop/cop/style/align_hash.rb +7 -3
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +39 -11
- data/lib/rubocop/cop/style/case_indentation.rb +18 -4
- data/lib/rubocop/cop/style/comment_annotation.rb +22 -7
- data/lib/rubocop/cop/style/documentation.rb +11 -5
- data/lib/rubocop/cop/style/empty_else.rb +25 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -5
- data/lib/rubocop/cop/style/indentation_width.rb +1 -5
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +12 -10
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/parallel_assignment.rb +196 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -4
- data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +41 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +11 -10
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +8 -0
- data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/team.rb +8 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
- data/lib/rubocop/formatter/formatter_set.rb +24 -1
- data/lib/rubocop/options.rb +4 -0
- data/lib/rubocop/processed_source.rb +4 -1
- data/lib/rubocop/runner.rb +12 -7
- data/lib/rubocop/target_finder.rb +3 -3
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.32.0.md +139 -0
- data/rubocop.gemspec +2 -2
- metadata +12 -8
- data/lib/rubocop/cop/performance/parallel_assignment.rb +0 -79
@@ -1,79 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module Performance
|
6
|
-
# Checks for simple usages of parallel assignment.
|
7
|
-
# This will only complain when the number of variables
|
8
|
-
# being assigned matched the number of assigning variables.
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# # bad
|
12
|
-
# a, b, c = 1, 2, 3
|
13
|
-
# a, b, c = [1, 2, 3]
|
14
|
-
#
|
15
|
-
# # good
|
16
|
-
# one, two = *foo
|
17
|
-
# a, b = foo()
|
18
|
-
#
|
19
|
-
# a = 1
|
20
|
-
# b = 2
|
21
|
-
# c = 3
|
22
|
-
class ParallelAssignment < Cop
|
23
|
-
MSG = 'Do not use parallel assignment.'
|
24
|
-
|
25
|
-
def on_masgn(node)
|
26
|
-
left, right = *node
|
27
|
-
left_elements = *left
|
28
|
-
right_elements = [*right].compact # edge case for one constant
|
29
|
-
|
30
|
-
# only complain when the number of variables matches
|
31
|
-
return if left_elements.size != right_elements.size
|
32
|
-
|
33
|
-
# account for edge cases using one variable with a comma
|
34
|
-
return if left_elements.size == 1
|
35
|
-
|
36
|
-
# allow mass assignment as the return of a method call
|
37
|
-
return if right.block_type? || right.send_type?
|
38
|
-
|
39
|
-
# allow mass assignment when using splat
|
40
|
-
return if (left_elements + right_elements).any?(&:splat_type?)
|
41
|
-
|
42
|
-
return if variable_reassignment?(left_elements, right_elements)
|
43
|
-
|
44
|
-
add_offense(node, :expression)
|
45
|
-
end
|
46
|
-
|
47
|
-
def autocorrect(node)
|
48
|
-
left, right = *node
|
49
|
-
|
50
|
-
lambda do |corrector|
|
51
|
-
l_vars = extract_sources(left)
|
52
|
-
r_vars = extract_sources(right)
|
53
|
-
groups = l_vars.zip(r_vars)
|
54
|
-
|
55
|
-
assignment = groups.map { |pair| pair.join(' = ') }
|
56
|
-
|
57
|
-
space_offset = node.loc.expression.column
|
58
|
-
corrector.replace(node.loc.expression,
|
59
|
-
assignment.join("\n" << ' ' * space_offset))
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def extract_sources(node)
|
66
|
-
node.children.map { |child| child.loc.expression.source }
|
67
|
-
end
|
68
|
-
|
69
|
-
def variable_reassignment?(left_elements, right_elements)
|
70
|
-
left_elements.any? do |le|
|
71
|
-
right_elements.any? do |re|
|
72
|
-
re.loc.expression.is?(le.loc.expression.source)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|