rubocop 0.76.0 → 0.80.1
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 +325 -283
- data/lib/rubocop.rb +43 -23
- data/lib/rubocop/ast/builder.rb +43 -42
- data/lib/rubocop/ast/node.rb +1 -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/traversal.rb +20 -3
- data/lib/rubocop/cli.rb +11 -230
- 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 +6 -1
- data/lib/rubocop/config.rb +28 -10
- data/lib/rubocop/config_loader.rb +19 -19
- data/lib/rubocop/config_obsoletion.rb +65 -11
- data/lib/rubocop/config_validator.rb +56 -98
- 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/cop.rb +21 -0
- 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 +1 -1
- 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/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +5 -5
- 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} +3 -3
- 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} +10 -6
- 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 +67 -108
- 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/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_inside_hash_literal_braces.rb +2 -9
- data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
- 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/ineffective_access_modifier.rb +1 -1
- 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/redundant_cop_disable_directive.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +13 -8
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- 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/{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/metrics/method_length.rb +1 -1
- 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 +171 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- 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 +2 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -12
- data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
- 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 +7 -2
- 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 +8 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- 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/frozen_string_literal_comment.rb +89 -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_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 +38 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +8 -4
- data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
- 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/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 +5 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +7 -7
- data/lib/rubocop/cop/style/next.rb +5 -5
- 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/redundant_condition.rb +17 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/redundant_return.rb +2 -8
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -1
- 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/variable_force.rb +4 -1
- 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 +97 -11
- data/lib/rubocop/options.rb +8 -8
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/rake_task.rb +1 -0
- data/lib/rubocop/result_cache.rb +23 -7
- data/lib/rubocop/rspec/shared_contexts.rb +5 -0
- data/lib/rubocop/runner.rb +18 -2
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +60 -27
- data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
# Common functionality for Rails safe mode.
|
6
|
-
#
|
7
|
-
# This module can be removed from RuboCop 0.76.
|
8
|
-
module SafeMode
|
9
|
-
private
|
10
|
-
|
11
|
-
def rails_safe_mode?
|
12
|
-
safe_mode? || rails?
|
13
|
-
end
|
14
|
-
|
15
|
-
def safe_mode?
|
16
|
-
cop_config['SafeMode']
|
17
|
-
end
|
18
|
-
|
19
|
-
def rails?
|
20
|
-
config['Rails']&.fetch('Enabled')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,209 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module Style
|
6
|
-
# This cop checks for braces around the last parameter in a method call
|
7
|
-
# if the last parameter is a hash.
|
8
|
-
# It supports `braces`, `no_braces` and `context_dependent` styles.
|
9
|
-
#
|
10
|
-
# @example EnforcedStyle: braces
|
11
|
-
# # The `braces` style enforces braces around all method
|
12
|
-
# # parameters that are hashes.
|
13
|
-
#
|
14
|
-
# # bad
|
15
|
-
# some_method(x, y, a: 1, b: 2)
|
16
|
-
#
|
17
|
-
# # good
|
18
|
-
# some_method(x, y, {a: 1, b: 2})
|
19
|
-
#
|
20
|
-
# @example EnforcedStyle: no_braces (default)
|
21
|
-
# # The `no_braces` style checks that the last parameter doesn't
|
22
|
-
# # have braces around it.
|
23
|
-
#
|
24
|
-
# # bad
|
25
|
-
# some_method(x, y, {a: 1, b: 2})
|
26
|
-
#
|
27
|
-
# # good
|
28
|
-
# some_method(x, y, a: 1, b: 2)
|
29
|
-
#
|
30
|
-
# @example EnforcedStyle: context_dependent
|
31
|
-
# # The `context_dependent` style checks that the last parameter
|
32
|
-
# # doesn't have braces around it, but requires braces if the
|
33
|
-
# # second to last parameter is also a hash literal.
|
34
|
-
#
|
35
|
-
# # bad
|
36
|
-
# some_method(x, y, {a: 1, b: 2})
|
37
|
-
# some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
|
38
|
-
#
|
39
|
-
# # good
|
40
|
-
# some_method(x, y, a: 1, b: 2)
|
41
|
-
# some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
|
42
|
-
class BracesAroundHashParameters < Cop
|
43
|
-
include ConfigurableEnforcedStyle
|
44
|
-
include RangeHelp
|
45
|
-
|
46
|
-
MSG = '%<type>s curly braces around a hash parameter.'
|
47
|
-
|
48
|
-
def on_send(node)
|
49
|
-
return if node.assignment_method? || node.operator_method?
|
50
|
-
|
51
|
-
return unless node.arguments? && node.last_argument.hash_type? &&
|
52
|
-
!node.last_argument.empty?
|
53
|
-
|
54
|
-
check(node.last_argument, node.arguments)
|
55
|
-
end
|
56
|
-
alias on_csend on_send
|
57
|
-
|
58
|
-
def autocorrect(send_node)
|
59
|
-
hash_node = send_node.last_argument
|
60
|
-
|
61
|
-
lambda do |corrector|
|
62
|
-
if hash_node.braces?
|
63
|
-
remove_braces_with_whitespace(corrector,
|
64
|
-
hash_node,
|
65
|
-
extra_space(hash_node))
|
66
|
-
else
|
67
|
-
add_braces(corrector, hash_node)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def check(arg, args)
|
75
|
-
case style
|
76
|
-
when :braces
|
77
|
-
check_braces(arg)
|
78
|
-
when :no_braces
|
79
|
-
check_no_braces(arg)
|
80
|
-
when :context_dependent
|
81
|
-
check_context_dependent(arg, args)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def check_braces(arg)
|
86
|
-
add_arg_offense(arg, :missing) unless arg.braces?
|
87
|
-
end
|
88
|
-
|
89
|
-
def check_no_braces(arg)
|
90
|
-
return unless arg.braces? && !braces_needed_for_semantics?(arg)
|
91
|
-
|
92
|
-
add_arg_offense(arg, :redundant)
|
93
|
-
end
|
94
|
-
|
95
|
-
def check_context_dependent(arg, args)
|
96
|
-
braces_around_second_from_end = args.size > 1 && args[-2].hash_type?
|
97
|
-
|
98
|
-
if arg.braces?
|
99
|
-
unless braces_around_second_from_end ||
|
100
|
-
braces_needed_for_semantics?(arg)
|
101
|
-
add_arg_offense(arg, :redundant)
|
102
|
-
end
|
103
|
-
elsif braces_around_second_from_end
|
104
|
-
add_arg_offense(arg, :missing)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Returns true if there's block inside the braces of the given hash arg
|
109
|
-
# and that block uses do..end. The reason for wanting to check this is
|
110
|
-
# that the do..end could bind to a different method invocation if the
|
111
|
-
# hash braces were removed.
|
112
|
-
def braces_needed_for_semantics?(arg)
|
113
|
-
arg.each_pair do |_key, value|
|
114
|
-
return true if value.block_type? && !value.braces?
|
115
|
-
end
|
116
|
-
false
|
117
|
-
end
|
118
|
-
|
119
|
-
def add_arg_offense(arg, type)
|
120
|
-
add_offense(arg.parent, location: arg.source_range,
|
121
|
-
message: format(MSG,
|
122
|
-
type: type.to_s.capitalize))
|
123
|
-
end
|
124
|
-
|
125
|
-
def extra_space(hash_node)
|
126
|
-
{
|
127
|
-
newlines: extra_left_space?(hash_node) &&
|
128
|
-
extra_right_space?(hash_node),
|
129
|
-
left: extra_left_space?(hash_node),
|
130
|
-
right: extra_right_space?(hash_node)
|
131
|
-
}
|
132
|
-
end
|
133
|
-
|
134
|
-
def extra_left_space?(hash_node)
|
135
|
-
@extra_left_space ||= begin
|
136
|
-
top_line = hash_node.source_range.source_line
|
137
|
-
top_line.delete(' ') == '{'
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def extra_right_space?(hash_node)
|
142
|
-
@extra_right_space ||= begin
|
143
|
-
bottom_line_number = hash_node.source_range.last_line
|
144
|
-
bottom_line = processed_source.lines[bottom_line_number - 1]
|
145
|
-
bottom_line.delete(' ') == '}'
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def remove_braces_with_whitespace(corrector, node, space)
|
150
|
-
loc = node.loc
|
151
|
-
|
152
|
-
if node.multiline?
|
153
|
-
remove_braces_with_range(corrector,
|
154
|
-
left_whole_line_range(loc.begin),
|
155
|
-
right_whole_line_range(loc.end))
|
156
|
-
else
|
157
|
-
remove_braces_with_range(corrector,
|
158
|
-
left_brace_and_space(loc.begin, space),
|
159
|
-
right_brace_and_space(loc.end, space))
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def remove_braces_with_range(corrector, left_range, right_range)
|
164
|
-
corrector.remove(left_range)
|
165
|
-
corrector.remove(right_range)
|
166
|
-
end
|
167
|
-
|
168
|
-
def left_whole_line_range(loc_begin)
|
169
|
-
if range_by_whole_lines(loc_begin).source.strip == '{'
|
170
|
-
range_by_whole_lines(loc_begin, include_final_newline: true)
|
171
|
-
else
|
172
|
-
loc_begin
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def right_whole_line_range(loc_end)
|
177
|
-
if range_by_whole_lines(loc_end).source.strip =~ /\A}\s*,?\z/
|
178
|
-
range_by_whole_lines(loc_end, include_final_newline: true)
|
179
|
-
else
|
180
|
-
loc_end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def left_brace_and_space(loc_begin, space)
|
185
|
-
range_with_surrounding_space(range: loc_begin,
|
186
|
-
side: :right,
|
187
|
-
newlines: space[:newlines],
|
188
|
-
whitespace: space[:left])
|
189
|
-
end
|
190
|
-
|
191
|
-
def right_brace_and_space(loc_end, space)
|
192
|
-
brace_and_space =
|
193
|
-
range_with_surrounding_space(
|
194
|
-
range: loc_end,
|
195
|
-
side: :left,
|
196
|
-
newlines: space[:newlines],
|
197
|
-
whitespace: space[:right]
|
198
|
-
)
|
199
|
-
range_with_surrounding_comma(brace_and_space, :left)
|
200
|
-
end
|
201
|
-
|
202
|
-
def add_braces(corrector, node)
|
203
|
-
corrector.insert_before(node.source_range, '{')
|
204
|
-
corrector.insert_after(node.source_range, '}')
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|