rubocop 1.45.1 → 1.47.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/README.md +1 -1
- data/config/default.yml +10 -9
- data/lib/rubocop/cli/command/auto_generate_config.rb +7 -0
- data/lib/rubocop/comment_config.rb +19 -0
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/base.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +4 -4
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +42 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +39 -0
- data/lib/rubocop/cop/internal_affairs.rb +3 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +4 -4
- data/lib/rubocop/cop/layout/class_structure.rb +5 -3
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +4 -0
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +8 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -3
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +11 -7
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +3 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -3
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +4 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +46 -4
- data/lib/rubocop/cop/lint/missing_super.rb +31 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -9
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +6 -10
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +10 -4
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
- data/lib/rubocop/cop/lint/refinement_import_methods.rb +2 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +3 -3
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +1 -1
- data/lib/rubocop/cop/lint/script_permission.rb +1 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +6 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -9
- data/lib/rubocop/cop/lint/useless_rescue.rb +2 -1
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +2 -2
- data/lib/rubocop/cop/migration/department_name.rb +1 -1
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +2 -2
- data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +10 -7
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
- data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +0 -3
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -6
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +22 -12
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
- data/lib/rubocop/cop/style/array_intersect.rb +1 -1
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -2
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/collection_compact.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +10 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +6 -6
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/documentation_method.rb +4 -4
- data/lib/rubocop/cop/style/each_with_object.rb +1 -1
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +4 -4
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/file_read.rb +1 -1
- data/lib/rubocop/cop/style/file_write.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +1 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +34 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +2 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/min_max.rb +3 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -1
- data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +2 -2
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +5 -6
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +10 -3
- data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
- data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
- data/lib/rubocop/cop/style/require_order.rb +1 -3
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +3 -3
- data/lib/rubocop/cop/style/word_array.rb +17 -5
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
- data/lib/rubocop/cop/team.rb +11 -8
- data/lib/rubocop/cop/util.rb +13 -4
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/directive_comment.rb +3 -3
- data/lib/rubocop/ext/comment.rb +18 -0
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +2 -0
- metadata +10 -5
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# @safety
|
10
10
|
# This cop is unsafe because `x..-1` and `x..` are only guaranteed to
|
11
|
-
# be equivalent for `Array#[]`, and the cop cannot determine what class
|
11
|
+
# be equivalent for `Array#[]`, `String#[]`, and the cop cannot determine what class
|
12
12
|
# the receiver is.
|
13
13
|
#
|
14
14
|
# For example:
|
@@ -167,7 +167,7 @@ module RuboCop
|
|
167
167
|
corrector.insert_before(condition,
|
168
168
|
"#{'!' if node.unless?}#{replace_condition(node.condition)} && ")
|
169
169
|
|
170
|
-
corrector.remove(node.condition.
|
170
|
+
corrector.remove(node.condition.source_range)
|
171
171
|
corrector.remove(range_with_surrounding_space(node.loc.keyword, newlines: false))
|
172
172
|
corrector.replace(if_branch.loc.keyword, 'if')
|
173
173
|
end
|
@@ -240,7 +240,7 @@ module RuboCop
|
|
240
240
|
end
|
241
241
|
|
242
242
|
def outer_condition_modify_form?(node, if_branch)
|
243
|
-
node.condition.
|
243
|
+
node.condition.source_range.begin_pos > if_branch.condition.source_range.begin_pos
|
244
244
|
end
|
245
245
|
end
|
246
246
|
end
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
elsif (class_node = parent.parent).body.nil?
|
56
56
|
corrector.remove(range_for_empty_class_body(class_node, parent))
|
57
57
|
else
|
58
|
-
corrector.insert_after(parent.
|
58
|
+
corrector.insert_after(parent.source_range, ' do')
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -144,7 +144,7 @@ module RuboCop
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def range_for_parentheses(offense, left)
|
147
|
-
range_between(offense.source_range.begin_pos - 1, left.
|
147
|
+
range_between(offense.source_range.begin_pos - 1, left.source_range.end_pos - 1)
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
@@ -52,9 +52,9 @@ module RuboCop
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def first_element_range(node, unpack_call)
|
55
|
-
Parser::Source::Range.new(node.
|
56
|
-
unpack_call.
|
57
|
-
node.
|
55
|
+
Parser::Source::Range.new(node.source_range.source_buffer,
|
56
|
+
unpack_call.source_range.end_pos,
|
57
|
+
node.source_range.end_pos)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -82,10 +82,19 @@ module RuboCop
|
|
82
82
|
attr_accessor :largest_brackets
|
83
83
|
end
|
84
84
|
|
85
|
+
def on_new_investigation
|
86
|
+
super
|
87
|
+
|
88
|
+
# Prevent O(n2) checks (checking the entire matrix once for each child array) by caching
|
89
|
+
@matrix_of_complex_content_cache = Hash.new do |cache, node|
|
90
|
+
cache[node] = matrix_of_complex_content?(node)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
85
94
|
def on_array(node)
|
86
95
|
if bracketed_array_of?(:str, node)
|
87
96
|
return if complex_content?(node.values)
|
88
|
-
return if
|
97
|
+
return if within_matrix_of_complex_content?(node)
|
89
98
|
|
90
99
|
check_bracketed_array(node, 'w')
|
91
100
|
elsif node.percent_literal?(:string)
|
@@ -95,12 +104,15 @@ module RuboCop
|
|
95
104
|
|
96
105
|
private
|
97
106
|
|
98
|
-
def
|
107
|
+
def within_matrix_of_complex_content?(node)
|
99
108
|
return false unless (parent = node.parent)
|
100
109
|
|
101
|
-
parent.array_type? &&
|
102
|
-
|
103
|
-
|
110
|
+
parent.array_type? && @matrix_of_complex_content_cache[parent]
|
111
|
+
end
|
112
|
+
|
113
|
+
def matrix_of_complex_content?(array)
|
114
|
+
array.values.all?(&:array_type?) &&
|
115
|
+
array.values.any? { |subarray| complex_content?(subarray.values) }
|
104
116
|
end
|
105
117
|
|
106
118
|
def complex_content?(strings, complex_regex: word_regex)
|
@@ -145,7 +145,7 @@ module RuboCop
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def actual_code_range(node)
|
148
|
-
range_between(node.
|
148
|
+
range_between(node.source_range.begin_pos, node.source_range.end_pos)
|
149
149
|
end
|
150
150
|
|
151
151
|
def reverse_comparison(operator)
|
@@ -4,10 +4,13 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
# Checks for numeric comparisons that can be replaced
|
7
|
-
# by a predicate method, such as receiver.length == 0
|
8
|
-
# receiver.length > 0
|
9
|
-
# receiver.length < 1 and receiver.size == 0 that can be
|
10
|
-
# replaced by receiver.empty
|
7
|
+
# by a predicate method, such as `receiver.length == 0`,
|
8
|
+
# `receiver.length > 0`, and `receiver.length != 0`,
|
9
|
+
# `receiver.length < 1` and `receiver.size == 0` that can be
|
10
|
+
# replaced by `receiver.empty?` and `!receiver.empty?`.
|
11
|
+
#
|
12
|
+
# NOTE: `File`, `Tempfile`, and `StringIO` do not have `empty?`
|
13
|
+
# so allow `size == 0` and `size.zero?`.
|
11
14
|
#
|
12
15
|
# @safety
|
13
16
|
# This cop is unsafe because it cannot be guaranteed that the receiver
|
@@ -49,6 +52,7 @@ module RuboCop
|
|
49
52
|
|
50
53
|
def check_zero_length_predicate(node)
|
51
54
|
return unless (length_method = zero_length_predicate(node.parent))
|
55
|
+
return if non_polymorphic_collection?(node.parent)
|
52
56
|
|
53
57
|
offense = node.loc.selector.join(node.parent.source_range.end)
|
54
58
|
message = format(ZERO_MSG, current: "#{length_method}.zero?")
|
@@ -134,7 +138,7 @@ module RuboCop
|
|
134
138
|
# @!method non_polymorphic_collection?(node)
|
135
139
|
def_node_matcher :non_polymorphic_collection?, <<~PATTERN
|
136
140
|
{(send (send (send (const {nil? cbase} :File) :stat _) ...) ...)
|
137
|
-
(send (send (send (const {nil? cbase} {:Tempfile :StringIO}) {:new :open} ...) ...) ...)}
|
141
|
+
(send (send (send (const {nil? cbase} {:File :Tempfile :StringIO}) {:new :open} ...) ...) ...)}
|
138
142
|
PATTERN
|
139
143
|
end
|
140
144
|
end
|
data/lib/rubocop/cop/team.rb
CHANGED
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
def self.mobilize_cops(cop_classes, config, options = {})
|
29
29
|
cop_classes = Registry.new(cop_classes.to_a, options) unless cop_classes.is_a?(Registry)
|
30
30
|
|
31
|
-
cop_classes.
|
31
|
+
cop_classes.map do |cop_class|
|
32
32
|
cop_class.new(config, options)
|
33
33
|
end
|
34
34
|
end
|
@@ -58,6 +58,7 @@ module RuboCop
|
|
58
58
|
@options = options
|
59
59
|
reset
|
60
60
|
@ready = true
|
61
|
+
@registry = Registry.new(cops, options.dup)
|
61
62
|
|
62
63
|
validate_config
|
63
64
|
end
|
@@ -84,7 +85,7 @@ module RuboCop
|
|
84
85
|
# until there are no corrections left to perform
|
85
86
|
# To speed things up, run autocorrecting cops by themselves, and only
|
86
87
|
# run the other cops when no corrections are left
|
87
|
-
on_duty = roundup_relevant_cops(processed_source
|
88
|
+
on_duty = roundup_relevant_cops(processed_source)
|
88
89
|
|
89
90
|
autocorrect_cops, other_cops = on_duty.partition(&:autocorrect?)
|
90
91
|
report = investigate_partial(autocorrect_cops, processed_source,
|
@@ -130,7 +131,7 @@ module RuboCop
|
|
130
131
|
# holds source read in from stdin, when --stdin option is used
|
131
132
|
@options[:stdin] = new_source
|
132
133
|
else
|
133
|
-
filename = processed_source.
|
134
|
+
filename = processed_source.file_path
|
134
135
|
File.write(filename, new_source)
|
135
136
|
end
|
136
137
|
@updated_source_file = true
|
@@ -156,11 +157,13 @@ module RuboCop
|
|
156
157
|
end
|
157
158
|
|
158
159
|
# @return [Array<cop>]
|
159
|
-
def roundup_relevant_cops(
|
160
|
-
cops.
|
161
|
-
|
162
|
-
|
163
|
-
|
160
|
+
def roundup_relevant_cops(processed_source)
|
161
|
+
cops.select do |cop|
|
162
|
+
next true if processed_source.comment_config.cop_opted_in?(cop)
|
163
|
+
next false unless @registry.enabled?(cop, @config)
|
164
|
+
next false if cop.excluded_file?(processed_source.file_path)
|
165
|
+
|
166
|
+
support_target_ruby_version?(cop) && support_target_rails_version?(cop)
|
164
167
|
end
|
165
168
|
end
|
166
169
|
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
# This module contains a collection of useful utility methods.
|
6
|
+
# rubocop:disable Metrics/ModuleLength
|
6
7
|
module Util
|
7
8
|
include PathUtil
|
8
9
|
|
@@ -80,7 +81,7 @@ module RuboCop
|
|
80
81
|
end
|
81
82
|
|
82
83
|
def args_end(node)
|
83
|
-
node.
|
84
|
+
node.source_range.end
|
84
85
|
end
|
85
86
|
|
86
87
|
def on_node(syms, sexp, excludes = [], &block)
|
@@ -92,13 +93,20 @@ module RuboCop
|
|
92
93
|
sexp.each_child_node { |elem| on_node(syms, elem, excludes, &block) }
|
93
94
|
end
|
94
95
|
|
96
|
+
# Arbitrarily chosen value, should be enough to cover
|
97
|
+
# the most nested source code in real world projects.
|
98
|
+
MAX_LINE_BEGINS_REGEX_INDEX = 50
|
95
99
|
LINE_BEGINS_REGEX_CACHE = Hash.new do |hash, index|
|
96
|
-
hash[index] = /^\s{#{index}}\S/
|
100
|
+
hash[index] = /^\s{#{index}}\S/ if index <= MAX_LINE_BEGINS_REGEX_INDEX
|
97
101
|
end
|
98
|
-
private_constant :LINE_BEGINS_REGEX_CACHE
|
102
|
+
private_constant :MAX_LINE_BEGINS_REGEX_INDEX, :LINE_BEGINS_REGEX_CACHE
|
99
103
|
|
100
104
|
def begins_its_line?(range)
|
101
|
-
|
105
|
+
if (regex = LINE_BEGINS_REGEX_CACHE[range.column])
|
106
|
+
range.source_line.match?(regex)
|
107
|
+
else
|
108
|
+
range.source_line.index(/\S/) == range.column
|
109
|
+
end
|
102
110
|
end
|
103
111
|
|
104
112
|
# Returns, for example, a bare `if` node if the given node is an `if`
|
@@ -190,5 +198,6 @@ module RuboCop
|
|
190
198
|
source == target || (source.is_a?(Array) && source.include?(target))
|
191
199
|
end
|
192
200
|
end
|
201
|
+
# rubocop:enable Metrics/ModuleLength
|
193
202
|
end
|
194
203
|
end
|
@@ -52,7 +52,7 @@ module RuboCop
|
|
52
52
|
# if/unless keyword. A preceding assignment is needed to put the
|
53
53
|
# variable in scope. For this reason we skip to the next assignment
|
54
54
|
# here.
|
55
|
-
next if
|
55
|
+
next if in_modifier_conditional?(assignment)
|
56
56
|
|
57
57
|
break if !assignment.branch || assignment.branch == reference.branch
|
58
58
|
|
@@ -63,10 +63,12 @@ module RuboCop
|
|
63
63
|
end
|
64
64
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
65
65
|
|
66
|
-
def
|
66
|
+
def in_modifier_conditional?(assignment)
|
67
67
|
parent = assignment.node.parent
|
68
68
|
parent = parent.parent if parent&.begin_type?
|
69
|
-
|
69
|
+
return false if parent.nil?
|
70
|
+
|
71
|
+
(parent.if_type? || parent.while_type? || parent.until_type?) && parent.modifier_form?
|
70
72
|
end
|
71
73
|
|
72
74
|
def capture_with_block!
|
@@ -45,9 +45,9 @@ module RuboCop
|
|
45
45
|
|
46
46
|
def range
|
47
47
|
match = comment.text.match(DIRECTIVE_COMMENT_REGEXP)
|
48
|
-
begin_pos = comment.
|
48
|
+
begin_pos = comment.source_range.begin_pos
|
49
49
|
Parser::Source::Range.new(
|
50
|
-
comment.
|
50
|
+
comment.source_range.source_buffer, begin_pos + match.begin(0), begin_pos + match.end(0)
|
51
51
|
)
|
52
52
|
end
|
53
53
|
|
@@ -108,7 +108,7 @@ module RuboCop
|
|
108
108
|
|
109
109
|
# Returns line number for directive
|
110
110
|
def line_number
|
111
|
-
comment.
|
111
|
+
comment.source_range.line
|
112
112
|
end
|
113
113
|
|
114
114
|
private
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Ext
|
5
|
+
# Extensions to `Parser::Source::Comment`.
|
6
|
+
module Comment
|
7
|
+
def source
|
8
|
+
loc.expression.source
|
9
|
+
end
|
10
|
+
|
11
|
+
def source_range
|
12
|
+
loc.expression
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Parser::Source::Comment.include RuboCop::Ext::Comment
|
@@ -69,7 +69,7 @@ module CopHelper
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def _investigate(cop, processed_source)
|
72
|
-
team = RuboCop::Cop::Team.new([cop],
|
72
|
+
team = RuboCop::Cop::Team.new([cop], configuration, raise_error: true)
|
73
73
|
report = team.investigate(processed_source)
|
74
74
|
@last_corrector = report.correctors.first || RuboCop::Cop::Corrector.new(processed_source)
|
75
75
|
report.offenses.reject(&:disabled?)
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
# The kind of Ruby that code inspected by RuboCop is written in.
|
5
5
|
# @api private
|
6
6
|
class TargetRuby
|
7
|
-
KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2].freeze
|
7
|
+
KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3].freeze
|
8
8
|
DEFAULT_VERSION = 2.6
|
9
9
|
|
10
10
|
OBSOLETE_RUBIES = {
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -14,6 +14,7 @@ require_relative 'rubocop/version'
|
|
14
14
|
require 'rubocop-ast'
|
15
15
|
|
16
16
|
require_relative 'rubocop/ast_aliases'
|
17
|
+
require_relative 'rubocop/ext/comment'
|
17
18
|
require_relative 'rubocop/ext/range'
|
18
19
|
require_relative 'rubocop/ext/regexp_node'
|
19
20
|
require_relative 'rubocop/ext/regexp_parser'
|
@@ -415,6 +416,7 @@ require_relative 'rubocop/cop/metrics/abc_size'
|
|
415
416
|
require_relative 'rubocop/cop/metrics/block_length'
|
416
417
|
require_relative 'rubocop/cop/metrics/block_nesting'
|
417
418
|
require_relative 'rubocop/cop/metrics/class_length'
|
419
|
+
require_relative 'rubocop/cop/metrics/collection_literal_length'
|
418
420
|
require_relative 'rubocop/cop/metrics/method_length'
|
419
421
|
require_relative 'rubocop/cop/metrics/module_length'
|
420
422
|
require_relative 'rubocop/cop/metrics/parameter_lists'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.47.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
requirements:
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: 1.
|
123
|
+
version: 1.26.0
|
124
124
|
- - "<"
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '2.0'
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
requirements:
|
131
131
|
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 1.
|
133
|
+
version: 1.26.0
|
134
134
|
- - "<"
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '2.0'
|
@@ -273,6 +273,7 @@ files:
|
|
273
273
|
- lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb
|
274
274
|
- lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb
|
275
275
|
- lib/rubocop/cop/internal_affairs/lambda_or_proc.rb
|
276
|
+
- lib/rubocop/cop/internal_affairs/location_expression.rb
|
276
277
|
- lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb
|
277
278
|
- lib/rubocop/cop/internal_affairs/method_name_end_with.rb
|
278
279
|
- lib/rubocop/cop/internal_affairs/method_name_equal.rb
|
@@ -281,12 +282,14 @@ files:
|
|
281
282
|
- lib/rubocop/cop/internal_affairs/node_type_predicate.rb
|
282
283
|
- lib/rubocop/cop/internal_affairs/numblock_handler.rb
|
283
284
|
- lib/rubocop/cop/internal_affairs/offense_location_keyword.rb
|
285
|
+
- lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb
|
284
286
|
- lib/rubocop/cop/internal_affairs/redundant_context_config_parameter.rb
|
285
287
|
- lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb
|
286
288
|
- lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb
|
287
289
|
- lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
|
288
290
|
- lib/rubocop/cop/internal_affairs/redundant_message_argument.rb
|
289
291
|
- lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
|
292
|
+
- lib/rubocop/cop/internal_affairs/redundant_source_range.rb
|
290
293
|
- lib/rubocop/cop/internal_affairs/single_line_comparison.rb
|
291
294
|
- lib/rubocop/cop/internal_affairs/style_detected_api_use.rb
|
292
295
|
- lib/rubocop/cop/internal_affairs/undefined_config.rb
|
@@ -530,6 +533,7 @@ files:
|
|
530
533
|
- lib/rubocop/cop/metrics/block_length.rb
|
531
534
|
- lib/rubocop/cop/metrics/block_nesting.rb
|
532
535
|
- lib/rubocop/cop/metrics/class_length.rb
|
536
|
+
- lib/rubocop/cop/metrics/collection_literal_length.rb
|
533
537
|
- lib/rubocop/cop/metrics/cyclomatic_complexity.rb
|
534
538
|
- lib/rubocop/cop/metrics/method_length.rb
|
535
539
|
- lib/rubocop/cop/metrics/module_length.rb
|
@@ -902,6 +906,7 @@ files:
|
|
902
906
|
- lib/rubocop/core_ext/string.rb
|
903
907
|
- lib/rubocop/directive_comment.rb
|
904
908
|
- lib/rubocop/error.rb
|
909
|
+
- lib/rubocop/ext/comment.rb
|
905
910
|
- lib/rubocop/ext/processed_source.rb
|
906
911
|
- lib/rubocop/ext/range.rb
|
907
912
|
- lib/rubocop/ext/regexp_node.rb
|
@@ -980,7 +985,7 @@ metadata:
|
|
980
985
|
homepage_uri: https://rubocop.org/
|
981
986
|
changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
|
982
987
|
source_code_uri: https://github.com/rubocop/rubocop/
|
983
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
988
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.47/
|
984
989
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
985
990
|
rubygems_mfa_required: 'true'
|
986
991
|
post_install_message:
|