rubocop 0.76.0 → 0.77.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 +2 -2
- data/config/default.yml +252 -239
- data/lib/rubocop.rb +27 -20
- data/lib/rubocop/ast/node.rb +1 -1
- data/lib/rubocop/ast/node/block_node.rb +2 -0
- 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 +73 -0
- data/lib/rubocop/cli/command/version.rb +17 -0
- data/lib/rubocop/cli/environment.rb +21 -0
- data/lib/rubocop/config_obsoletion.rb +62 -9
- data/lib/rubocop/config_validator.rb +1 -3
- data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
- data/lib/rubocop/cop/cop.rb +19 -0
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -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/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +3 -3
- 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} +2 -2
- data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +1 -1
- data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
- 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 +1 -1
- data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.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/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
- 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 +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +41 -38
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
- 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/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +3 -3
- data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- 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/ip_addresses.rb +4 -4
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- 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/numeric_literals.rb +7 -3
- data/lib/rubocop/cop/style/option_hash.rb +3 -3
- 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/trivial_accessors.rb +5 -5
- data/lib/rubocop/cop/team.rb +5 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
- data/lib/rubocop/formatter/tap_formatter.rb +1 -3
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/rake_task.rb +1 -0
- data/lib/rubocop/result_cache.rb +21 -7
- data/lib/rubocop/runner.rb +13 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +30 -22
- data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
@@ -127,9 +127,7 @@ module RuboCop
|
|
127
127
|
valid_cop_names.each do |name|
|
128
128
|
validate_section_presence(name)
|
129
129
|
each_invalid_parameter(name) do |param, supported_params|
|
130
|
-
|
131
|
-
# https://github.com/jruby/jruby/issues/5935
|
132
|
-
warn Rainbow(<<~MESSAGE).yellow.to_s
|
130
|
+
warn Rainbow(<<~MESSAGE).yellow
|
133
131
|
Warning: #{name} does not support #{param} parameter.
|
134
132
|
|
135
133
|
Supported parameters are:
|
@@ -24,7 +24,7 @@ module RuboCop
|
|
24
24
|
|
25
25
|
def on_send(node)
|
26
26
|
return unless gem_declaration?(node)
|
27
|
-
return if
|
27
|
+
return if ignored_gem?(node)
|
28
28
|
return if commented?(node)
|
29
29
|
|
30
30
|
add_offense(node)
|
@@ -54,9 +54,9 @@ module RuboCop
|
|
54
54
|
comment_line?(node2.loc.expression.source)
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
57
|
+
def ignored_gem?(node)
|
58
|
+
ignored_gems = Array(cop_config['IgnoredGems'])
|
59
|
+
ignored_gems.include?(node.first_argument.value)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -217,6 +217,25 @@ module RuboCop
|
|
217
217
|
!relevant_file?(file)
|
218
218
|
end
|
219
219
|
|
220
|
+
# This method should be overriden when a cop's behavior depends
|
221
|
+
# on state that lives outside of these locations:
|
222
|
+
#
|
223
|
+
# (1) the file under inspection
|
224
|
+
# (2) the cop's source code
|
225
|
+
# (3) the config (eg a .rubocop.yml file)
|
226
|
+
#
|
227
|
+
# For example, some cops may want to look at other parts of
|
228
|
+
# the codebase being inspected to find violations. A cop may
|
229
|
+
# use the presence or absence of file `foo.rb` to determine
|
230
|
+
# whether a certain violation exists in `bar.rb`.
|
231
|
+
#
|
232
|
+
# Overriding this method allows the cop to indicate to RuboCop's
|
233
|
+
# ResultCache system when those external dependencies change,
|
234
|
+
# ie when the ResultCache should be invalidated.
|
235
|
+
def external_dependency_checksum
|
236
|
+
nil
|
237
|
+
end
|
238
|
+
|
220
239
|
private
|
221
240
|
|
222
241
|
def find_message(node, message)
|
@@ -12,12 +12,11 @@ module RuboCop
|
|
12
12
|
def empty_corrections(processed_source, corrector, empty_config,
|
13
13
|
left_token, right_token)
|
14
14
|
@processed_source = processed_source
|
15
|
+
range = range_between(left_token.end_pos, right_token.begin_pos)
|
15
16
|
if offending_empty_space?(empty_config, left_token, right_token)
|
16
|
-
range = side_space_range(range: left_token.pos, side: :right)
|
17
17
|
corrector.remove(range)
|
18
18
|
corrector.insert_after(left_token.pos, ' ')
|
19
19
|
elsif offending_empty_no_space?(empty_config, left_token, right_token)
|
20
|
-
range = side_space_range(range: left_token.pos, side: :right)
|
21
20
|
corrector.remove(range)
|
22
21
|
end
|
23
22
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks that method names are checked using `method?` method.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# node.method_name == :do_something
|
11
|
+
#
|
12
|
+
# # good
|
13
|
+
# node.method?(:do_something)
|
14
|
+
#
|
15
|
+
class MethodNameEqual < Cop
|
16
|
+
include RangeHelp
|
17
|
+
|
18
|
+
MSG = 'Use `method?(%<method_name>s)` instead of ' \
|
19
|
+
'`method_name == %<method_name>s`.'
|
20
|
+
|
21
|
+
def_node_matcher :method_name?, <<~PATTERN
|
22
|
+
(send
|
23
|
+
$(send
|
24
|
+
(...) :method_name) :==
|
25
|
+
$...)
|
26
|
+
PATTERN
|
27
|
+
|
28
|
+
def on_send(node)
|
29
|
+
method_name?(node) do |method_name_node, method_name_arg|
|
30
|
+
message = format(MSG, method_name: method_name_arg.first.source)
|
31
|
+
|
32
|
+
range = range(method_name_node, node)
|
33
|
+
|
34
|
+
add_offense(node, location: range, message: message)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def autocorrect(node)
|
39
|
+
lambda do |corrector|
|
40
|
+
method_name?(node) do |method_name_node, method_name_arg|
|
41
|
+
corrector.replace(
|
42
|
+
range(method_name_node, node),
|
43
|
+
"method?(#{method_name_arg.first.source})"
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def range(method_name_node, node)
|
52
|
+
range_between(
|
53
|
+
method_name_node.loc.selector.begin_pos, node.source_range.end_pos
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
#
|
22
22
|
# The indentation of the remaining lines can be corrected with
|
23
23
|
# other cops such as `IndentationConsistency` and `EndAlignment`.
|
24
|
-
class
|
24
|
+
class AssignmentIndentation < Cop
|
25
25
|
include CheckAssignment
|
26
26
|
include Alignment
|
27
27
|
|
@@ -114,7 +114,7 @@ module RuboCop
|
|
114
114
|
|
115
115
|
# Returns an array of ranges that should not be reported. It's the
|
116
116
|
# extra spaces between the keys and values in a multiline hash,
|
117
|
-
# since those are handled by the
|
117
|
+
# since those are handled by the Layout/HashAlignment cop.
|
118
118
|
def ignored_ranges(ast)
|
119
119
|
return [] unless ast
|
120
120
|
|
@@ -5,11 +5,11 @@ module RuboCop
|
|
5
5
|
# rubocop:disable Metrics/LineLength
|
6
6
|
module Layout
|
7
7
|
# This cop checks the indentation of the first argument in a method call.
|
8
|
-
# Arguments after the first one are checked by Layout/
|
8
|
+
# Arguments after the first one are checked by Layout/ArgumentAlignment,
|
9
9
|
# not by this cop.
|
10
10
|
#
|
11
11
|
# For indenting the first parameter of method *definitions*, check out
|
12
|
-
# Layout/
|
12
|
+
# Layout/FirstParameterIndentation.
|
13
13
|
#
|
14
14
|
# @example
|
15
15
|
#
|
@@ -142,7 +142,7 @@ module RuboCop
|
|
142
142
|
# nested_first_param),
|
143
143
|
# second_param
|
144
144
|
#
|
145
|
-
class
|
145
|
+
class FirstArgumentIndentation < Cop
|
146
146
|
# rubocop:enable Metrics/LineLength
|
147
147
|
include Alignment
|
148
148
|
include ConfigurableEnforcedStyle
|
data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb}
RENAMED
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop checks the indentation of the first element in an array literal
|
7
7
|
# where the opening bracket and the first element are on separate lines.
|
8
|
-
# The other elements' indentations are handled by the
|
8
|
+
# The other elements' indentations are handled by the ArrayAlignment cop.
|
9
9
|
#
|
10
10
|
# By default, array literals that are arguments in a method call with
|
11
11
|
# parentheses, and where the opening square bracket of the array is on the
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
# @example EnforcedStyle: special_inside_parentheses (default)
|
23
23
|
# # The `special_inside_parentheses` style enforces that the first
|
24
24
|
# # element in an array literal where the opening bracket and first
|
25
|
-
# # element are on
|
25
|
+
# # element are on separate lines is indented one step (two spaces) more
|
26
26
|
# # than the position inside the opening parenthesis.
|
27
27
|
#
|
28
28
|
# #bad
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
# @example EnforcedStyle: consistent
|
45
45
|
# # The `consistent` style enforces that the first element in an array
|
46
46
|
# # literal where the opening bracket and the first element are on
|
47
|
-
# #
|
47
|
+
# # separate lines is indented the same as an array literal which is not
|
48
48
|
# # defined inside a method call.
|
49
49
|
#
|
50
50
|
# #bad
|
@@ -79,7 +79,7 @@ module RuboCop
|
|
79
79
|
# and_now_for_something = [
|
80
80
|
# :completely_different
|
81
81
|
# ]
|
82
|
-
class
|
82
|
+
class FirstArrayElementIndentation < Cop
|
83
83
|
include Alignment
|
84
84
|
include ConfigurableEnforcedStyle
|
85
85
|
include MultilineElementIndentation
|
data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb}
RENAMED
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop checks the indentation of the first key in a hash literal
|
7
7
|
# where the opening brace and the first key are on separate lines. The
|
8
|
-
# other keys' indentations are handled by the
|
8
|
+
# other keys' indentations are handled by the HashAlignment cop.
|
9
9
|
#
|
10
10
|
# By default, Hash literals that are arguments in a method call with
|
11
11
|
# parentheses, and where the opening curly brace of the hash is on the
|
@@ -77,7 +77,7 @@ module RuboCop
|
|
77
77
|
# and_now_for_something = {
|
78
78
|
# completely: :different
|
79
79
|
# }
|
80
|
-
class
|
80
|
+
class FirstHashElementIndentation < Cop
|
81
81
|
include Alignment
|
82
82
|
include ConfigurableEnforcedStyle
|
83
83
|
include MultilineElementIndentation
|
@@ -149,7 +149,7 @@ module RuboCop
|
|
149
149
|
def separator_style?(first_pair)
|
150
150
|
separator = first_pair.loc.operator
|
151
151
|
key = "Enforced#{separator.is?(':') ? 'Colon' : 'HashRocket'}Style"
|
152
|
-
config.for_cop('Layout/
|
152
|
+
config.for_cop('Layout/HashAlignment')[key] == 'separator'
|
153
153
|
end
|
154
154
|
|
155
155
|
def check_based_on_longest_key(hash_node, left_brace, left_parenthesis)
|
@@ -5,10 +5,10 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop checks the indentation of the first parameter in a method
|
7
7
|
# definition. Parameters after the first one are checked by
|
8
|
-
# Layout/
|
8
|
+
# Layout/ParameterAlignment, not by this cop.
|
9
9
|
#
|
10
10
|
# For indenting the first argument of method *calls*, check out
|
11
|
-
# Layout/
|
11
|
+
# Layout/FirstArgumentIndentation, which supports options related to
|
12
12
|
# nesting that are irrelevant for method *definitions*.
|
13
13
|
#
|
14
14
|
# @example
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
# second_param)
|
42
42
|
# 123
|
43
43
|
# end
|
44
|
-
class
|
44
|
+
class FirstParameterIndentation < Cop
|
45
45
|
include Alignment
|
46
46
|
include ConfigurableEnforcedStyle
|
47
47
|
include MultilineElementIndentation
|
@@ -175,8 +175,8 @@ module RuboCop
|
|
175
175
|
# do_something({foo: 1,
|
176
176
|
# bar: 2})
|
177
177
|
#
|
178
|
-
class
|
179
|
-
include
|
178
|
+
class HashAlignment < Cop
|
179
|
+
include HashAlignmentStyles
|
180
180
|
include RangeHelp
|
181
181
|
|
182
182
|
MSG = 'Align the elements of a hash literal if they span more than ' \
|
@@ -30,10 +30,12 @@ module RuboCop
|
|
30
30
|
|
31
31
|
DO = 'do'
|
32
32
|
SAFE_NAVIGATION = '&.'
|
33
|
+
NAMESPACE_OPERATOR = '::'
|
33
34
|
ACCEPT_LEFT_PAREN =
|
34
35
|
%w[break defined? next not rescue return super yield].freeze
|
35
36
|
ACCEPT_LEFT_SQUARE_BRACKET =
|
36
37
|
%w[super yield].freeze
|
38
|
+
ACCEPT_NAMESPACE_OPERATOR = 'super'
|
37
39
|
|
38
40
|
def on_and(node)
|
39
41
|
check(node, [:operator].freeze) if node.keyword?
|
@@ -193,6 +195,8 @@ module RuboCop
|
|
193
195
|
|
194
196
|
return false if accepted_opening_delimiter?(range, char)
|
195
197
|
return false if safe_navigation_call?(range, pos)
|
198
|
+
return false if accept_namespace_operator?(range) &&
|
199
|
+
namespace_operator?(range, pos)
|
196
200
|
|
197
201
|
char !~ /[\s;,#\\\)\}\]\.]/
|
198
202
|
end
|
@@ -212,10 +216,18 @@ module RuboCop
|
|
212
216
|
ACCEPT_LEFT_SQUARE_BRACKET.include?(range.source)
|
213
217
|
end
|
214
218
|
|
219
|
+
def accept_namespace_operator?(range)
|
220
|
+
ACCEPT_NAMESPACE_OPERATOR == range.source
|
221
|
+
end
|
222
|
+
|
215
223
|
def safe_navigation_call?(range, pos)
|
216
224
|
range.source_buffer.source[pos, 2].start_with?(SAFE_NAVIGATION)
|
217
225
|
end
|
218
226
|
|
227
|
+
def namespace_operator?(range, pos)
|
228
|
+
range.source_buffer.source[pos, 2].start_with?(NAMESPACE_OPERATOR)
|
229
|
+
end
|
230
|
+
|
219
231
|
def preceded_by_operator?(node, _range)
|
220
232
|
# regular dotted method calls bind more tightly than operators
|
221
233
|
# so we need to climb up the AST past them
|
@@ -117,7 +117,7 @@ module RuboCop
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def correct_visibility?(node, modifier, ignored_methods)
|
120
|
-
return true if modifier.nil? || modifier.
|
120
|
+
return true if modifier.nil? || modifier.method?(:public)
|
121
121
|
|
122
122
|
ignored_methods.include?(node.method_name)
|
123
123
|
end
|