rubocop 1.71.2 → 1.73.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 +3 -3
- data/config/default.yml +51 -11
- data/config/internal_affairs.yml +16 -0
- data/lib/rubocop/cli/command/suggest_extensions.rb +7 -1
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +4 -0
- data/lib/rubocop/config_loader.rb +44 -8
- data/lib/rubocop/config_loader_resolver.rb +23 -9
- data/lib/rubocop/config_validator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +4 -2
- data/lib/rubocop/cop/internal_affairs/location_exists.rb +116 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +7 -1
- data/lib/rubocop/cop/internal_affairs.rb +1 -16
- data/lib/rubocop/cop/layout/block_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +26 -1
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +22 -2
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +3 -3
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +84 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -14
- data/lib/rubocop/cop/lint/float_comparison.rb +1 -6
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +104 -7
- data/lib/rubocop/cop/lint/mixed_case_range.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +252 -0
- data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +111 -0
- data/lib/rubocop/cop/lint/useless_constant_scoping.rb +80 -0
- data/lib/rubocop/cop/lint/void.rb +6 -0
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
- data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +18 -18
- data/lib/rubocop/cop/mixin/hash_subset.rb +19 -4
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +74 -74
- data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +3 -3
- data/lib/rubocop/cop/mixin/string_help.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +12 -0
- data/lib/rubocop/cop/naming/block_forwarding.rb +3 -3
- data/lib/rubocop/cop/naming/predicate_name.rb +44 -0
- data/lib/rubocop/cop/naming/variable_name.rb +64 -6
- data/lib/rubocop/cop/style/accessor_grouping.rb +19 -5
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
- data/lib/rubocop/cop/style/endless_method.rb +163 -18
- data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +34 -0
- data/lib/rubocop/cop/style/redundant_format.rb +250 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +18 -4
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +3 -3
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +7 -5
- data/lib/rubocop/cops_documentation_generator.rb +12 -1
- data/lib/rubocop/directive_comment.rb +35 -2
- data/lib/rubocop/lsp/runtime.rb +2 -0
- data/lib/rubocop/lsp/server.rb +0 -2
- data/lib/rubocop/options.rb +26 -11
- data/lib/rubocop/path_util.rb +4 -0
- data/lib/rubocop/plugin/configuration_integrator.rb +143 -0
- data/lib/rubocop/plugin/load_error.rb +26 -0
- data/lib/rubocop/plugin/loader.rb +100 -0
- data/lib/rubocop/plugin/not_supported_error.rb +29 -0
- data/lib/rubocop/plugin.rb +46 -0
- data/lib/rubocop/rake_task.rb +4 -1
- data/lib/rubocop/rspec/cop_helper.rb +9 -0
- data/lib/rubocop/rspec/shared_contexts.rb +15 -0
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/server/cache.rb +35 -2
- data/lib/rubocop/server/cli.rb +2 -2
- data/lib/rubocop/version.rb +17 -2
- data/lib/rubocop.rb +5 -1
- data/lib/ruby_lsp/rubocop/addon.rb +7 -10
- data/lib/ruby_lsp/rubocop/{wraps_built_in_lsp_runtime.rb → runtime_adapter.rb} +5 -8
- metadata +35 -10
- data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
@@ -1,113 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module Utils
|
6
|
-
# Helper to abstract complexity of building range pairs
|
7
|
-
# with octal escape reconstruction (needed for regexp_parser < 2.7).
|
8
|
-
class RegexpRanges
|
9
|
-
attr_reader :root
|
10
|
-
|
11
|
-
def initialize(root)
|
12
|
-
@root = root
|
13
|
-
@compound_token = []
|
14
|
-
@pairs = []
|
15
|
-
@populated = false
|
16
|
-
end
|
17
|
-
|
18
|
-
def compound_token
|
19
|
-
populate_all unless @populated
|
20
|
-
|
21
|
-
@compound_token
|
22
|
-
end
|
23
|
-
|
24
|
-
def pairs
|
25
|
-
populate_all unless @populated
|
26
|
-
|
27
|
-
@pairs
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def populate_all
|
33
|
-
populate(@root)
|
34
|
-
|
35
|
-
# If either bound is a compound the first one is an escape
|
36
|
-
# and that's all we need to work with.
|
37
|
-
# If there are any cops that wanted to operate on the compound
|
38
|
-
# expression we could wrap it with a facade class.
|
39
|
-
@pairs.map! { |pair| pair.map(&:first) }
|
40
|
-
|
41
|
-
@populated = true
|
42
|
-
end
|
43
|
-
|
44
|
-
def populate(expr)
|
45
|
-
expressions = expr.expressions.to_a
|
46
|
-
|
47
|
-
until expressions.empty?
|
48
|
-
current = expressions.shift
|
49
|
-
|
50
|
-
if escaped_octal?(current)
|
51
|
-
@compound_token << current
|
52
|
-
@compound_token.concat(pop_octal_digits(expressions))
|
53
|
-
# If we have all the digits we can discard.
|
54
|
-
end
|
55
|
-
|
56
|
-
next unless current.type == :set
|
57
|
-
|
58
|
-
process_set(expressions, current)
|
59
|
-
@compound_token.clear
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def process_set(expressions, current)
|
64
|
-
case current.token
|
65
|
-
when :range
|
66
|
-
@pairs << compose_range(expressions, current)
|
67
|
-
when :character
|
68
|
-
# Child expressions may include the range we are looking for.
|
69
|
-
populate(current)
|
70
|
-
when :intersection
|
71
|
-
# Each child expression could have child expressions that lead to ranges.
|
72
|
-
current.expressions.each do |intersected|
|
73
|
-
populate(intersected)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def compose_range(expressions, current)
|
79
|
-
range_start, range_end = current.expressions
|
80
|
-
range_start = if @compound_token.size.between?(1, 2) && octal_digit?(range_start.text)
|
81
|
-
@compound_token.dup << range_start
|
82
|
-
else
|
83
|
-
[range_start]
|
84
|
-
end
|
85
|
-
range_end = [range_end]
|
86
|
-
range_end.concat(pop_octal_digits(expressions)) if escaped_octal?(range_end.first)
|
87
|
-
[range_start, range_end]
|
88
|
-
end
|
89
|
-
|
90
|
-
def escaped_octal?(expr)
|
91
|
-
expr.text.valid_encoding? && expr.text =~ /^\\[0-7]$/
|
92
|
-
end
|
93
|
-
|
94
|
-
def octal_digit?(char)
|
95
|
-
('0'..'7').cover?(char)
|
96
|
-
end
|
97
|
-
|
98
|
-
def pop_octal_digits(expressions)
|
99
|
-
digits = []
|
100
|
-
|
101
|
-
2.times do
|
102
|
-
next unless (next_child = expressions.first)
|
103
|
-
next unless next_child.type == :literal && next_child.text =~ /^[0-7]$/
|
104
|
-
|
105
|
-
digits << expressions.shift
|
106
|
-
end
|
107
|
-
|
108
|
-
digits
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|