rubocop 0.75.1 → 0.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +4 -4
- data/config/default.yml +374 -335
- data/lib/rubocop.rb +53 -32
- data/lib/rubocop/ast/builder.rb +43 -41
- data/lib/rubocop/ast/node.rb +5 -13
- data/lib/rubocop/ast/node/block_node.rb +2 -0
- data/lib/rubocop/ast/node/def_node.rb +11 -0
- data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
- data/lib/rubocop/ast/node/regexp_node.rb +2 -4
- data/lib/rubocop/ast/node/return_node.rb +24 -0
- data/lib/rubocop/ast/traversal.rb +20 -3
- data/lib/rubocop/cli.rb +11 -227
- data/lib/rubocop/cli/command.rb +21 -0
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
- data/lib/rubocop/cli/command/base.rb +33 -0
- data/lib/rubocop/cli/command/execute_runner.rb +76 -0
- data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
- data/lib/rubocop/cli/command/show_cops.rb +80 -0
- data/lib/rubocop/cli/command/version.rb +17 -0
- data/lib/rubocop/cli/environment.rb +21 -0
- data/lib/rubocop/comment_config.rb +8 -3
- data/lib/rubocop/config.rb +8 -1
- data/lib/rubocop/config_loader.rb +20 -20
- data/lib/rubocop/config_loader_resolver.rb +2 -1
- data/lib/rubocop/config_obsoletion.rb +73 -10
- data/lib/rubocop/config_validator.rb +77 -110
- data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
- data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
- data/lib/rubocop/cop/commissioner.rb +15 -7
- data/lib/rubocop/cop/cop.rb +31 -6
- data/lib/rubocop/cop/corrector.rb +8 -7
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/generator.rb +3 -4
- data/lib/rubocop/cop/generator/configuration_injector.rb +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
- data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
- data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
- data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
- data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
- data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
- data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +16 -8
- data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
- data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -2
- data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +68 -112
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +50 -7
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
- data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
- data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
- data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
- data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
- data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
- data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +18 -15
- data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
- data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
- data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
- data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
- data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
- data/lib/rubocop/cop/lint/void.rb +4 -4
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
- data/lib/rubocop/cop/migration/department_name.rb +30 -2
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
- data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +172 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
- data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
- data/lib/rubocop/cop/mixin/trailing_comma.rb +16 -18
- data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
- data/lib/rubocop/cop/naming/file_name.rb +12 -5
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
- data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
- data/lib/rubocop/cop/offense.rb +11 -0
- data/lib/rubocop/cop/registry.rb +8 -3
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +10 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/copyright.rb +11 -7
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +2 -2
- data/lib/rubocop/cop/style/empty_method.rb +5 -5
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +10 -7
- data/lib/rubocop/cop/style/format_string_token.rb +2 -0
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +99 -11
- data/lib/rubocop/cop/style/guard_clause.rb +3 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +87 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_keys.rb +79 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +79 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +45 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
- data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
- data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +169 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +6 -2
- data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
- data/lib/rubocop/cop/style/next.rb +5 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
- data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
- data/lib/rubocop/cop/style/option_hash.rb +3 -3
- data/lib/rubocop/cop/style/or_assignment.rb +3 -2
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
- data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
- data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +27 -29
- data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
- data/lib/rubocop/cop/style/safe_navigation.rb +13 -10
- data/lib/rubocop/cop/style/semicolon.rb +2 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
- data/lib/rubocop/cop/style/symbol_array.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +0 -22
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
- data/lib/rubocop/cop/team.rb +5 -0
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +10 -18
- data/lib/rubocop/cop/variable_force.rb +11 -6
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/formatter/junit_formatter.rb +63 -0
- data/lib/rubocop/formatter/tap_formatter.rb +1 -3
- data/lib/rubocop/node_pattern.rb +100 -12
- data/lib/rubocop/options.rb +17 -11
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/rake_task.rb +1 -0
- data/lib/rubocop/result_cache.rb +24 -8
- data/lib/rubocop/rspec/shared_contexts.rb +5 -0
- data/lib/rubocop/runner.rb +50 -29
- data/lib/rubocop/target_finder.rb +12 -6
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +69 -35
- data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
@@ -54,33 +54,42 @@ module RuboCop
|
|
54
54
|
MULTI_RETURN_MSG = 'To return multiple values, use an array.'
|
55
55
|
|
56
56
|
def on_def(node)
|
57
|
-
return unless node.body
|
58
|
-
|
59
57
|
check_branch(node.body)
|
60
58
|
end
|
61
59
|
alias on_defs on_def
|
62
60
|
|
63
|
-
def autocorrect(node)
|
61
|
+
def autocorrect(node)
|
64
62
|
lambda do |corrector|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
return_value, = *node
|
71
|
-
if node.children.size > 1
|
72
|
-
add_brackets(corrector, node)
|
73
|
-
elsif return_value.hash_type?
|
74
|
-
add_braces(corrector, return_value) unless return_value.braces?
|
63
|
+
if node.arguments?
|
64
|
+
correct_with_arguments(node, corrector)
|
65
|
+
else
|
66
|
+
correct_without_arguments(node, corrector)
|
75
67
|
end
|
76
|
-
return_kw = range_with_surrounding_space(range: node.loc.keyword,
|
77
|
-
side: :right)
|
78
|
-
corrector.remove(return_kw)
|
79
68
|
end
|
80
69
|
end
|
81
70
|
|
82
71
|
private
|
83
72
|
|
73
|
+
def correct_without_arguments(return_node, corrector)
|
74
|
+
corrector.replace(return_node.source_range, 'nil')
|
75
|
+
end
|
76
|
+
|
77
|
+
def correct_with_arguments(return_node, corrector)
|
78
|
+
if return_node.arguments.size > 1
|
79
|
+
add_brackets(corrector, return_node)
|
80
|
+
elsif hash_without_braces?(return_node.first_argument)
|
81
|
+
add_braces(corrector, return_node.first_argument)
|
82
|
+
end
|
83
|
+
|
84
|
+
keyword = range_with_surrounding_space(range: return_node.loc.keyword,
|
85
|
+
side: :right)
|
86
|
+
corrector.remove(keyword)
|
87
|
+
end
|
88
|
+
|
89
|
+
def hash_without_braces?(node)
|
90
|
+
node.hash_type? && !node.braces?
|
91
|
+
end
|
92
|
+
|
84
93
|
def add_brackets(corrector, node)
|
85
94
|
kids = node.children.map(&:source_range)
|
86
95
|
corrector.insert_before(kids.first, '[')
|
@@ -93,13 +102,6 @@ module RuboCop
|
|
93
102
|
corrector.insert_after(kids.last, '}')
|
94
103
|
end
|
95
104
|
|
96
|
-
def arguments?(args)
|
97
|
-
return false if args.empty?
|
98
|
-
return true if args.size > 1
|
99
|
-
|
100
|
-
!args.first.begin_type? || !args.first.children.empty?
|
101
|
-
end
|
102
|
-
|
103
105
|
# rubocop:disable Metrics/CyclomaticComplexity
|
104
106
|
def check_branch(node)
|
105
107
|
return unless node
|
@@ -148,12 +150,8 @@ module RuboCop
|
|
148
150
|
end
|
149
151
|
|
150
152
|
def check_begin_node(node)
|
151
|
-
|
152
|
-
last_expr
|
153
|
-
|
154
|
-
return unless last_expr&.return_type?
|
155
|
-
|
156
|
-
check_return_node(last_expr)
|
153
|
+
last_expr = node.children.last
|
154
|
+
check_branch(last_expr)
|
157
155
|
end
|
158
156
|
|
159
157
|
def allow_multiple_return_values?
|
@@ -49,13 +49,13 @@ module RuboCop
|
|
49
49
|
# # good
|
50
50
|
# arr.max_by(&:foo)
|
51
51
|
#
|
52
|
-
class
|
52
|
+
class RedundantSort < Cop
|
53
53
|
include RangeHelp
|
54
54
|
|
55
55
|
MSG = 'Use `%<suggestion>s` instead of '\
|
56
56
|
'`%<sorter>s...%<accessor_source>s`.'
|
57
57
|
|
58
|
-
def_node_matcher :
|
58
|
+
def_node_matcher :redundant_sort?, <<~MATCHER
|
59
59
|
{
|
60
60
|
(send $(send _ $:sort ...) ${:last :first})
|
61
61
|
(send $(send _ $:sort ...) ${:[] :at :slice} {(int 0) (int -1)})
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
72
72
|
MATCHER
|
73
73
|
|
74
74
|
def on_send(node)
|
75
|
-
|
75
|
+
redundant_sort?(node) do |sort_node, sorter, accessor|
|
76
76
|
range = range_between(
|
77
77
|
sort_node.loc.selector.begin_pos,
|
78
78
|
node.loc.expression.end_pos
|
@@ -87,7 +87,7 @@ module RuboCop
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def autocorrect(node)
|
90
|
-
sort_node, sorter, accessor =
|
90
|
+
sort_node, sorter, accessor = redundant_sort?(node)
|
91
91
|
|
92
92
|
lambda do |corrector|
|
93
93
|
# Remove accessor, e.g. `first` or `[-1]`.
|
@@ -127,7 +127,7 @@ module RuboCop
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def base(accessor, arg)
|
130
|
-
if accessor == :first ||
|
130
|
+
if accessor == :first || arg&.zero?
|
131
131
|
'min'
|
132
132
|
elsif accessor == :last || arg == -1
|
133
133
|
'max'
|
@@ -112,9 +112,8 @@ module RuboCop
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def autocorrect(node)
|
115
|
-
|
116
|
-
|
117
|
-
method_call, = matching_receiver.parent
|
115
|
+
body = node.node_parts[1]
|
116
|
+
method_call = method_call(node)
|
118
117
|
|
119
118
|
lambda do |corrector|
|
120
119
|
corrector.remove(begin_range(node, body))
|
@@ -129,25 +128,29 @@ module RuboCop
|
|
129
128
|
private
|
130
129
|
|
131
130
|
def handle_comments(corrector, node, method_call)
|
132
|
-
|
131
|
+
comments = comments(node)
|
132
|
+
return if comments.empty?
|
133
133
|
|
134
134
|
corrector.insert_before(method_call.loc.expression,
|
135
|
-
"#{comments(
|
135
|
+
"#{comments.map(&:text).join("\n")}\n")
|
136
136
|
end
|
137
137
|
|
138
138
|
def comments(node)
|
139
|
-
|
140
|
-
comment.loc.first_line
|
141
|
-
comment.loc.last_line
|
139
|
+
processed_source.comments.select do |comment|
|
140
|
+
comment.loc.first_line > node.loc.first_line &&
|
141
|
+
comment.loc.last_line < node.loc.last_line
|
142
142
|
end
|
143
|
-
|
144
|
-
comments.map(&:text)
|
145
143
|
end
|
146
144
|
|
147
145
|
def allowed_if_condition?(node)
|
148
146
|
node.else? || node.elsif? || node.ternary?
|
149
147
|
end
|
150
148
|
|
149
|
+
def method_call(node)
|
150
|
+
_checked_variable, matching_receiver, = extract_parts(node)
|
151
|
+
matching_receiver.parent
|
152
|
+
end
|
153
|
+
|
151
154
|
def extract_parts(node)
|
152
155
|
case node.type
|
153
156
|
when :if
|
@@ -47,8 +47,8 @@ module RuboCop
|
|
47
47
|
return if exprs.size < 2
|
48
48
|
|
49
49
|
# create a map matching lines to the number of expressions on them
|
50
|
-
exprs_lines = exprs.map
|
51
|
-
lines = exprs_lines.group_by
|
50
|
+
exprs_lines = exprs.map(&:first_line)
|
51
|
+
lines = exprs_lines.group_by(&:itself)
|
52
52
|
|
53
53
|
lines.each do |line, expr_on_line|
|
54
54
|
# Every line with more than one expression on it is a
|
@@ -160,17 +160,15 @@ module RuboCop
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def format_message(english, regular, global)
|
163
|
-
if
|
163
|
+
if regular.empty?
|
164
|
+
format(MSG_ENGLISH, prefer: format_list(english), global: global)
|
165
|
+
elsif english.empty?
|
166
|
+
format(MSG_REGULAR, prefer: format_list(regular), global: global)
|
167
|
+
else
|
164
168
|
format(MSG_BOTH,
|
165
169
|
prefer: format_list(english),
|
166
170
|
regular: format_list(regular),
|
167
171
|
global: global)
|
168
|
-
elsif !regular.empty?
|
169
|
-
format(MSG_REGULAR, prefer: format_list(regular), global: global)
|
170
|
-
elsif !english.empty?
|
171
|
-
format(MSG_ENGLISH, prefer: format_list(english), global: global)
|
172
|
-
else
|
173
|
-
raise 'Bug in SpecialGlobalVars - global var w/o preferred vars!'
|
174
172
|
end
|
175
173
|
end
|
176
174
|
|
@@ -11,8 +11,8 @@ module RuboCop
|
|
11
11
|
#
|
12
12
|
# Configuration option: MinSize
|
13
13
|
# If set, arrays with fewer elements than this value will not trigger the
|
14
|
-
# cop. For example, a `MinSize of `3` will not enforce a style on an
|
15
|
-
# of 2 or fewer elements.
|
14
|
+
# cop. For example, a `MinSize` of `3` will not enforce a style on an
|
15
|
+
# array of 2 or fewer elements.
|
16
16
|
#
|
17
17
|
# @example EnforcedStyle: percent (default)
|
18
18
|
# # good
|
@@ -162,7 +162,7 @@ module RuboCop
|
|
162
162
|
# `RedundantParentheses` cop is enabled, it will cause an infinite loop
|
163
163
|
# as they compete to add and remove the parentheses respectively.
|
164
164
|
def infinite_loop?
|
165
|
-
require_parentheses? &&
|
165
|
+
(require_parentheses? || require_parentheses_when_complex?) &&
|
166
166
|
redundant_parentheses_enabled?
|
167
167
|
end
|
168
168
|
|
@@ -68,28 +68,6 @@ module RuboCop
|
|
68
68
|
def self.autocorrect_incompatible_with
|
69
69
|
[Layout::HeredocArgumentClosingParenthesis]
|
70
70
|
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def avoid_autocorrect?(args)
|
75
|
-
args.last.hash_type? && args.last.braces? &&
|
76
|
-
braces_will_be_removed?(args)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Returns true if running with --auto-correct would remove the braces
|
80
|
-
# of the last argument.
|
81
|
-
def braces_will_be_removed?(args)
|
82
|
-
brace_config = config.for_cop('Style/BracesAroundHashParameters')
|
83
|
-
return false unless brace_config.fetch('Enabled')
|
84
|
-
return false if brace_config['AutoCorrect'] == false
|
85
|
-
|
86
|
-
brace_style = brace_config['EnforcedStyle']
|
87
|
-
return true if brace_style == 'no_braces'
|
88
|
-
|
89
|
-
return false unless brace_style == 'context_dependent'
|
90
|
-
|
91
|
-
args.one? || !args[-2].hash_type?
|
92
|
-
end
|
93
71
|
end
|
94
72
|
end
|
95
73
|
end
|
@@ -20,8 +20,14 @@ module RuboCop
|
|
20
20
|
# a, *b, _ = foo()
|
21
21
|
# # => The correction `a, *b, = foo()` is a syntax error
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# @example AllowNamedUnderscoreVariables: true (default)
|
24
|
+
# # good
|
24
25
|
# a, b, _something = foo()
|
26
|
+
#
|
27
|
+
# @example AllowNamedUnderscoreVariables: false
|
28
|
+
# # bad
|
29
|
+
# a, b, _something = foo()
|
30
|
+
#
|
25
31
|
class TrailingUnderscoreVariable < Cop
|
26
32
|
include SurroundingSpace
|
27
33
|
include RangeHelp
|
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
when :module
|
61
61
|
return true
|
62
62
|
else
|
63
|
-
return true if pnode.
|
63
|
+
return true if pnode.method?(:instance_eval)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
false
|
@@ -95,9 +95,9 @@ module RuboCop
|
|
95
95
|
cop_config['IgnoreClassMethods']
|
96
96
|
end
|
97
97
|
|
98
|
-
def
|
99
|
-
|
100
|
-
Array(
|
98
|
+
def allowed_methods
|
99
|
+
allowed_methods = cop_config['AllowedMethods']
|
100
|
+
Array(allowed_methods).map(&:to_sym) + [:initialize]
|
101
101
|
end
|
102
102
|
|
103
103
|
def dsl_writer?(method_name)
|
@@ -124,7 +124,7 @@ module RuboCop
|
|
124
124
|
PATTERN
|
125
125
|
|
126
126
|
def allowed_method?(node)
|
127
|
-
|
127
|
+
allowed_methods.include?(node.method_name) ||
|
128
128
|
exact_name_match? && !names_match?(node)
|
129
129
|
end
|
130
130
|
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# Checks for while and until statements that would fit on one line
|
7
7
|
# if written as a modifier while/until. The maximum line length is
|
8
|
-
# configured in the `
|
8
|
+
# configured in the `Layout/LineLength` cop.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
# # bad
|
@@ -67,9 +67,16 @@ module RuboCop
|
|
67
67
|
|
68
68
|
NONCOMMUTATIVE_OPERATORS = %i[===].freeze
|
69
69
|
|
70
|
+
PROGRAM_NAMES = %i[$0 $PROGRAM_NAME].freeze
|
71
|
+
|
72
|
+
def_node_matcher :file_constant_equal_program_name?, <<~PATTERN
|
73
|
+
(send #source_file_path_constant? {:== :!=} (gvar #program_name?))
|
74
|
+
PATTERN
|
75
|
+
|
70
76
|
def on_send(node)
|
71
77
|
return unless yoda_compatible_condition?(node)
|
72
|
-
return if equality_only? && non_equality_operator?(node)
|
78
|
+
return if equality_only? && non_equality_operator?(node) ||
|
79
|
+
file_constant_equal_program_name?(node)
|
73
80
|
|
74
81
|
valid_yoda?(node) || add_offense(node)
|
75
82
|
end
|
@@ -135,6 +142,14 @@ module RuboCop
|
|
135
142
|
def noncommutative_operator?(node)
|
136
143
|
NONCOMMUTATIVE_OPERATORS.include?(node.method_name)
|
137
144
|
end
|
145
|
+
|
146
|
+
def source_file_path_constant?(node)
|
147
|
+
node.source == '__FILE__'
|
148
|
+
end
|
149
|
+
|
150
|
+
def program_name?(name)
|
151
|
+
PROGRAM_NAMES.include?(name)
|
152
|
+
end
|
138
153
|
end
|
139
154
|
end
|
140
155
|
end
|
data/lib/rubocop/cop/team.rb
CHANGED
data/lib/rubocop/cop/util.rb
CHANGED
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# Match literal regex characters, not including anchors, character
|
10
10
|
# classes, alternatives, groups, repetitions, references, etc
|
11
11
|
LITERAL_REGEX =
|
12
|
-
|
12
|
+
%r{[\w\s\-,"'!#%&<>=;:`~/]|\\[^AbBdDgGhHkpPRwWXsSzZ0-9]}.freeze
|
13
13
|
|
14
14
|
module_function
|
15
15
|
|
@@ -44,15 +44,15 @@ module RuboCop
|
|
44
44
|
attr_reader :begin_pos, :end_pos
|
45
45
|
attr_reader :flags, :width, :precision, :name, :type
|
46
46
|
|
47
|
-
def initialize(
|
48
|
-
@source =
|
49
|
-
@begin_pos =
|
50
|
-
@end_pos =
|
51
|
-
@flags =
|
52
|
-
@width =
|
53
|
-
@precision =
|
54
|
-
@name =
|
55
|
-
@type =
|
47
|
+
def initialize(match)
|
48
|
+
@source = match[0]
|
49
|
+
@begin_pos = match.begin(0)
|
50
|
+
@end_pos = match.end(0)
|
51
|
+
@flags = match[:flags].to_s + match[:more_flags].to_s
|
52
|
+
@width = match[:width]
|
53
|
+
@precision = match[:precision]
|
54
|
+
@name = match[:name]
|
55
|
+
@type = match[:type]
|
56
56
|
end
|
57
57
|
|
58
58
|
def percent?
|
@@ -109,16 +109,8 @@ module RuboCop
|
|
109
109
|
|
110
110
|
def parse
|
111
111
|
@source.to_enum(:scan, SEQUENCE).map do
|
112
|
-
match = Regexp.last_match
|
113
112
|
FormatSequence.new(
|
114
|
-
|
115
|
-
begin_pos: match.begin(0),
|
116
|
-
end_pos: match.end(0),
|
117
|
-
flags: match[:flags].to_s + match[:more_flags].to_s,
|
118
|
-
width: match[:width],
|
119
|
-
precision: match[:precision],
|
120
|
-
name: match[:name],
|
121
|
-
type: match[:type]
|
113
|
+
Regexp.last_match
|
122
114
|
)
|
123
115
|
end
|
124
116
|
end
|
@@ -190,7 +190,10 @@ module RuboCop
|
|
190
190
|
end
|
191
191
|
|
192
192
|
def regexp_captured_names(node)
|
193
|
-
regexp_string = node.children
|
193
|
+
regexp_string = node.children.select(&:str_type?).map do |child|
|
194
|
+
child.children.first
|
195
|
+
end.join || ''
|
196
|
+
|
194
197
|
regexp = Regexp.new(regexp_string)
|
195
198
|
|
196
199
|
regexp.named_captures.keys
|
@@ -284,11 +287,7 @@ module RuboCop
|
|
284
287
|
def process_scope(node)
|
285
288
|
if TWISTED_SCOPE_TYPES.include?(node.type)
|
286
289
|
# See the comment at the end of file for this behavior.
|
287
|
-
twisted_nodes
|
288
|
-
twisted_nodes << node.children[1] if node.class_type?
|
289
|
-
twisted_nodes.compact!
|
290
|
-
|
291
|
-
twisted_nodes.each do |twisted_node|
|
290
|
+
twisted_nodes(node).each do |twisted_node|
|
292
291
|
process_node(twisted_node)
|
293
292
|
scanned_nodes << twisted_node
|
294
293
|
end
|
@@ -298,6 +297,12 @@ module RuboCop
|
|
298
297
|
skip_children!
|
299
298
|
end
|
300
299
|
|
300
|
+
def twisted_nodes(node)
|
301
|
+
twisted_nodes = [node.children[0]]
|
302
|
+
twisted_nodes << node.children[1] if node.class_type?
|
303
|
+
twisted_nodes.compact
|
304
|
+
end
|
305
|
+
|
301
306
|
def process_send(node)
|
302
307
|
_receiver, method_name, args = *node
|
303
308
|
return unless method_name == :binding
|