rubocop 1.43.0 → 1.50.2
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 +108 -40
- data/lib/rubocop/cli/command/auto_generate_config.rb +7 -0
- data/lib/rubocop/cli/command/execute_runner.rb +7 -2
- data/lib/rubocop/cli.rb +54 -8
- data/lib/rubocop/comment_config.rb +19 -0
- data/lib/rubocop/config.rb +3 -3
- data/lib/rubocop/config_loader.rb +20 -23
- data/lib/rubocop/config_loader_resolver.rb +3 -4
- data/lib/rubocop/cop/autocorrect_logic.rb +29 -13
- data/lib/rubocop/cop/base.rb +28 -10
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +8 -2
- data/lib/rubocop/cop/cop.rb +25 -5
- data/lib/rubocop/cop/corrector.rb +11 -3
- 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 +2 -7
- 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/dependency_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +107 -0
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +5 -5
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.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_let_rubocop_config_new.rb +11 -3
- 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 +66 -0
- data/lib/rubocop/cop/internal_affairs.rb +3 -0
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -15
- data/lib/rubocop/cop/layout/class_structure.rb +8 -19
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +2 -6
- 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/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 +9 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +8 -3
- 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 +8 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +8 -11
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- 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/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/rescue_ensure_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +11 -13
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +4 -4
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +5 -4
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +11 -27
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +62 -112
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
- 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 +3 -7
- 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/format_parameter_mismatch.rb +14 -7
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +15 -17
- data/lib/rubocop/cop/lint/implicit_string_concatenation.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/mixed_regexp_capture_types.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +4 -9
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -0
- 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 +11 -5
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +12 -2
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
- 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/syntax.rb +4 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +13 -3
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +10 -7
- data/lib/rubocop/cop/lint/useless_method_definition.rb +12 -4
- data/lib/rubocop/cop/lint/useless_rescue.rb +20 -2
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +9 -1
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +24 -11
- data/lib/rubocop/cop/metrics/block_length.rb +1 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
- data/lib/rubocop/cop/metrics/class_length.rb +1 -0
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +2 -5
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +3 -3
- data/lib/rubocop/cop/migration/department_name.rb +1 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_methods.rb +3 -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 +8 -6
- 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 +56 -25
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
- data/lib/rubocop/cop/mixin/line_length_help.rb +3 -1
- data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
- 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 +3 -3
- data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -2
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +4 -0
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
- data/lib/rubocop/cop/naming/method_name.rb +3 -3
- 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/registry.rb +15 -8
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -11
- data/lib/rubocop/cop/style/accessor_grouping.rb +39 -17
- data/lib/rubocop/cop/style/arguments_forwarding.rb +4 -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 +17 -2
- data/lib/rubocop/cop/style/case_like_if.rb +20 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +4 -11
- data/lib/rubocop/cop/style/class_equality_comparison.rb +42 -9
- data/lib/rubocop/cop/style/collection_compact.rb +4 -1
- data/lib/rubocop/cop/style/command_literal.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/comparable_clamp.rb +125 -0
- data/lib/rubocop/cop/style/concat_array_literals.rb +10 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +6 -12
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- data/lib/rubocop/cop/style/dir_empty.rb +60 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +2 -2
- data/lib/rubocop/cop/style/documentation.rb +11 -5
- data/lib/rubocop/cop/style/documentation_method.rb +10 -4
- data/lib/rubocop/cop/style/double_negation.rb +2 -2
- 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_empty.rb +71 -0
- 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/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +1 -1
- data/lib/rubocop/cop/style/hash_except.rb +4 -4
- data/lib/rubocop/cop/style/hash_like_case.rb +3 -9
- data/lib/rubocop/cop/style/hash_syntax.rb +5 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +108 -15
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
- data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +114 -0
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +2 -2
- 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 +14 -12
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +44 -37
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -0
- data/lib/rubocop/cop/style/min_max.rb +3 -3
- data/lib/rubocop/cop/style/min_max_comparison.rb +11 -1
- data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +0 -4
- data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
- data/lib/rubocop/cop/style/multiline_method_signature.rb +7 -4
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +18 -3
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +13 -12
- data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
- data/lib/rubocop/cop/style/numbered_parameters_limit.rb +11 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -6
- data/lib/rubocop/cop/style/operator_method_call.rb +2 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +29 -19
- 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_condition.rb +18 -3
- data/lib/rubocop/cop/style/redundant_conditional.rb +0 -4
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +16 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
- data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +58 -0
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +179 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +7 -8
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +11 -4
- data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
- data/lib/rubocop/cop/style/redundant_string_escape.rb +3 -4
- data/lib/rubocop/cop/style/require_order.rb +3 -12
- 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/self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/semicolon.rb +24 -2
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -3
- 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/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
- 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/style/unpack_first.rb +3 -3
- data/lib/rubocop/cop/style/word_array.rb +18 -6
- data/lib/rubocop/cop/style/yoda_condition.rb +13 -6
- data/lib/rubocop/cop/style/yoda_expression.rb +11 -2
- data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
- data/lib/rubocop/cop/team.rb +30 -22
- data/lib/rubocop/cop/util.rb +13 -4
- data/lib/rubocop/cop/variable_force/scope.rb +3 -3
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +3 -1
- data/lib/rubocop/cop/variable_force.rb +1 -1
- data/lib/rubocop/cops_documentation_generator.rb +10 -3
- data/lib/rubocop/directive_comment.rb +3 -3
- data/lib/rubocop/ext/comment.rb +18 -0
- data/lib/rubocop/ext/regexp_node.rb +1 -1
- data/lib/rubocop/ext/regexp_parser.rb +1 -1
- data/lib/rubocop/formatter/junit_formatter.rb +4 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/formatter.rb +0 -1
- data/lib/rubocop/options.rb +26 -2
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +6 -4
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/runner.rb +40 -4
- data/lib/rubocop/server/cache.rb +11 -4
- data/lib/rubocop/server/cli.rb +37 -18
- data/lib/rubocop/server/client_command/exec.rb +1 -1
- data/lib/rubocop/server/client_command/start.rb +6 -1
- data/lib/rubocop/server/core.rb +24 -9
- data/lib/rubocop/server/helper.rb +1 -1
- data/lib/rubocop/server/server_command/exec.rb +1 -1
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +12 -0
- metadata +21 -26
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
#
|
7
7
|
# This mixin makes it easier to specify strict offense expectations
|
8
8
|
# in a declarative and visual fashion. Just type out the code that
|
9
|
-
# should generate
|
9
|
+
# should generate an offense, annotate code by writing '^'s
|
10
10
|
# underneath each character that should be highlighted, and follow
|
11
11
|
# the carets with a string (separated by a space) that is the
|
12
12
|
# message of the offense. You can include multiple offenses in
|
@@ -126,7 +126,7 @@ module RuboCop
|
|
126
126
|
@offenses
|
127
127
|
end
|
128
128
|
|
129
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
129
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
130
130
|
def expect_correction(correction, loop: true, source: nil)
|
131
131
|
if source
|
132
132
|
expected_annotations = parse_annotations(source, raise_error: false)
|
@@ -138,6 +138,8 @@ module RuboCop
|
|
138
138
|
|
139
139
|
source = @processed_source.raw_source
|
140
140
|
|
141
|
+
raise 'Use `expect_no_corrections` if the code will not change' if correction == source
|
142
|
+
|
141
143
|
iteration = 0
|
142
144
|
new_source = loop do
|
143
145
|
iteration += 1
|
@@ -157,11 +159,11 @@ module RuboCop
|
|
157
159
|
_investigate(cop, @processed_source)
|
158
160
|
end
|
159
161
|
|
160
|
-
raise '
|
162
|
+
raise 'Expected correction but no corrections were made' if new_source == source
|
161
163
|
|
162
164
|
expect(new_source).to eq(correction)
|
163
165
|
end
|
164
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
|
166
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
165
167
|
|
166
168
|
def expect_no_corrections
|
167
169
|
raise '`expect_no_corrections` must follow `expect_offense`' unless @processed_source
|
data/lib/rubocop/runner.rb
CHANGED
@@ -24,6 +24,27 @@ module RuboCop
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
class << self
|
28
|
+
# @return [Array<#call>]
|
29
|
+
def ruby_extractors
|
30
|
+
@ruby_extractors ||= [default_ruby_extractor]
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [#call]
|
36
|
+
def default_ruby_extractor
|
37
|
+
lambda do |processed_source|
|
38
|
+
[
|
39
|
+
{
|
40
|
+
offset: 0,
|
41
|
+
processed_source: processed_source
|
42
|
+
}
|
43
|
+
]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
27
48
|
# @api private
|
28
49
|
MAX_ITERATIONS = 200
|
29
50
|
|
@@ -319,10 +340,25 @@ module RuboCop
|
|
319
340
|
end
|
320
341
|
|
321
342
|
def inspect_file(processed_source, team = mobilize_team(processed_source))
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
343
|
+
extracted_ruby_sources = extract_ruby_sources(processed_source)
|
344
|
+
offenses = extracted_ruby_sources.flat_map do |extracted_ruby_source|
|
345
|
+
report = team.investigate(
|
346
|
+
extracted_ruby_source[:processed_source],
|
347
|
+
offset: extracted_ruby_source[:offset],
|
348
|
+
original: processed_source
|
349
|
+
)
|
350
|
+
@errors.concat(team.errors)
|
351
|
+
@warnings.concat(team.warnings)
|
352
|
+
report.offenses
|
353
|
+
end
|
354
|
+
[offenses, team.updated_source_file?]
|
355
|
+
end
|
356
|
+
|
357
|
+
def extract_ruby_sources(processed_source)
|
358
|
+
self.class.ruby_extractors.find do |ruby_extractor|
|
359
|
+
result = ruby_extractor.call(processed_source)
|
360
|
+
break result if result
|
361
|
+
end
|
326
362
|
end
|
327
363
|
|
328
364
|
def mobilize_team(processed_source)
|
data/lib/rubocop/server/cache.rb
CHANGED
@@ -57,18 +57,24 @@ module RuboCop
|
|
57
57
|
File.expand_path(File.join(cache_root_dir, 'server'))
|
58
58
|
end
|
59
59
|
|
60
|
+
# rubocop:disable Metrics/MethodLength
|
60
61
|
def cache_root_dir_from_config
|
61
62
|
CacheConfig.root_dir do
|
62
63
|
# `RuboCop::ConfigStore` has heavy dependencies, this is a lightweight implementation
|
63
64
|
# so that only the necessary `CacheRootDirectory` can be obtained.
|
64
|
-
require 'yaml'
|
65
65
|
config_path = ConfigFinder.find_config_path(Dir.pwd)
|
66
|
+
file_contents = File.read(config_path)
|
67
|
+
|
68
|
+
# Returns early if `CacheRootDirectory` is not used before requiring `erb` or `yaml`.
|
69
|
+
next unless file_contents.include?('CacheRootDirectory')
|
66
70
|
|
67
71
|
require 'erb'
|
68
|
-
file_contents = File.read(config_path)
|
69
72
|
yaml_code = ERB.new(file_contents).result
|
70
73
|
|
71
|
-
|
74
|
+
require 'yaml'
|
75
|
+
config_yaml = YAML.safe_load(
|
76
|
+
yaml_code, permitted_classes: [Regexp, Symbol], aliases: true
|
77
|
+
)
|
72
78
|
|
73
79
|
# For compatibility with Ruby 3.0 or lower.
|
74
80
|
if Gem::Version.new(Psych::VERSION) < Gem::Version.new('4.0.0')
|
@@ -78,6 +84,7 @@ module RuboCop
|
|
78
84
|
config_yaml&.dig('AllCops', 'CacheRootDirectory')
|
79
85
|
end
|
80
86
|
end
|
87
|
+
# rubocop:enable Metrics/MethodLength
|
81
88
|
|
82
89
|
def port_path
|
83
90
|
dir.join('port')
|
@@ -109,7 +116,7 @@ module RuboCop
|
|
109
116
|
|
110
117
|
def pid_running?
|
111
118
|
Process.kill(0, pid_path.read.to_i) == 1
|
112
|
-
rescue Errno::ESRCH, Errno::ENOENT
|
119
|
+
rescue Errno::ESRCH, Errno::ENOENT, Errno::EACCES
|
113
120
|
false
|
114
121
|
end
|
115
122
|
|
data/lib/rubocop/server/cli.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'rainbow'
|
4
3
|
require_relative '../arguments_env'
|
5
4
|
require_relative '../arguments_file'
|
6
5
|
|
@@ -23,15 +22,21 @@ module RuboCop
|
|
23
22
|
STATUS_ERROR = 2
|
24
23
|
|
25
24
|
SERVER_OPTIONS = %w[
|
26
|
-
--server
|
25
|
+
--server
|
26
|
+
--no-server
|
27
|
+
--server-status
|
28
|
+
--restart-server
|
29
|
+
--start-server
|
30
|
+
--stop-server
|
31
|
+
--no-detach
|
27
32
|
].freeze
|
28
33
|
EXCLUSIVE_OPTIONS = (SERVER_OPTIONS - %w[--server --no-server]).freeze
|
34
|
+
NO_DETACH_OPTIONS = %w[--server --start-server --restart-server].freeze
|
29
35
|
|
30
36
|
def initialize
|
31
37
|
@exit = false
|
32
38
|
end
|
33
39
|
|
34
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
35
40
|
def run(argv = ARGV)
|
36
41
|
unless Server.support_server?
|
37
42
|
return error('RuboCop server is not supported by this Ruby.') if use_server_option?(argv)
|
@@ -40,16 +45,34 @@ module RuboCop
|
|
40
45
|
end
|
41
46
|
|
42
47
|
Cache.cache_root_path = fetch_cache_root_path_from(argv)
|
43
|
-
deleted_server_arguments = delete_server_argument_from(argv)
|
44
48
|
|
45
|
-
|
46
|
-
|
49
|
+
process_arguments(argv)
|
50
|
+
end
|
51
|
+
|
52
|
+
def exit?
|
53
|
+
@exit
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
59
|
+
def process_arguments(argv)
|
60
|
+
server_arguments = delete_server_argument_from(argv)
|
61
|
+
|
62
|
+
detach = !server_arguments.delete('--no-detach')
|
63
|
+
|
64
|
+
if server_arguments.size >= 2
|
65
|
+
return error("#{server_arguments.join(', ')} cannot be specified together.")
|
47
66
|
end
|
48
67
|
|
49
|
-
server_command =
|
68
|
+
server_command = server_arguments.first
|
69
|
+
|
70
|
+
unless detach || NO_DETACH_OPTIONS.include?(server_command)
|
71
|
+
return error("#{server_command} cannot be combined with --no-detach.")
|
72
|
+
end
|
50
73
|
|
51
74
|
if EXCLUSIVE_OPTIONS.include?(server_command) && argv.count > allowed_option_count
|
52
|
-
return error("#{server_command} cannot be combined with
|
75
|
+
return error("#{server_command} cannot be combined with #{argv[0]}.")
|
53
76
|
end
|
54
77
|
|
55
78
|
if server_command.nil?
|
@@ -57,23 +80,17 @@ module RuboCop
|
|
57
80
|
ArgumentsFile.read_as_arguments.delete('--server')
|
58
81
|
end
|
59
82
|
|
60
|
-
run_command(server_command)
|
83
|
+
run_command(server_command, detach: detach)
|
61
84
|
|
62
85
|
STATUS_SUCCESS
|
63
86
|
end
|
64
87
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
65
88
|
|
66
|
-
def exit?
|
67
|
-
@exit
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
89
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength:
|
73
|
-
def run_command(server_command)
|
90
|
+
def run_command(server_command, detach:)
|
74
91
|
case server_command
|
75
92
|
when '--server'
|
76
|
-
Server::ClientCommand::Start.new.run unless Server.running?
|
93
|
+
Server::ClientCommand::Start.new(detach: detach).run unless Server.running?
|
77
94
|
when '--no-server'
|
78
95
|
Server::ClientCommand::Stop.new.run if Server.running?
|
79
96
|
when '--restart-server'
|
@@ -81,7 +98,7 @@ module RuboCop
|
|
81
98
|
Server::ClientCommand::Restart.new.run
|
82
99
|
when '--start-server'
|
83
100
|
@exit = true
|
84
|
-
Server::ClientCommand::Start.new.run
|
101
|
+
Server::ClientCommand::Start.new(detach: detach).run
|
85
102
|
when '--stop-server'
|
86
103
|
@exit = true
|
87
104
|
Server::ClientCommand::Stop.new.run
|
@@ -118,6 +135,8 @@ module RuboCop
|
|
118
135
|
end
|
119
136
|
|
120
137
|
def error(message)
|
138
|
+
require 'rainbow'
|
139
|
+
|
121
140
|
@exit = true
|
122
141
|
warn Rainbow(message).red
|
123
142
|
|
@@ -15,6 +15,11 @@ module RuboCop
|
|
15
15
|
# This class is a client command to start server process.
|
16
16
|
# @api private
|
17
17
|
class Start < Base
|
18
|
+
def initialize(detach: true)
|
19
|
+
@detach = detach
|
20
|
+
super()
|
21
|
+
end
|
22
|
+
|
18
23
|
def run
|
19
24
|
if Server.running?
|
20
25
|
warn "RuboCop server (#{Cache.pid_path.read}) is already running."
|
@@ -34,7 +39,7 @@ module RuboCop
|
|
34
39
|
host = ENV.fetch('RUBOCOP_SERVER_HOST', '127.0.0.1')
|
35
40
|
port = ENV.fetch('RUBOCOP_SERVER_PORT', 0)
|
36
41
|
|
37
|
-
Server::Core.new.start(host, port)
|
42
|
+
Server::Core.new.start(host, port, detach: @detach)
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
data/lib/rubocop/server/core.rb
CHANGED
@@ -27,31 +27,46 @@ module RuboCop
|
|
27
27
|
self.class.token
|
28
28
|
end
|
29
29
|
|
30
|
-
def start(host, port)
|
30
|
+
def start(host, port, detach: true)
|
31
31
|
$PROGRAM_NAME = "rubocop --server #{Cache.project_dir}"
|
32
32
|
|
33
|
-
|
33
|
+
require_relative '../../rubocop'
|
34
34
|
start_server(host, port)
|
35
35
|
|
36
|
-
|
36
|
+
return unless server_mode?
|
37
|
+
|
38
|
+
detach ? detach_server : run_server
|
37
39
|
end
|
38
40
|
|
39
41
|
private
|
40
42
|
|
41
|
-
def
|
42
|
-
|
43
|
+
def detach_server
|
44
|
+
write_port_and_token_files
|
43
45
|
|
44
46
|
pid = fork do
|
45
47
|
Process.daemon(true)
|
46
48
|
$stderr.reopen(Cache.stderr_path, 'w')
|
47
|
-
|
48
|
-
read_socket(@server.accept) until @server.closed?
|
49
|
-
end
|
49
|
+
process_input
|
50
50
|
end
|
51
51
|
|
52
52
|
Process.waitpid(pid)
|
53
53
|
end
|
54
54
|
|
55
|
+
def write_port_and_token_files
|
56
|
+
Cache.write_port_and_token_files(port: @server.addr[1], token: token)
|
57
|
+
end
|
58
|
+
|
59
|
+
def process_input
|
60
|
+
Cache.write_pid_file do
|
61
|
+
read_socket(@server.accept) until @server.closed?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def run_server
|
66
|
+
write_port_and_token_files
|
67
|
+
process_input
|
68
|
+
end
|
69
|
+
|
55
70
|
def server_mode?
|
56
71
|
true
|
57
72
|
end
|
@@ -85,7 +100,7 @@ module RuboCop
|
|
85
100
|
|
86
101
|
def use_json_format?
|
87
102
|
return true if ARGV.include?('--format=json') || ARGV.include?('--format=j')
|
88
|
-
return false unless (index = ARGV.index('--format'))
|
103
|
+
return false unless (index = ARGV.index('--format') || ARGV.index('-f'))
|
89
104
|
|
90
105
|
format = ARGV[index + 1]
|
91
106
|
|
@@ -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
@@ -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'
|
@@ -101,6 +102,7 @@ require_relative 'rubocop/cop/mixin/hash_shorthand_syntax'
|
|
101
102
|
require_relative 'rubocop/cop/mixin/method_complexity'
|
102
103
|
require_relative 'rubocop/cop/mixin/method_preference'
|
103
104
|
require_relative 'rubocop/cop/mixin/min_body_length'
|
105
|
+
require_relative 'rubocop/cop/mixin/min_branches_count'
|
104
106
|
require_relative 'rubocop/cop/mixin/multiline_element_indentation'
|
105
107
|
require_relative 'rubocop/cop/mixin/multiline_element_line_breaks'
|
106
108
|
require_relative 'rubocop/cop/mixin/multiline_expression_indentation'
|
@@ -166,6 +168,7 @@ require_relative 'rubocop/cop/bundler/ordered_gems'
|
|
166
168
|
|
167
169
|
require_relative 'rubocop/cop/gemspec/dependency_version'
|
168
170
|
require_relative 'rubocop/cop/gemspec/deprecated_attribute_assignment'
|
171
|
+
require_relative 'rubocop/cop/gemspec/development_dependencies'
|
169
172
|
require_relative 'rubocop/cop/gemspec/duplicated_assignment'
|
170
173
|
require_relative 'rubocop/cop/gemspec/ordered_dependencies'
|
171
174
|
require_relative 'rubocop/cop/gemspec/require_mfa'
|
@@ -296,6 +299,7 @@ require_relative 'rubocop/cop/lint/duplicate_case_condition'
|
|
296
299
|
require_relative 'rubocop/cop/lint/duplicate_elsif_condition'
|
297
300
|
require_relative 'rubocop/cop/lint/duplicate_hash_key'
|
298
301
|
require_relative 'rubocop/cop/lint/duplicate_magic_comment'
|
302
|
+
require_relative 'rubocop/cop/lint/duplicate_match_pattern'
|
299
303
|
require_relative 'rubocop/cop/lint/duplicate_methods'
|
300
304
|
require_relative 'rubocop/cop/lint/duplicate_regexp_character_class_element'
|
301
305
|
require_relative 'rubocop/cop/lint/duplicate_require'
|
@@ -414,6 +418,7 @@ require_relative 'rubocop/cop/metrics/abc_size'
|
|
414
418
|
require_relative 'rubocop/cop/metrics/block_length'
|
415
419
|
require_relative 'rubocop/cop/metrics/block_nesting'
|
416
420
|
require_relative 'rubocop/cop/metrics/class_length'
|
421
|
+
require_relative 'rubocop/cop/metrics/collection_literal_length'
|
417
422
|
require_relative 'rubocop/cop/metrics/method_length'
|
418
423
|
require_relative 'rubocop/cop/metrics/module_length'
|
419
424
|
require_relative 'rubocop/cop/metrics/parameter_lists'
|
@@ -471,13 +476,16 @@ require_relative 'rubocop/cop/style/combinable_loops'
|
|
471
476
|
require_relative 'rubocop/cop/style/command_literal'
|
472
477
|
require_relative 'rubocop/cop/style/comment_annotation'
|
473
478
|
require_relative 'rubocop/cop/style/commented_keyword'
|
479
|
+
require_relative 'rubocop/cop/style/comparable_clamp'
|
474
480
|
require_relative 'rubocop/cop/style/concat_array_literals'
|
475
481
|
require_relative 'rubocop/cop/style/conditional_assignment'
|
476
482
|
require_relative 'rubocop/cop/style/constant_visibility'
|
477
483
|
require_relative 'rubocop/cop/style/copyright'
|
484
|
+
require_relative 'rubocop/cop/style/data_inheritance'
|
478
485
|
require_relative 'rubocop/cop/style/date_time'
|
479
486
|
require_relative 'rubocop/cop/style/def_with_parentheses'
|
480
487
|
require_relative 'rubocop/cop/style/dir'
|
488
|
+
require_relative 'rubocop/cop/style/dir_empty'
|
481
489
|
require_relative 'rubocop/cop/style/disable_cops_within_source_code_directive'
|
482
490
|
require_relative 'rubocop/cop/style/documentation_method'
|
483
491
|
require_relative 'rubocop/cop/style/documentation'
|
@@ -503,6 +511,7 @@ require_relative 'rubocop/cop/style/expand_path_arguments'
|
|
503
511
|
require_relative 'rubocop/cop/style/explicit_block_argument'
|
504
512
|
require_relative 'rubocop/cop/style/exponential_notation'
|
505
513
|
require_relative 'rubocop/cop/style/fetch_env_var'
|
514
|
+
require_relative 'rubocop/cop/style/file_empty'
|
506
515
|
require_relative 'rubocop/cop/style/file_read'
|
507
516
|
require_relative 'rubocop/cop/style/file_write'
|
508
517
|
require_relative 'rubocop/cop/style/float_division'
|
@@ -532,6 +541,7 @@ require_relative 'rubocop/cop/style/in_pattern_then'
|
|
532
541
|
require_relative 'rubocop/cop/style/infinite_loop'
|
533
542
|
require_relative 'rubocop/cop/style/inverse_methods'
|
534
543
|
require_relative 'rubocop/cop/style/inline_comment'
|
544
|
+
require_relative 'rubocop/cop/style/invertible_unless_condition'
|
535
545
|
require_relative 'rubocop/cop/style/ip_addresses'
|
536
546
|
require_relative 'rubocop/cop/style/keyword_parameters_order'
|
537
547
|
require_relative 'rubocop/cop/style/lambda'
|
@@ -553,7 +563,9 @@ require_relative 'rubocop/cop/style/redundant_double_splat_hash_braces'
|
|
553
563
|
require_relative 'rubocop/cop/style/redundant_each'
|
554
564
|
require_relative 'rubocop/cop/style/redundant_fetch_block'
|
555
565
|
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
566
|
+
require_relative 'rubocop/cop/style/redundant_heredoc_delimiter_quotes'
|
556
567
|
require_relative 'rubocop/cop/style/redundant_initialize'
|
568
|
+
require_relative 'rubocop/cop/style/redundant_line_continuation'
|
557
569
|
require_relative 'rubocop/cop/style/redundant_self_assignment'
|
558
570
|
require_relative 'rubocop/cop/style/redundant_self_assignment_branch'
|
559
571
|
require_relative 'rubocop/cop/style/require_order'
|