rubocop 0.48.1 → 0.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/config/default.yml +397 -357
- data/config/disabled.yml +29 -29
- data/config/enabled.yml +366 -326
- data/lib/rubocop.rb +85 -70
- data/lib/rubocop/ast/builder.rb +4 -1
- data/lib/rubocop/ast/node.rb +2 -2
- data/lib/rubocop/ast/node/and_node.rb +1 -1
- data/lib/rubocop/ast/node/args_node.rb +24 -0
- data/lib/rubocop/ast/node/block_node.rb +107 -0
- data/lib/rubocop/ast/node/case_node.rb +1 -1
- data/lib/rubocop/ast/node/ensure_node.rb +1 -1
- data/lib/rubocop/ast/node/for_node.rb +1 -1
- data/lib/rubocop/ast/node/if_node.rb +1 -1
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +74 -0
- data/lib/rubocop/ast/node/or_node.rb +1 -1
- data/lib/rubocop/ast/node/pair_node.rb +1 -1
- data/lib/rubocop/ast/node/resbody_node.rb +1 -1
- data/lib/rubocop/ast/node/send_node.rb +36 -57
- data/lib/rubocop/ast/node/super_node.rb +42 -0
- data/lib/rubocop/ast/node/until_node.rb +1 -1
- data/lib/rubocop/ast/node/when_node.rb +1 -1
- data/lib/rubocop/ast/node/while_node.rb +1 -1
- data/lib/rubocop/cli.rb +10 -0
- data/lib/rubocop/config.rb +23 -7
- data/lib/rubocop/config_loader.rb +19 -3
- data/lib/rubocop/cop/badge.rb +1 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/cop.rb +10 -0
- data/lib/rubocop/cop/{style → layout}/access_modifier_indentation.rb +33 -3
- data/lib/rubocop/cop/{style → layout}/align_array.rb +16 -1
- data/lib/rubocop/cop/{style → layout}/align_hash.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/align_parameters.rb +29 -1
- data/lib/rubocop/cop/{style → layout}/block_end_newline.rb +10 -5
- data/lib/rubocop/cop/{style → layout}/case_indentation.rb +64 -1
- data/lib/rubocop/cop/{style → layout}/closing_parenthesis_indentation.rb +2 -2
- data/lib/rubocop/cop/{style → layout}/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/dot_position.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/else_alignment.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/empty_line_after_magic_comment.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/empty_lines.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/empty_lines_around_access_modifier.rb +2 -7
- data/lib/rubocop/cop/{style → layout}/empty_lines_around_begin_body.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/empty_lines_around_block_body.rb +2 -4
- data/lib/rubocop/cop/{style → layout}/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/empty_lines_around_exception_handling_keywords.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/empty_lines_around_method_body.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/empty_lines_around_module_body.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/end_of_line.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/first_array_element_line_break.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/first_hash_element_line_break.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/first_method_argument_line_break.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/first_method_parameter_line_break.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/indent_array.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/indent_assignment.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/indent_hash.rb +2 -2
- data/lib/rubocop/cop/{style → layout}/indent_heredoc.rb +3 -3
- data/lib/rubocop/cop/{style → layout}/indentation_consistency.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/indentation_width.rb +10 -12
- data/lib/rubocop/cop/{style → layout}/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/multiline_array_brace_layout.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/multiline_block_layout.rb +21 -36
- data/lib/rubocop/cop/{style → layout}/multiline_hash_brace_layout.rb +5 -1
- data/lib/rubocop/cop/{style → layout}/multiline_method_call_brace_layout.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/multiline_method_call_indentation.rb +3 -3
- data/lib/rubocop/cop/{style → layout}/multiline_method_definition_brace_layout.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/multiline_operation_indentation.rb +6 -5
- data/lib/rubocop/cop/{style → layout}/rescue_ensure_alignment.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_after_colon.rb +2 -2
- data/lib/rubocop/cop/{style → layout}/space_after_comma.rb +2 -2
- data/lib/rubocop/cop/{style → layout}/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_after_not.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_after_semicolon.rb +2 -2
- data/lib/rubocop/cop/{style → layout}/space_around_block_parameters.rb +7 -5
- data/lib/rubocop/cop/{style → layout}/space_around_equals_in_parameter_default.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_around_operators.rb +6 -2
- data/lib/rubocop/cop/{style → layout}/space_before_block_braces.rb +6 -2
- data/lib/rubocop/cop/{style → layout}/space_before_comma.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_before_comment.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_before_first_arg.rb +4 -2
- data/lib/rubocop/cop/{style → layout}/space_before_semicolon.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_inside_array_percent_literal.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_inside_block_braces.rb +3 -4
- data/lib/rubocop/cop/{style → layout}/space_inside_brackets.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_inside_parens.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_inside_percent_literal_delimiters.rb +8 -7
- data/lib/rubocop/cop/{style → layout}/space_inside_range_literal.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/space_inside_string_interpolation.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/tab.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/trailing_blank_lines.rb +1 -1
- data/lib/rubocop/cop/{style → layout}/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -4
- data/lib/rubocop/cop/lint/debugger.rb +0 -15
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +81 -0
- data/lib/rubocop/cop/lint/script_permission.rb +42 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
- data/lib/rubocop/cop/message_annotator.rb +23 -13
- data/lib/rubocop/cop/metrics/block_length.rb +1 -1
- data/lib/rubocop/cop/mixin/array_min_size.rb +59 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +10 -11
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +36 -0
- data/lib/rubocop/cop/mixin/hash_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +7 -3
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/performance/caller.rb +41 -0
- data/lib/rubocop/cop/performance/compare_with_block.rb +60 -14
- data/lib/rubocop/cop/performance/double_start_end_with.rb +2 -2
- data/lib/rubocop/cop/performance/redundant_merge.rb +2 -0
- data/lib/rubocop/cop/rails/action_filter.rb +1 -3
- data/lib/rubocop/cop/rails/application_job.rb +32 -0
- data/lib/rubocop/cop/rails/application_record.rb +32 -0
- data/lib/rubocop/cop/rails/blank.rb +9 -3
- data/lib/rubocop/cop/rails/output_safety.rb +59 -15
- data/lib/rubocop/cop/rails/present.rb +9 -3
- data/lib/rubocop/cop/rails/relative_date_constant.rb +35 -4
- data/lib/rubocop/cop/rails/reversible_migration.rb +82 -18
- data/lib/rubocop/cop/rails/save_bang.rb +7 -2
- data/lib/rubocop/cop/rails/skips_model_validations.rb +7 -0
- data/lib/rubocop/cop/registry.rb +4 -3
- data/lib/rubocop/cop/security/eval.rb +9 -3
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +11 -17
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +1 -3
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/copyright.rb +2 -2
- data/lib/rubocop/cop/style/documentation_method.rb +1 -1
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +2 -1
- data/lib/rubocop/cop/style/each_with_object.rb +10 -6
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/for.rb +4 -5
- data/lib/rubocop/cop/style/format_string.rb +49 -0
- data/lib/rubocop/cop/style/format_string_token.rb +141 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +10 -1
- data/lib/rubocop/cop/style/lambda.rb +9 -9
- data/lib/rubocop/cop/style/line_end_concatenation.rb +4 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -2
- data/lib/rubocop/cop/style/method_name.rb +8 -2
- data/lib/rubocop/cop/style/mixin_grouping.rb +41 -3
- data/lib/rubocop/cop/style/multiline_block_chain.rb +7 -11
- data/lib/rubocop/cop/style/multiple_comparison.rb +77 -0
- data/lib/rubocop/cop/style/next.rb +11 -22
- data/lib/rubocop/cop/style/parallel_assignment.rb +10 -19
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -2
- data/lib/rubocop/cop/style/self_assignment.rb +4 -0
- data/lib/rubocop/cop/style/single_line_block_params.rb +23 -17
- data/lib/rubocop/cop/style/symbol_array.rb +24 -13
- data/lib/rubocop/cop/style/symbol_proc.rb +4 -0
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_interpolation.rb +4 -0
- data/lib/rubocop/cop/style/word_array.rb +33 -53
- data/lib/rubocop/cop/style/yoda_condition.rb +78 -0
- data/lib/rubocop/cop/team.rb +1 -14
- data/lib/rubocop/cop/util.rb +16 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +0 -11
- data/lib/rubocop/node_pattern.rb +52 -52
- data/lib/rubocop/options.rb +25 -0
- data/lib/rubocop/path_util.rb +17 -1
- data/lib/rubocop/result_cache.rb +8 -7
- data/lib/rubocop/rspec/expect_offense.rb +167 -0
- data/lib/rubocop/rspec/shared_examples.rb +0 -8
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/runner.rb +12 -2
- data/lib/rubocop/target_finder.rb +5 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +101 -72
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
# Checks whether the `if` node has an `else` clause.
|
37
37
|
#
|
38
38
|
# @note This returns `true` for nodes containing an `elsif` clause.
|
39
|
-
# This is legacy
|
39
|
+
# This is legacy behavior, and many cops rely on it.
|
40
40
|
#
|
41
41
|
# @return [Boolean] whether the node has an `else` clause
|
42
42
|
def else?
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# Common functionality for nodes that are parameterized:
|
6
|
+
# `send`, `super`, `zsuper` ...
|
7
|
+
module ParameterizedNode
|
8
|
+
# Checks whether this super invocation's arguments are wrapped in
|
9
|
+
# parentheses.
|
10
|
+
#
|
11
|
+
# @return [Boolean] whether this super invocation's arguments are
|
12
|
+
# wrapped in parentheses
|
13
|
+
def parenthesized?
|
14
|
+
loc.end && loc.end.is?(')')
|
15
|
+
end
|
16
|
+
|
17
|
+
# A shorthand for getting the first argument of the method invocation.
|
18
|
+
# Equivalent to `arguments.first`.
|
19
|
+
#
|
20
|
+
# @return [Node, nil] the first argument of the method invocation,
|
21
|
+
# or `nil` if there are no arguments
|
22
|
+
def first_argument
|
23
|
+
arguments[0]
|
24
|
+
end
|
25
|
+
|
26
|
+
# A shorthand for getting the last argument of the method invocation.
|
27
|
+
# Equivalent to `arguments.last`.
|
28
|
+
#
|
29
|
+
# @return [Node, nil] the last argument of the method invocation,
|
30
|
+
# or `nil` if there are no arguments
|
31
|
+
def last_argument
|
32
|
+
arguments[-1]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Checks whether this method was invoked with arguments.
|
36
|
+
#
|
37
|
+
# @return [Boolean] whether this method was invoked with arguments
|
38
|
+
def arguments?
|
39
|
+
!arguments.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
# Checks whether any argument of the method invocation is a splat
|
43
|
+
# argument, i.e. `*splat`.
|
44
|
+
#
|
45
|
+
# @return [Boolean] whether the invoked method is a splat argument
|
46
|
+
def splat_argument?
|
47
|
+
arguments? && arguments.any?(&:splat_type?)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Whether the last argument of the method invocation is a block pass,
|
51
|
+
# i.e. `&block`.
|
52
|
+
#
|
53
|
+
# @return [Boolean] whether the invoked method is a block pass
|
54
|
+
def block_argument?
|
55
|
+
arguments? && last_argument.block_pass_type?
|
56
|
+
end
|
57
|
+
|
58
|
+
# Whether this method invocation has an explicit block.
|
59
|
+
#
|
60
|
+
# @return [Boolean] whether the invoked method has a block
|
61
|
+
def block_literal?
|
62
|
+
parent && parent.block_type? && eql?(parent.send_node)
|
63
|
+
end
|
64
|
+
|
65
|
+
# The block node associated with this method call, if any.
|
66
|
+
#
|
67
|
+
# @return [BlockNode, nil] the `block` node associated with this method
|
68
|
+
# call or `nil`
|
69
|
+
def block_node
|
70
|
+
parent if block_literal?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -6,6 +6,13 @@ module RuboCop
|
|
6
6
|
# node when the builder constructs the AST, making its methods available
|
7
7
|
# to all `send` nodes within RuboCop.
|
8
8
|
class SendNode < Node
|
9
|
+
include ParameterizedNode
|
10
|
+
|
11
|
+
ENUMERATOR_METHODS = %i[collect collect_concat detect downto each
|
12
|
+
find find_all find_index inject loop map!
|
13
|
+
map reduce reject reject! reverse_each select
|
14
|
+
select! times upto].freeze
|
15
|
+
|
9
16
|
# The receiving node of the method invocation.
|
10
17
|
#
|
11
18
|
# @return [Node, nil] the receiver of the invoked method or `nil`
|
@@ -20,6 +27,13 @@ module RuboCop
|
|
20
27
|
node_parts[1]
|
21
28
|
end
|
22
29
|
|
30
|
+
# An array containing the arguments of the method invocation.
|
31
|
+
#
|
32
|
+
# @return [Array<Node>] the arguments of the method invocation or `nil`
|
33
|
+
def arguments
|
34
|
+
node_parts[2..-1]
|
35
|
+
end
|
36
|
+
|
23
37
|
# Checks whether the method name matches the argument.
|
24
38
|
#
|
25
39
|
# @param [Symbol, String] name the method name to check for
|
@@ -48,59 +62,40 @@ module RuboCop
|
|
48
62
|
!receiver && method?(name)
|
49
63
|
end
|
50
64
|
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# @return [Array<Node>] the arguments of the method invocation or `nil`
|
54
|
-
def arguments
|
55
|
-
node_parts[2..-1]
|
56
|
-
end
|
57
|
-
|
58
|
-
# A shorthand for getting the first argument of the method invocation.
|
59
|
-
# Equivalent to `arguments.first`.
|
60
|
-
#
|
61
|
-
# @return [Node, nil] the first argument of the method invocation,
|
62
|
-
# or `nil` if there are no arguments
|
63
|
-
def first_argument
|
64
|
-
arguments[0]
|
65
|
-
end
|
66
|
-
|
67
|
-
# A shorthand for getting the last argument of the method invocation.
|
68
|
-
# Equivalent to `arguments.last`.
|
65
|
+
# Checks whether the invoked method is a setter method.
|
69
66
|
#
|
70
|
-
# @return [
|
71
|
-
|
72
|
-
|
73
|
-
arguments[-1]
|
67
|
+
# @return [Boolean] whether the invoked method is a setter
|
68
|
+
def setter_method?
|
69
|
+
loc.operator
|
74
70
|
end
|
75
71
|
|
76
|
-
# Checks whether
|
72
|
+
# Checks whether the invoked method is an operator method.
|
77
73
|
#
|
78
|
-
# @return [Boolean] whether
|
79
|
-
def
|
80
|
-
|
74
|
+
# @return [Boolean] whether the invoked method is an operator
|
75
|
+
def operator_method?
|
76
|
+
RuboCop::Cop::Util::OPERATOR_METHODS.include?(method_name)
|
81
77
|
end
|
82
78
|
|
83
|
-
# Checks whether
|
84
|
-
# parentheses.
|
79
|
+
# Checks whether the invoked method is a comparison method.
|
85
80
|
#
|
86
|
-
# @return [Boolean] whether
|
87
|
-
|
88
|
-
|
89
|
-
loc.end && loc.end.is?(')')
|
81
|
+
# @return [Boolean] whether the involed method is a comparison
|
82
|
+
def comparison_method?
|
83
|
+
COMPARISON_OPERATORS.include?(method_name)
|
90
84
|
end
|
91
85
|
|
92
|
-
# Checks whether the invoked method is
|
86
|
+
# Checks whether the invoked method is an assignment method.
|
93
87
|
#
|
94
|
-
# @return [Boolean] whether the invoked method is
|
95
|
-
def
|
96
|
-
|
88
|
+
# @return [Boolean] whether the invoked method is an assignment.
|
89
|
+
def assignment_method?
|
90
|
+
!comparison_method? && method_name.to_s.end_with?('=')
|
97
91
|
end
|
98
92
|
|
99
|
-
# Checks whether the invoked method is an
|
93
|
+
# Checks whether the invoked method is an enumerator method.
|
100
94
|
#
|
101
|
-
# @return [Boolean] whether the invoked method is an
|
102
|
-
def
|
103
|
-
|
95
|
+
# @return [Boolean] whether the invoked method is an enumerator.
|
96
|
+
def enumerator_method?
|
97
|
+
ENUMERATOR_METHODS.include?(method_name) ||
|
98
|
+
method_name.to_s.start_with?('each_')
|
104
99
|
end
|
105
100
|
|
106
101
|
# Checks whether the method call uses a dot to connect the receiver and
|
@@ -160,28 +155,12 @@ module RuboCop
|
|
160
155
|
method_name.to_s =~ /\A[A-Z]/
|
161
156
|
end
|
162
157
|
|
163
|
-
# Whether the last argument of the method invocation is a block pass,
|
164
|
-
# i.e. `&block`.
|
165
|
-
#
|
166
|
-
# @return [Boolean] whether the invoked method is a block pass
|
167
|
-
def block_argument?
|
168
|
-
arguments? && last_argument.block_pass_type?
|
169
|
-
end
|
170
|
-
|
171
|
-
# Checks whether any argument of the method invocation is a splat
|
172
|
-
# argument, i.e. `*splat`.
|
173
|
-
#
|
174
|
-
# @return [Boolean] whether the invoked method is a splat argument
|
175
|
-
def splat_argument?
|
176
|
-
arguments? && arguments.any?(&:splat_type?)
|
177
|
-
end
|
178
|
-
|
179
158
|
# Custom destructuring method. This can be used to normalize
|
180
159
|
# destructuring for different variations of the node.
|
181
160
|
#
|
182
161
|
# @return [Array] the different parts of the `send` node
|
183
162
|
def node_parts
|
184
|
-
|
163
|
+
to_a
|
185
164
|
end
|
186
165
|
|
187
166
|
private
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `super`- and `zsuper` nodes. This will be used in
|
6
|
+
# place of a plain node when the builder constructs the AST, making its
|
7
|
+
# methods available to all `super`- and `zsuper` nodes within RuboCop.
|
8
|
+
class SuperNode < Node
|
9
|
+
include ParameterizedNode
|
10
|
+
|
11
|
+
# The method name of this `super` node. Always `:super`.
|
12
|
+
#
|
13
|
+
# @return [Symbol] the method name of `super`
|
14
|
+
def method_name
|
15
|
+
:super
|
16
|
+
end
|
17
|
+
|
18
|
+
# An array containing the arguments of the super invocation.
|
19
|
+
#
|
20
|
+
# @return [Array<Node>] the arguments of the super invocation
|
21
|
+
def arguments
|
22
|
+
node_parts
|
23
|
+
end
|
24
|
+
|
25
|
+
# Checks whether the method name matches the argument.
|
26
|
+
#
|
27
|
+
# @param [Symbol, String] name the method name to check for
|
28
|
+
# @return [Boolean] whether the method name matches the argument
|
29
|
+
def method?(name)
|
30
|
+
method_name == name.to_sym
|
31
|
+
end
|
32
|
+
|
33
|
+
# Custom destructuring method. This can be used to normalize
|
34
|
+
# destructuring for different variations of the node.
|
35
|
+
#
|
36
|
+
# @return [Array] the different parts of the `block` node
|
37
|
+
def node_parts
|
38
|
+
to_a
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/rubocop/cli.rb
CHANGED
@@ -21,6 +21,7 @@ module RuboCop
|
|
21
21
|
# @return [Integer] UNIX exit code
|
22
22
|
def run(args = ARGV)
|
23
23
|
@options, paths = Options.new.parse(args)
|
24
|
+
validate_options_vs_config
|
24
25
|
act_on_options
|
25
26
|
apply_default_formatter
|
26
27
|
|
@@ -47,6 +48,15 @@ module RuboCop
|
|
47
48
|
|
48
49
|
private
|
49
50
|
|
51
|
+
def validate_options_vs_config
|
52
|
+
if @options[:parallel] &&
|
53
|
+
!@config_store.for(Dir.pwd).for_all_cops['UseCache']
|
54
|
+
raise ArgumentError, '-P/--parallel uses caching to speed up ' \
|
55
|
+
'execution, so combining with AllCops: ' \
|
56
|
+
'UseCache: false is not allowed.'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
50
60
|
def act_on_options
|
51
61
|
handle_exiting_options
|
52
62
|
|
data/lib/rubocop/config.rb
CHANGED
@@ -28,25 +28,41 @@ module RuboCop
|
|
28
28
|
'The `Rails/DefaultScope` cop no longer exists.',
|
29
29
|
'Style/SingleSpaceBeforeFirstArg' =>
|
30
30
|
'The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to ' \
|
31
|
-
'`
|
31
|
+
'`Layout/SpaceBeforeFirstArg`.',
|
32
32
|
'Lint/SpaceBeforeFirstArg' =>
|
33
33
|
'The `Lint/SpaceBeforeFirstArg` cop has been removed, since it was a ' \
|
34
|
-
'duplicate of `
|
35
|
-
'`
|
34
|
+
'duplicate of `Layout/SpaceBeforeFirstArg`. Please use ' \
|
35
|
+
'`Layout/SpaceBeforeFirstArg` instead.',
|
36
|
+
'Layout/SpaceAfterControlKeyword' =>
|
37
|
+
'The `Layout/SpaceAfterControlKeyword` cop has been removed. Please ' \
|
38
|
+
'use `Layout/SpaceAroundKeyword` instead.',
|
39
|
+
'Layout/SpaceBeforeModifierKeyword' =>
|
40
|
+
'The `Layout/SpaceBeforeModifierKeyword` cop has been removed. ' \
|
41
|
+
'Please use `Layout/SpaceAroundKeyword` instead.',
|
36
42
|
'Style/SpaceAfterControlKeyword' =>
|
37
43
|
'The `Style/SpaceAfterControlKeyword` cop has been removed. Please ' \
|
38
|
-
'use `
|
44
|
+
'use `Layout/SpaceAroundKeyword` instead.',
|
39
45
|
'Style/SpaceBeforeModifierKeyword' =>
|
40
46
|
'The `Style/SpaceBeforeModifierKeyword` cop has been removed. Please ' \
|
41
|
-
'use `
|
47
|
+
'use `Layout/SpaceAroundKeyword` instead.',
|
42
48
|
'Style/MethodCallParentheses' =>
|
43
49
|
'The `Style/MethodCallParentheses` cop has been renamed to ' \
|
44
50
|
'`Style/MethodCallWithoutArgsParentheses`.',
|
45
51
|
'Lint/Eval' =>
|
46
|
-
'The `Lint/Eval` cop has been renamed to `Security/Eval`.'
|
52
|
+
'The `Lint/Eval` cop has been renamed to `Security/Eval`.',
|
53
|
+
'Style/DeprecatedHashMethods' =>
|
54
|
+
'The `Style/DeprecatedHashMethods` cop has been renamed to ' \
|
55
|
+
'`Style/PreferredHashMethods`.'
|
47
56
|
}.freeze
|
48
57
|
|
49
58
|
OBSOLETE_PARAMETERS = [
|
59
|
+
{
|
60
|
+
cop: 'Layout/SpaceAroundOperators',
|
61
|
+
parameter: 'MultiSpaceAllowedForOperators',
|
62
|
+
alternative: 'If your intention was to allow extra spaces ' \
|
63
|
+
'for alignment, please use AllowForAlignment: ' \
|
64
|
+
'true instead.'
|
65
|
+
},
|
50
66
|
{
|
51
67
|
cop: 'Style/SpaceAroundOperators',
|
52
68
|
parameter: 'MultiSpaceAllowedForOperators',
|
@@ -61,7 +77,7 @@ module RuboCop
|
|
61
77
|
"Rails:\n Enabled: true"
|
62
78
|
},
|
63
79
|
{
|
64
|
-
cop: '
|
80
|
+
cop: 'Layout/CaseIndentation',
|
65
81
|
parameter: 'IndentWhenRelativeTo',
|
66
82
|
alternative: '`IndentWhenRelativeTo` has been renamed to ' \
|
67
83
|
'`EnforcedStyle`'
|
@@ -147,9 +147,7 @@ module RuboCop
|
|
147
147
|
end
|
148
148
|
|
149
149
|
if disabled_by_default
|
150
|
-
config =
|
151
|
-
{ 'Enabled' => true }.merge(params) # Set true if not set.
|
152
|
-
end
|
150
|
+
config = handle_disabled_by_default(config, default_configuration)
|
153
151
|
end
|
154
152
|
|
155
153
|
Config.new(merge(default_configuration, config), config_file)
|
@@ -164,6 +162,24 @@ module RuboCop
|
|
164
162
|
|
165
163
|
private
|
166
164
|
|
165
|
+
def handle_disabled_by_default(config, new_default_configuration)
|
166
|
+
department_config = config.to_hash.reject { |cop| cop.include?('/') }
|
167
|
+
department_config.each do |dept, dept_params|
|
168
|
+
next unless dept_params['Enabled']
|
169
|
+
|
170
|
+
new_default_configuration.each do |cop, params|
|
171
|
+
next unless cop.start_with?(dept + '/')
|
172
|
+
|
173
|
+
# Retain original default configuration for cops in the department.
|
174
|
+
params['Enabled'] = default_configuration[cop]['Enabled']
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
transform(config) do |params|
|
179
|
+
{ 'Enabled' => true }.merge(params) # Set true if not set.
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
167
183
|
# Returns a new hash where the parameters of the given config hash have
|
168
184
|
# been replaced by parameters returned by the given block.
|
169
185
|
def transform(config)
|