rubocop 1.48.1 → 1.52.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/README.md +3 -3
- data/config/default.yml +59 -12
- data/lib/rubocop/cli/command/execute_runner.rb +7 -2
- data/lib/rubocop/cli.rb +6 -6
- data/lib/rubocop/config.rb +5 -1
- data/lib/rubocop/config_loader.rb +8 -8
- data/lib/rubocop/config_obsoletion.rb +2 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +28 -12
- data/lib/rubocop/cop/base.rb +5 -1
- data/lib/rubocop/cop/cop.rb +2 -2
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +33 -9
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +29 -2
- data/lib/rubocop/cop/layout/class_structure.rb +1 -0
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +0 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +5 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -4
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
- data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -0
- data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +13 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +3 -3
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -4
- data/lib/rubocop/cop/lint/identity_comparison.rb +0 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -3
- data/lib/rubocop/cop/lint/inherit_exception.rb +9 -0
- data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
- data/lib/rubocop/cop/lint/missing_super.rb +3 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +0 -1
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -2
- data/lib/rubocop/cop/lint/shadowed_exception.rb +5 -11
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +7 -1
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +23 -9
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
- data/lib/rubocop/cop/lint/useless_assignment.rb +59 -1
- data/lib/rubocop/cop/lint/useless_method_definition.rb +10 -2
- data/lib/rubocop/cop/lint/void.rb +69 -9
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -0
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -2
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_receivers.rb +34 -0
- data/lib/rubocop/cop/mixin/comments_help.rb +7 -3
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +22 -7
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +11 -3
- data/lib/rubocop/cop/naming/variable_name.rb +6 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +5 -1
- data/lib/rubocop/cop/style/attr.rb +11 -1
- data/lib/rubocop/cop/style/begin_block.rb +1 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
- data/lib/rubocop/cop/style/class_equality_comparison.rb +51 -40
- data/lib/rubocop/cop/style/collection_compact.rb +19 -6
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/combinable_loops.rb +26 -6
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/copyright.rb +6 -3
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/dir_empty.rb +8 -14
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- 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/double_negation.rb +2 -2
- data/lib/rubocop/cop/style/eval_with_location.rb +5 -5
- data/lib/rubocop/cop/style/exact_regexp_match.rb +68 -0
- data/lib/rubocop/cop/style/file_empty.rb +3 -3
- data/lib/rubocop/cop/style/file_read.rb +2 -2
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +2 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -22
- data/lib/rubocop/cop/style/hash_except.rb +23 -12
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
- data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
- data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +41 -12
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +9 -5
- data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
- data/lib/rubocop/cop/style/map_to_set.rb +4 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +4 -9
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +43 -36
- data/lib/rubocop/cop/style/multiline_method_signature.rb +6 -3
- data/lib/rubocop/cop/style/multiple_comparison.rb +14 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/parallel_assignment.rb +26 -18
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/redundant_array_constructor.rb +77 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +101 -0
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +183 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +46 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -3
- data/lib/rubocop/cop/style/regexp_literal.rb +11 -2
- data/lib/rubocop/cop/style/require_order.rb +11 -5
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -3
- data/lib/rubocop/cop/style/select_by_regexp.rb +15 -5
- data/lib/rubocop/cop/style/semicolon.rb +12 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +5 -3
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -4
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
- data/lib/rubocop/cop/team.rb +1 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +33 -1
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
- data/lib/rubocop/cop/variable_force.rb +1 -0
- data/lib/rubocop/cops_documentation_generator.rb +10 -3
- data/lib/rubocop/ext/regexp_node.rb +1 -1
- data/lib/rubocop/ext/regexp_parser.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/options.rb +4 -1
- data/lib/rubocop/result_cache.rb +2 -2
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/server/cache.rb +1 -1
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/server/helper.rb +1 -1
- data/lib/rubocop/server/server_command/exec.rb +1 -1
- data/lib/rubocop/target_ruby.rb +3 -2
- data/lib/rubocop/version.rb +10 -6
- data/lib/rubocop.rb +8 -0
- metadata +20 -12
@@ -84,6 +84,7 @@ module RuboCop
|
|
84
84
|
}
|
85
85
|
PATTERN
|
86
86
|
|
87
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
87
88
|
def on_send(node)
|
88
89
|
return unless (block_node = node.block_node)
|
89
90
|
return if block_node.body&.begin_type?
|
@@ -91,11 +92,14 @@ module RuboCop
|
|
91
92
|
return unless (regexp_method_send_node = extract_send_node(block_node))
|
92
93
|
return if match_predicate_without_receiver?(regexp_method_send_node)
|
93
94
|
|
94
|
-
|
95
|
+
replacement = replacement(regexp_method_send_node, node)
|
96
|
+
return if target_ruby_version <= 2.2 && replacement == 'grep_v'
|
97
|
+
|
95
98
|
regexp = find_regexp(regexp_method_send_node, block_node)
|
96
99
|
|
97
|
-
register_offense(node, block_node, regexp,
|
100
|
+
register_offense(node, block_node, regexp, replacement)
|
98
101
|
end
|
102
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
99
103
|
|
100
104
|
private
|
101
105
|
|
@@ -105,9 +109,15 @@ module RuboCop
|
|
105
109
|
node.hash_type? || creates_hash?(node) || env_const?(node)
|
106
110
|
end
|
107
111
|
|
108
|
-
def
|
109
|
-
|
110
|
-
|
112
|
+
def replacement(regexp_method_send_node, node)
|
113
|
+
opposite = opposite?(regexp_method_send_node)
|
114
|
+
|
115
|
+
method_name = node.method_name
|
116
|
+
|
117
|
+
opposite ? OPPOSITE_REPLACEMENTS[method_name] : REPLACEMENTS[method_name]
|
118
|
+
end
|
119
|
+
|
120
|
+
def register_offense(node, block_node, regexp, replacement)
|
111
121
|
message = format(MSG, replacement: replacement, original_method: node.method_name)
|
112
122
|
|
113
123
|
add_offense(block_node, message: message) do |corrector|
|
@@ -90,8 +90,11 @@ module RuboCop
|
|
90
90
|
0
|
91
91
|
elsif exist_semicolon_before_right_curly_brace?(tokens)
|
92
92
|
-3
|
93
|
-
elsif exist_semicolon_after_left_curly_brace?(tokens)
|
93
|
+
elsif exist_semicolon_after_left_curly_brace?(tokens) ||
|
94
|
+
exist_semicolon_after_left_string_interpolation_brace?(tokens)
|
94
95
|
2
|
96
|
+
elsif exist_semicolon_before_right_string_interpolation_brace?(tokens)
|
97
|
+
-4
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
@@ -103,6 +106,14 @@ module RuboCop
|
|
103
106
|
tokens[1]&.left_curly_brace? && tokens[2]&.semicolon?
|
104
107
|
end
|
105
108
|
|
109
|
+
def exist_semicolon_before_right_string_interpolation_brace?(tokens)
|
110
|
+
tokens[-3]&.type == :tSTRING_DEND && tokens[-4]&.semicolon?
|
111
|
+
end
|
112
|
+
|
113
|
+
def exist_semicolon_after_left_string_interpolation_brace?(tokens)
|
114
|
+
tokens[1]&.type == :tSTRING_DBEG && tokens[2]&.semicolon?
|
115
|
+
end
|
116
|
+
|
106
117
|
def register_semicolon(line, column, after_expression, token_before_semicolon = nil)
|
107
118
|
range = source_range(processed_source.buffer, line, column)
|
108
119
|
|
@@ -135,7 +135,7 @@ module RuboCop
|
|
135
135
|
|
136
136
|
def disallow_endless_method_style?
|
137
137
|
endless_method_config = config.for_cop('Style/EndlessMethod')
|
138
|
-
return
|
138
|
+
return true unless endless_method_config['Enabled']
|
139
139
|
|
140
140
|
endless_method_config['EnforcedStyle'] == 'disallow'
|
141
141
|
end
|
@@ -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)
|
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
|
@@ -186,8 +186,10 @@ module RuboCop
|
|
186
186
|
begin_pos = condition.first_argument.source_range.begin_pos
|
187
187
|
return if end_pos > begin_pos
|
188
188
|
|
189
|
-
|
190
|
-
corrector.
|
189
|
+
range = range_between(end_pos, begin_pos)
|
190
|
+
corrector.remove(range)
|
191
|
+
corrector.insert_after(range, '(')
|
192
|
+
corrector.insert_after(condition.last_argument, ')')
|
191
193
|
end
|
192
194
|
|
193
195
|
def insert_bang(corrector, node, is_modify_form)
|
@@ -3,8 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
7
|
-
# This cop looks for uses of Perl-style global variables.
|
6
|
+
# Looks for uses of Perl-style global variables.
|
8
7
|
# Correcting to global variables in the 'English' library
|
9
8
|
# will add a require statement to the top of the file if
|
10
9
|
# enabled by RequireEnglish config.
|
@@ -234,9 +233,9 @@ module RuboCop
|
|
234
233
|
end
|
235
234
|
|
236
235
|
def matching_styles(global)
|
237
|
-
STYLE_VARS_MAP.
|
236
|
+
STYLE_VARS_MAP.filter_map do |style, vars|
|
238
237
|
style if vars.values.flatten(1).include? global
|
239
|
-
end
|
238
|
+
end
|
240
239
|
end
|
241
240
|
|
242
241
|
def english_name_replacement(preferred_name, node)
|
data/lib/rubocop/cop/team.rb
CHANGED
@@ -47,6 +47,10 @@ module RuboCop
|
|
47
47
|
@node.type == REGEXP_NAMED_CAPTURE_TYPE
|
48
48
|
end
|
49
49
|
|
50
|
+
def exception_assignment?
|
51
|
+
node.parent&.resbody_type? && node.parent.exception_variable == node
|
52
|
+
end
|
53
|
+
|
50
54
|
def operator_assignment?
|
51
55
|
return false unless meta_assignment_node
|
52
56
|
|
@@ -59,6 +63,18 @@ module RuboCop
|
|
59
63
|
meta_assignment_node.type == MULTIPLE_ASSIGNMENT_TYPE
|
60
64
|
end
|
61
65
|
|
66
|
+
def rest_assignment?
|
67
|
+
return false unless meta_assignment_node
|
68
|
+
|
69
|
+
meta_assignment_node.type == REST_ASSIGNMENT_TYPE
|
70
|
+
end
|
71
|
+
|
72
|
+
def for_assignment?
|
73
|
+
return false unless meta_assignment_node
|
74
|
+
|
75
|
+
meta_assignment_node.for_type?
|
76
|
+
end
|
77
|
+
|
62
78
|
def operator
|
63
79
|
assignment_node = meta_assignment_node || @node
|
64
80
|
assignment_node.loc.operator.source
|
@@ -66,7 +82,10 @@ module RuboCop
|
|
66
82
|
|
67
83
|
def meta_assignment_node
|
68
84
|
unless instance_variable_defined?(:@meta_assignment_node)
|
69
|
-
@meta_assignment_node = operator_assignment_node ||
|
85
|
+
@meta_assignment_node = operator_assignment_node ||
|
86
|
+
multiple_assignment_node ||
|
87
|
+
rest_assignment_node ||
|
88
|
+
for_assignment_node
|
70
89
|
end
|
71
90
|
|
72
91
|
@meta_assignment_node
|
@@ -90,6 +109,19 @@ module RuboCop
|
|
90
109
|
|
91
110
|
grandparent_node
|
92
111
|
end
|
112
|
+
|
113
|
+
def rest_assignment_node
|
114
|
+
return nil unless node.parent
|
115
|
+
return nil unless node.parent.type == REST_ASSIGNMENT_TYPE
|
116
|
+
|
117
|
+
node.parent
|
118
|
+
end
|
119
|
+
|
120
|
+
def for_assignment_node
|
121
|
+
return nil unless node.parent&.for_type?
|
122
|
+
|
123
|
+
node.parent
|
124
|
+
end
|
93
125
|
end
|
94
126
|
end
|
95
127
|
end
|
@@ -113,14 +113,14 @@ module RuboCop
|
|
113
113
|
def accessible_variables
|
114
114
|
scope_stack.reverse_each.with_object([]) do |scope, variables|
|
115
115
|
variables.concat(scope.variables.values)
|
116
|
-
break variables unless scope.node.block_type?
|
116
|
+
break variables unless scope.node.block_type? || scope.node.numblock_type?
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
private
|
121
121
|
|
122
122
|
def mark_variable_as_captured_by_block_if_so(variable)
|
123
|
-
return unless current_scope.node.block_type?
|
123
|
+
return unless current_scope.node.block_type? || current_scope.node.numblock_type?
|
124
124
|
return if variable.scope == current_scope
|
125
125
|
|
126
126
|
variable.capture_with_block!
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'fileutils'
|
4
|
+
|
3
5
|
# Class for generating documentation of all cops departments
|
4
6
|
# @api private
|
5
7
|
class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
@@ -14,6 +16,8 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
14
16
|
@departments = departments.map(&:to_sym).sort!
|
15
17
|
@cops = RuboCop::Cop::Registry.global
|
16
18
|
@config = RuboCop::ConfigLoader.default_configuration
|
19
|
+
@docs_path = "#{Dir.pwd}/docs/modules/ROOT/pages/"
|
20
|
+
FileUtils.mkdir_p(@docs_path)
|
17
21
|
end
|
18
22
|
|
19
23
|
def call
|
@@ -27,7 +31,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
27
31
|
|
28
32
|
private
|
29
33
|
|
30
|
-
attr_reader :departments, :cops, :config
|
34
|
+
attr_reader :departments, :cops, :config, :docs_path
|
31
35
|
|
32
36
|
def cops_of_department(department)
|
33
37
|
cops.with_department(department).sort!
|
@@ -252,7 +256,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
252
256
|
content = +"= #{department}\n"
|
253
257
|
selected_cops.each { |cop| content << print_cop_with_doc(cop) }
|
254
258
|
content << footer_for_department(department)
|
255
|
-
file_name = "#{
|
259
|
+
file_name = "#{docs_path}/#{department_to_basename(department)}.adoc"
|
256
260
|
File.open(file_name, 'w') do |file|
|
257
261
|
puts "* generated #{file_name}"
|
258
262
|
file.write("#{content.strip}\n")
|
@@ -298,7 +302,10 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
|
|
298
302
|
end
|
299
303
|
|
300
304
|
def print_table_of_contents
|
301
|
-
path = "#{
|
305
|
+
path = "#{docs_path}/cops.adoc"
|
306
|
+
|
307
|
+
File.write(path, table_contents) and return unless File.exist?(path)
|
308
|
+
|
302
309
|
original = File.read(path)
|
303
310
|
content = +"// START_COP_LIST\n\n"
|
304
311
|
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
@parsed_tree&.each_expression(true) { |e| e.origin = origin }
|
30
30
|
end
|
31
31
|
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
32
|
-
# It's for compatibility with
|
32
|
+
# It's for compatibility with regexp_parser 1.8 and will never be maintained.
|
33
33
|
else
|
34
34
|
def assign_properties(*)
|
35
35
|
super
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
@expression ||= origin.adjust(begin_pos: ts, end_pos: ts + full_length)
|
29
29
|
end
|
30
30
|
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
31
|
-
# It's for compatibility with
|
31
|
+
# It's for compatibility with regexp_parser 1.8 and will never be maintained.
|
32
32
|
else
|
33
33
|
attr_accessor :source
|
34
34
|
|
@@ -61,7 +61,7 @@ module RuboCop
|
|
61
61
|
correctable_count,
|
62
62
|
rainbow,
|
63
63
|
# :safe_autocorrect is a derived option based on several command-line
|
64
|
-
# arguments - see
|
64
|
+
# arguments - see RuboCop::Options#add_autocorrection_options
|
65
65
|
safe_autocorrect: @options[:safe_autocorrect])
|
66
66
|
|
67
67
|
output.puts
|
data/lib/rubocop/options.rb
CHANGED
@@ -182,7 +182,10 @@ module RuboCop
|
|
182
182
|
raise OptionArgumentError, message
|
183
183
|
end
|
184
184
|
|
185
|
-
|
185
|
+
cop_names = list.empty? ? [''] : list.split(',')
|
186
|
+
cop_names.unshift('Lint/Syntax') if option == 'only' && !cop_names.include?('Lint/Syntax')
|
187
|
+
|
188
|
+
@options[:"#{option}"] = cop_names
|
186
189
|
end
|
187
190
|
end
|
188
191
|
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -83,10 +83,10 @@ module RuboCop
|
|
83
83
|
config_store.for_pwd.for_all_cops['AllowSymlinksInCacheRootDirectory']
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
attr_reader :path
|
87
87
|
|
88
88
|
def initialize(file, team, options, config_store, cache_root = nil)
|
89
|
-
cache_root ||= options[:cache_root]
|
89
|
+
cache_root ||= File.join(options[:cache_root], 'rubocop_cache') if options[:cache_root]
|
90
90
|
cache_root ||= ResultCache.cache_root(config_store)
|
91
91
|
@allow_symlinks_in_cache_location =
|
92
92
|
ResultCache.allow_symlinks_in_cache_location?(config_store)
|
data/lib/rubocop/server/cache.rb
CHANGED
@@ -18,10 +18,11 @@ module RuboCop
|
|
18
18
|
def run
|
19
19
|
ensure_server!
|
20
20
|
Cache.status_path.delete if Cache.status_path.file?
|
21
|
+
read_stdin = ARGV.include?('-s') || ARGV.include?('--stdin')
|
21
22
|
send_request(
|
22
23
|
command: 'exec',
|
23
24
|
args: ARGV.dup,
|
24
|
-
body: $stdin.
|
25
|
+
body: read_stdin ? $stdin.read : ''
|
25
26
|
)
|
26
27
|
warn stderr unless stderr.empty?
|
27
28
|
status
|
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
module RuboCop
|
13
13
|
module Server
|
14
|
-
# This module has a helper
|
14
|
+
# This module has a helper method for `RuboCop::Server::SocketReader`.
|
15
15
|
# @api private
|
16
16
|
module Helper
|
17
17
|
def self.redirect(stdin: $stdin, stdout: $stdout, stderr: $stderr, &_block)
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
# We must pass the --color option to preserve this behavior.
|
22
22
|
@args.unshift('--color') unless %w[--color --no-color].any? { |f| @args.include?(f) }
|
23
23
|
status = RuboCop::CLI.new.run(@args)
|
24
|
-
# This status file is read by `rubocop --server` (`RuboCop::Server::
|
24
|
+
# This status file is read by `rubocop --server` (`RuboCop::Server::ClientCommand::Exec`).
|
25
25
|
# so that they use the correct exit code.
|
26
26
|
# Status is 1 when there are any issues, and 0 otherwise.
|
27
27
|
Cache.write_status_file(status)
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
# @api private
|
6
6
|
class TargetRuby
|
7
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
|
-
DEFAULT_VERSION = 2.
|
8
|
+
DEFAULT_VERSION = 2.7
|
9
9
|
|
10
10
|
OBSOLETE_RUBIES = {
|
11
11
|
1.9 => '0.41',
|
@@ -14,7 +14,8 @@ module RuboCop
|
|
14
14
|
2.2 => '0.68',
|
15
15
|
2.3 => '0.81',
|
16
16
|
2.4 => '1.12',
|
17
|
-
2.5 => '1.28'
|
17
|
+
2.5 => '1.28',
|
18
|
+
2.6 => '1.50'
|
18
19
|
}.freeze
|
19
20
|
private_constant :KNOWN_RUBIES, :OBSOLETE_RUBIES
|
20
21
|
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,15 +3,19 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '1.
|
6
|
+
STRING = '1.52.1'
|
7
7
|
|
8
8
|
MSG = '%<version>s (using Parser %<parser_version>s, ' \
|
9
9
|
'rubocop-ast %<rubocop_ast_version>s, ' \
|
10
10
|
'running on %<ruby_engine>s %<ruby_version>s)%<server_mode>s [%<ruby_platform>s]'
|
11
11
|
|
12
|
-
CANONICAL_FEATURE_NAMES = {
|
13
|
-
|
14
|
-
|
12
|
+
CANONICAL_FEATURE_NAMES = {
|
13
|
+
'Rspec' => 'RSpec', 'Graphql' => 'GraphQL', 'Md' => 'Markdown', 'Factory_bot' => 'FactoryBot',
|
14
|
+
'Thread_safety' => 'ThreadSafety'
|
15
|
+
}.freeze
|
16
|
+
EXTENSION_PATH_NAMES = {
|
17
|
+
'rubocop-md' => 'markdown', 'rubocop-factory_bot' => 'factory_bot'
|
18
|
+
}.freeze
|
15
19
|
|
16
20
|
# @api private
|
17
21
|
def self.version(debug: false, env: nil)
|
@@ -43,7 +47,7 @@ module RuboCop
|
|
43
47
|
env.config_store.unvalidated.for_pwd.loaded_features.sort
|
44
48
|
end
|
45
49
|
|
46
|
-
features.
|
50
|
+
features.filter_map do |loaded_feature|
|
47
51
|
next unless (match = loaded_feature.match(/rubocop-(?<feature>.*)/))
|
48
52
|
|
49
53
|
# Get the expected name of the folder containing the extension code.
|
@@ -61,7 +65,7 @@ module RuboCop
|
|
61
65
|
next unless (feature_version = feature_version(feature))
|
62
66
|
|
63
67
|
" - #{loaded_feature} #{feature_version}"
|
64
|
-
end
|
68
|
+
end
|
65
69
|
end
|
66
70
|
|
67
71
|
# Returns feature version in one of two ways:
|
data/lib/rubocop.rb
CHANGED
@@ -69,6 +69,7 @@ require_relative 'rubocop/cop/mixin/alignment'
|
|
69
69
|
require_relative 'rubocop/cop/mixin/allowed_identifiers'
|
70
70
|
require_relative 'rubocop/cop/mixin/allowed_methods'
|
71
71
|
require_relative 'rubocop/cop/mixin/allowed_pattern'
|
72
|
+
require_relative 'rubocop/cop/mixin/allowed_receivers'
|
72
73
|
require_relative 'rubocop/cop/mixin/auto_corrector' # rubocop:todo Naming/InclusiveLanguage
|
73
74
|
require_relative 'rubocop/cop/mixin/check_assignment'
|
74
75
|
require_relative 'rubocop/cop/mixin/check_line_breakable'
|
@@ -299,6 +300,7 @@ require_relative 'rubocop/cop/lint/duplicate_case_condition'
|
|
299
300
|
require_relative 'rubocop/cop/lint/duplicate_elsif_condition'
|
300
301
|
require_relative 'rubocop/cop/lint/duplicate_hash_key'
|
301
302
|
require_relative 'rubocop/cop/lint/duplicate_magic_comment'
|
303
|
+
require_relative 'rubocop/cop/lint/duplicate_match_pattern'
|
302
304
|
require_relative 'rubocop/cop/lint/duplicate_methods'
|
303
305
|
require_relative 'rubocop/cop/lint/duplicate_regexp_character_class_element'
|
304
306
|
require_relative 'rubocop/cop/lint/duplicate_require'
|
@@ -480,6 +482,7 @@ require_relative 'rubocop/cop/style/concat_array_literals'
|
|
480
482
|
require_relative 'rubocop/cop/style/conditional_assignment'
|
481
483
|
require_relative 'rubocop/cop/style/constant_visibility'
|
482
484
|
require_relative 'rubocop/cop/style/copyright'
|
485
|
+
require_relative 'rubocop/cop/style/data_inheritance'
|
483
486
|
require_relative 'rubocop/cop/style/date_time'
|
484
487
|
require_relative 'rubocop/cop/style/def_with_parentheses'
|
485
488
|
require_relative 'rubocop/cop/style/dir'
|
@@ -505,6 +508,7 @@ require_relative 'rubocop/cop/style/end_block'
|
|
505
508
|
require_relative 'rubocop/cop/style/env_home'
|
506
509
|
require_relative 'rubocop/cop/style/eval_with_location'
|
507
510
|
require_relative 'rubocop/cop/style/even_odd'
|
511
|
+
require_relative 'rubocop/cop/style/exact_regexp_match'
|
508
512
|
require_relative 'rubocop/cop/style/expand_path_arguments'
|
509
513
|
require_relative 'rubocop/cop/style/explicit_block_argument'
|
510
514
|
require_relative 'rubocop/cop/style/exponential_notation'
|
@@ -555,14 +559,18 @@ require_relative 'rubocop/cop/style/multiline_in_pattern_then'
|
|
555
559
|
require_relative 'rubocop/cop/style/numbered_parameters'
|
556
560
|
require_relative 'rubocop/cop/style/open_struct_use'
|
557
561
|
require_relative 'rubocop/cop/style/operator_method_call'
|
562
|
+
require_relative 'rubocop/cop/style/redundant_array_constructor'
|
558
563
|
require_relative 'rubocop/cop/style/redundant_assignment'
|
559
564
|
require_relative 'rubocop/cop/style/redundant_constant_base'
|
560
565
|
require_relative 'rubocop/cop/style/redundant_double_splat_hash_braces'
|
561
566
|
require_relative 'rubocop/cop/style/redundant_each'
|
562
567
|
require_relative 'rubocop/cop/style/redundant_fetch_block'
|
563
568
|
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
569
|
+
require_relative 'rubocop/cop/style/redundant_filter_chain'
|
564
570
|
require_relative 'rubocop/cop/style/redundant_heredoc_delimiter_quotes'
|
565
571
|
require_relative 'rubocop/cop/style/redundant_initialize'
|
572
|
+
require_relative 'rubocop/cop/style/redundant_line_continuation'
|
573
|
+
require_relative 'rubocop/cop/style/redundant_regexp_constructor'
|
566
574
|
require_relative 'rubocop/cop/style/redundant_self_assignment'
|
567
575
|
require_relative 'rubocop/cop/style/redundant_self_assignment_branch'
|
568
576
|
require_relative 'rubocop/cop/style/require_order'
|