sonicop 26.8.111 → 26.8.113
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/CONFORMANCE.md +64 -31
- data/Cargo.lock +94 -19
- data/Cargo.toml +13 -8
- data/NOTICE +15 -3
- data/README.ja.md +145 -57
- data/README.md +140 -48
- data/build.rs +155 -0
- data/lib/sonicop/runner.rb +7 -1
- data/lib/sonicop/version.rb +1 -1
- data/src/cli.rs +216 -45
- data/src/config/inheritance.rs +637 -64
- data/src/config/mod.rs +130 -1
- data/src/config/paths.rs +550 -48
- data/src/cop_name.rs +18 -1
- data/src/diagnostic.rs +168 -3
- data/src/directives.rs +398 -77
- data/src/display_width.rs +82 -42
- data/src/display_width_table.rs +506 -0
- data/src/engine.rs +1532 -51
- data/src/formatter.rs +10 -1
- data/src/lib.rs +2 -0
- data/src/main.rs +112 -1
- data/src/nul_bytes.rs +245 -47
- data/src/parser.rs +37 -0
- data/src/profile.rs +174 -24
- data/src/ruby_version.rs +167 -21
- data/src/rules/bundler/duplicated_group.rs +3 -2
- data/src/rules/bundler/gem_comment.rs +5 -4
- data/src/rules/gemspec/attribute_assignment.rs +4 -3
- data/src/rules/gemspec/deprecated_attribute_assignment.rs +7 -6
- data/src/rules/gemspec/duplicated_assignment.rs +4 -3
- data/src/rules/gemspec/require_mfa.rs +10 -9
- data/src/rules/gemspec/required_ruby_version.rs +3 -2
- data/src/rules/gemspec/support.rs +28 -8
- data/src/rules/layout/access_modifier_indentation.rs +13 -6
- data/src/rules/layout/argument_alignment.rs +19 -7
- data/src/rules/layout/array_alignment.rs +1 -2
- data/src/rules/layout/block_alignment.rs +74 -30
- data/src/rules/layout/block_end_newline.rs +5 -5
- data/src/rules/layout/class_structure.rs +13 -4
- data/src/rules/layout/closing_heredoc_indentation.rs +24 -5
- data/src/rules/layout/closing_parenthesis_indentation.rs +3 -3
- data/src/rules/layout/comment_indentation.rs +2 -1
- data/src/rules/layout/condition_position.rs +3 -2
- data/src/rules/layout/def_end_alignment.rs +10 -6
- data/src/rules/layout/dot_position.rs +1 -2
- data/src/rules/layout/else_alignment.rs +24 -14
- data/src/rules/layout/empty_line_after_guard_clause.rs +8 -7
- data/src/rules/layout/empty_line_after_multiline_condition.rs +5 -5
- data/src/rules/layout/empty_line_between_defs.rs +8 -6
- data/src/rules/layout/empty_lines_around_access_modifier.rs +22 -10
- data/src/rules/layout/empty_lines_around_arguments.rs +4 -4
- data/src/rules/layout/empty_lines_around_body.rs +8 -2
- data/src/rules/layout/empty_lines_around_exception_handling_keywords.rs +1 -2
- data/src/rules/layout/empty_lines_around_method_body.rs +3 -2
- data/src/rules/layout/end_alignment.rs +32 -7
- data/src/rules/layout/end_of_line.rs +14 -1
- data/src/rules/layout/extra_spacing.rs +9 -11
- data/src/rules/layout/first_array_element_indentation.rs +1 -2
- data/src/rules/layout/first_hash_element_indentation.rs +8 -6
- data/src/rules/layout/hash_alignment.rs +113 -19
- data/src/rules/layout/heredoc_argument_closing_parenthesis.rs +6 -5
- data/src/rules/layout/heredoc_indentation.rs +4 -3
- data/src/rules/layout/indentation_style.rs +6 -4
- data/src/rules/layout/indentation_width.rs +76 -16
- data/src/rules/layout/initial_indentation.rs +18 -5
- data/src/rules/layout/line_continuation_leading_space.rs +4 -3
- data/src/rules/layout/line_continuation_spacing.rs +4 -3
- data/src/rules/layout/line_length.rs +417 -43
- data/src/rules/layout/mod.rs +1 -1
- data/src/rules/layout/multiline_assignment_layout.rs +20 -3
- data/src/rules/layout/multiline_block_layout.rs +1 -2
- data/src/rules/layout/multiline_expression.rs +60 -31
- data/src/rules/layout/multiline_hash_brace_layout.rs +4 -3
- data/src/rules/layout/multiline_method_call_indentation.rs +1 -1
- data/src/rules/layout/multiline_operation_indentation.rs +3 -3
- data/src/rules/layout/redundant_line_break.rs +16 -5
- data/src/rules/layout/rescue_ensure_alignment.rs +20 -12
- data/src/rules/layout/single_line_block_chain.rs +13 -4
- data/src/rules/layout/space_around_block_parameters.rs +16 -2
- data/src/rules/layout/space_around_equals_in_parameter_default.rs +1 -2
- data/src/rules/layout/space_around_keyword.rs +22 -4
- data/src/rules/layout/space_around_operators.rs +34 -2
- data/src/rules/layout/space_before_brackets.rs +13 -6
- data/src/rules/layout/space_before_comma.rs +3 -2
- data/src/rules/layout/space_inside_array_literal_brackets.rs +25 -10
- data/src/rules/layout/space_inside_array_percent_literal.rs +7 -1
- data/src/rules/layout/space_inside_parens.rs +170 -87
- data/src/rules/layout/space_inside_range_literal.rs +53 -19
- data/src/rules/layout/space_inside_reference_brackets.rs +65 -3
- data/src/rules/layout/space_inside_string_interpolation.rs +147 -48
- data/src/rules/layout/support.rs +172 -26
- data/src/rules/layout/tokens.rs +47 -7
- data/src/rules/layout/trailing_whitespace.rs +5 -2
- data/src/rules/lint/access_modifier.rs +50 -5
- data/src/rules/lint/ambiguity.rs +97 -7
- data/src/rules/lint/ambiguous_block_association.rs +29 -12
- data/src/rules/lint/ambiguous_operator.rs +8 -0
- data/src/rules/lint/ambiguous_operator_precedence.rs +18 -1
- data/src/rules/lint/ambiguous_range.rs +15 -1
- data/src/rules/lint/ambiguous_regexp_literal.rs +40 -1
- data/src/rules/lint/array_literal_in_regexp.rs +13 -5
- data/src/rules/lint/assignment_in_condition.rs +3 -2
- data/src/rules/lint/blocks.rs +2 -1
- data/src/rules/lint/boolean_symbol.rs +4 -4
- data/src/rules/lint/constant_definition_in_block.rs +1 -2
- data/src/rules/lint/constant_reassignment.rs +9 -13
- data/src/rules/lint/constant_resolution.rs +8 -0
- data/src/rules/lint/cop_directives.rs +28 -4
- data/src/rules/lint/debugger.rs +59 -9
- data/src/rules/lint/deprecated_open_ssl_constant.rs +1 -2
- data/src/rules/lint/disjunctive_assignment_in_constructor.rs +2 -2
- data/src/rules/lint/duplicate_branch.rs +16 -6
- data/src/rules/lint/duplicate_case_condition.rs +5 -5
- data/src/rules/lint/duplicate_hash_key.rs +8 -4
- data/src/rules/lint/duplicate_match_pattern.rs +7 -5
- data/src/rules/lint/duplicate_methods.rs +133 -54
- data/src/rules/lint/duplicate_require.rs +1 -2
- data/src/rules/lint/duplicate_set_element.rs +19 -5
- data/src/rules/lint/empty_conditional_body.rs +19 -3
- data/src/rules/lint/empty_expression.rs +16 -1
- data/src/rules/lint/empty_in_pattern.rs +3 -2
- data/src/rules/lint/empty_when.rs +4 -4
- data/src/rules/lint/ensure_return.rs +3 -2
- data/src/rules/lint/float_comparison.rs +8 -6
- data/src/rules/lint/flow.rs +8 -5
- data/src/rules/lint/format_parameter_mismatch.rs +4 -3
- data/src/rules/lint/hash_compare_by_identity.rs +5 -4
- data/src/rules/lint/heredoc_method_call_position.rs +3 -2
- data/src/rules/lint/implicit_string_concatenation.rs +33 -3
- data/src/rules/lint/ineffective_access_modifier.rs +5 -4
- data/src/rules/lint/inherit_exception.rs +4 -3
- data/src/rules/lint/literal_as_condition.rs +51 -31
- data/src/rules/lint/literal_assignment_in_condition.rs +4 -3
- data/src/rules/lint/literal_in_interpolation.rs +66 -5
- data/src/rules/lint/literals.rs +10 -8
- data/src/rules/lint/missing_cop_enable_directive.rs +95 -18
- data/src/rules/lint/mod.rs +1 -0
- data/src/rules/lint/nested_method_definition.rs +36 -11
- data/src/rules/lint/nil_receiver.rs +420 -0
- data/src/rules/lint/no_return_in_begin_end_blocks.rs +2 -2
- data/src/rules/lint/node_equality.rs +8 -5
- data/src/rules/lint/non_atomic_file_operation.rs +9 -3
- data/src/rules/lint/non_deterministic_require_order.rs +5 -3
- data/src/rules/lint/non_local_exit_from_iterator.rs +22 -9
- data/src/rules/lint/number_conversion.rs +1 -1
- data/src/rules/lint/out_of_range_regexp_ref.rs +6 -4
- data/src/rules/lint/parentheses_as_grouped_expression.rs +5 -0
- data/src/rules/lint/redundant_cop_enable_directive.rs +3 -1
- data/src/rules/lint/redundant_dir_glob_sort.rs +1 -2
- data/src/rules/lint/redundant_safe_navigation.rs +47 -22
- data/src/rules/lint/redundant_splat_expansion.rs +4 -2
- data/src/rules/lint/redundant_string_coercion.rs +3 -2
- data/src/rules/lint/redundant_type_conversion.rs +16 -4
- data/src/rules/lint/regexp.rs +1 -3
- data/src/rules/lint/regexp_source.rs +2 -2
- data/src/rules/lint/regexp_tree.rs +38 -5
- data/src/rules/lint/require_range_parentheses.rs +5 -5
- data/src/rules/lint/rescue_exception.rs +4 -3
- data/src/rules/lint/rescue_type.rs +3 -2
- data/src/rules/lint/return_in_void_context.rs +8 -3
- data/src/rules/lint/safe_navigation_chain.rs +47 -11
- data/src/rules/lint/self_assignment.rs +20 -2
- data/src/rules/lint/shadowed_argument.rs +2 -2
- data/src/rules/lint/shadowed_exception.rs +2 -2
- data/src/rules/lint/suppressed_exception.rs +21 -3
- data/src/rules/lint/suppressed_exception_in_number_conversion.rs +4 -3
- data/src/rules/lint/symbol_conversion.rs +56 -8
- data/src/rules/lint/syntax.rs +195 -5
- data/src/rules/lint/top_level_return_with_argument.rs +11 -1
- data/src/rules/lint/triple_quotes.rs +3 -2
- data/src/rules/lint/unescaped_bracket_in_regexp.rs +1 -1
- data/src/rules/lint/unexpected_block_arity.rs +23 -5
- data/src/rules/lint/unified_integer.rs +18 -12
- data/src/rules/lint/unmodified_reduce_accumulator.rs +36 -7
- data/src/rules/lint/unreachable_code.rs +4 -4
- data/src/rules/lint/unreachable_loop.rs +26 -10
- data/src/rules/lint/unreachable_pattern_branch.rs +7 -5
- data/src/rules/lint/unused_block_argument.rs +2 -2
- data/src/rules/lint/unused_method_argument.rs +1 -2
- data/src/rules/lint/useless_assignment.rs +3 -2
- data/src/rules/lint/useless_constant_scoping.rs +3 -2
- data/src/rules/lint/useless_else_without_rescue.rs +4 -3
- data/src/rules/lint/useless_rescue.rs +5 -4
- data/src/rules/lint/useless_ruby2_keywords.rs +2 -1
- data/src/rules/lint/useless_setter_call.rs +5 -4
- data/src/rules/lint/useless_times.rs +4 -3
- data/src/rules/lint/variable_force.rs +307 -79
- data/src/rules/lint/void.rs +32 -20
- data/src/rules/metrics/abc_size.rs +197 -7
- data/src/rules/metrics/block_length.rs +19 -10
- data/src/rules/metrics/block_nesting.rs +1 -2
- data/src/rules/metrics/class_length.rs +16 -4
- data/src/rules/metrics/collection_literal_length.rs +2 -1
- data/src/rules/metrics/complexity.rs +52 -14
- data/src/rules/metrics/fragments.rs +10 -14
- data/src/rules/metrics/locals.rs +35 -14
- data/src/rules/metrics/method_length.rs +14 -6
- data/src/rules/metrics/parameter_lists.rs +7 -6
- data/src/rules/metrics/perceived_complexity.rs +1 -3
- data/src/rules/metrics/support.rs +94 -4
- data/src/rules/mod.rs +525 -80
- data/src/rules/naming/ascii_identifiers.rs +3 -3
- data/src/rules/naming/binary_operator_parameter_name.rs +5 -4
- data/src/rules/naming/block_forwarding.rs +9 -8
- data/src/rules/naming/constant_name.rs +56 -18
- data/src/rules/naming/file_name.rs +174 -43
- data/src/rules/naming/method_name.rs +8 -1
- data/src/rules/naming/predicate_method.rs +42 -14
- data/src/rules/naming/predicate_prefix.rs +70 -4
- data/src/rules/naming/rescued_exceptions_variable_name.rs +14 -11
- data/src/rules/naming/support.rs +54 -295
- data/src/rules/naming/variable_name.rs +17 -4
- data/src/rules/naming/variable_number.rs +9 -10
- data/src/rules/node_ext.rs +1 -1
- data/src/rules/ruby_literal.rs +8 -3
- data/src/rules/security/compound_hash.rs +3 -2
- data/src/rules/security/open.rs +5 -4
- data/src/rules/send_node.rs +134 -0
- data/src/rules/single_line.rs +4 -4
- data/src/rules/style/access_modifier_declarations.rs +76 -22
- data/src/rules/style/accessor_grouping.rs +44 -6
- data/src/rules/style/alias.rs +4 -3
- data/src/rules/style/and_or.rs +2 -2
- data/src/rules/style/arguments_forwarding.rs +5 -5
- data/src/rules/style/array_coercion.rs +5 -5
- data/src/rules/style/array_first_last.rs +19 -4
- data/src/rules/style/array_intersect.rs +26 -8
- data/src/rules/style/array_intersect_with_single_element.rs +1 -1
- data/src/rules/style/ascii_comments.rs +2 -0
- data/src/rules/style/attr.rs +1 -1
- data/src/rules/style/auto_resource_cleanup.rs +1 -1
- data/src/rules/style/bitwise_predicate.rs +2 -2
- data/src/rules/style/block_args.rs +1 -1
- data/src/rules/style/block_comments.rs +11 -2
- data/src/rules/style/block_delimiters.rs +154 -10
- data/src/rules/style/case_equality.rs +7 -2
- data/src/rules/style/case_like_if.rs +26 -2
- data/src/rules/style/class_and_module_children.rs +162 -10
- data/src/rules/style/class_methods.rs +1 -1
- data/src/rules/style/class_methods_definitions.rs +9 -0
- data/src/rules/style/collection_compact.rs +4 -4
- data/src/rules/style/combinable_defined.rs +2 -2
- data/src/rules/style/combinable_loops.rs +9 -11
- data/src/rules/style/comments.rs +6 -3
- data/src/rules/style/comparable_clamp.rs +2 -2
- data/src/rules/style/concat_array_literals.rs +3 -3
- data/src/rules/style/conditional.rs +12 -1
- data/src/rules/style/conditional_assignment.rs +133 -4
- data/src/rules/style/constant_visibility.rs +3 -3
- data/src/rules/style/copyright.rs +64 -3
- data/src/rules/style/data_inheritance.rs +1 -1
- data/src/rules/style/def_with_parentheses.rs +1 -1
- data/src/rules/style/document_dynamic_eval_definition.rs +50 -12
- data/src/rules/style/documentation.rs +1 -1
- data/src/rules/style/each_for_simple_loop.rs +1 -1
- data/src/rules/style/each_with_object.rs +4 -4
- data/src/rules/style/empty_block_parameter.rs +1 -1
- data/src/rules/style/empty_case_condition.rs +6 -6
- data/src/rules/style/empty_class_definition.rs +1 -1
- data/src/rules/style/empty_else.rs +1 -1
- data/src/rules/style/empty_heredoc.rs +14 -1
- data/src/rules/style/empty_lambda_parameter.rs +1 -1
- data/src/rules/style/empty_literal.rs +34 -2
- data/src/rules/style/empty_method.rs +1 -1
- data/src/rules/style/empty_string_inside_interpolation.rs +1 -1
- data/src/rules/style/endless.rs +11 -3
- data/src/rules/style/env_home.rs +1 -1
- data/src/rules/style/eval_with_location.rs +6 -0
- data/src/rules/style/even_odd.rs +1 -1
- data/src/rules/style/exact_regexp_match.rs +1 -1
- data/src/rules/style/expand_path_arguments.rs +3 -3
- data/src/rules/style/explicit_block_argument.rs +3 -3
- data/src/rules/style/file_open.rs +5 -0
- data/src/rules/style/file_open_call.rs +3 -3
- data/src/rules/style/file_write.rs +1 -1
- data/src/rules/style/for.rs +1 -1
- data/src/rules/style/format_sequences.rs +6 -0
- data/src/rules/style/format_string.rs +75 -11
- data/src/rules/style/format_string_token.rs +61 -12
- data/src/rules/style/frozen_string_literal_comment.rs +62 -4
- data/src/rules/style/guard_clause.rs +8 -7
- data/src/rules/style/hash_as_last_array_item.rs +4 -4
- data/src/rules/style/hash_each_methods.rs +1 -1
- data/src/rules/style/hash_like_case.rs +8 -8
- data/src/rules/style/hash_lookup_method.rs +43 -3
- data/src/rules/style/hash_subset.rs +16 -10
- data/src/rules/style/hash_syntax.rs +609 -71
- data/src/rules/style/hash_transform.rs +20 -18
- data/src/rules/style/hash_transform_keys.rs +7 -0
- data/src/rules/style/hash_transform_values.rs +7 -0
- data/src/rules/style/identical_conditional_branches.rs +54 -5
- data/src/rules/style/if_inside_else.rs +19 -3
- data/src/rules/style/if_unless_modifier.rs +13 -14
- data/src/rules/style/if_with_boolean_literal_branches.rs +1 -1
- data/src/rules/style/if_with_semicolon.rs +7 -1
- data/src/rules/style/implicit_runtime_error.rs +7 -0
- data/src/rules/style/in_pattern_then.rs +2 -2
- data/src/rules/style/infinite_loop.rs +6 -0
- data/src/rules/style/inline_comment.rs +4 -1
- data/src/rules/style/inverse_methods.rs +12 -2
- data/src/rules/style/invertible_unless_condition.rs +12 -12
- data/src/rules/style/it_block_parameter.rs +5 -2
- data/src/rules/style/keyword_arguments_merging.rs +8 -2
- data/src/rules/style/keyword_parameters_order.rs +1 -1
- data/src/rules/style/line_end_concatenation.rs +1 -1
- data/src/rules/style/magic_comment_format.rs +14 -6
- data/src/rules/style/map_chain.rs +1 -1
- data/src/rules/style/map_compact_with_conditional_block.rs +3 -3
- data/src/rules/style/map_into_array.rs +7 -7
- data/src/rules/style/map_join.rs +3 -3
- data/src/rules/style/method_call_with_args_parentheses.rs +7 -7
- data/src/rules/style/method_call_without_args_parentheses.rs +2 -2
- data/src/rules/style/method_def_parentheses.rs +2 -3
- data/src/rules/style/min_max.rs +3 -3
- data/src/rules/style/min_max_comparison.rs +2 -2
- data/src/rules/style/missing_else.rs +1 -1
- data/src/rules/style/missing_respond_to_missing.rs +1 -1
- data/src/rules/style/mixin_grouping.rs +6 -7
- data/src/rules/style/multiline_block_chain.rs +6 -8
- data/src/rules/style/multiline_if_then.rs +1 -1
- data/src/rules/style/multiline_in_pattern_then.rs +16 -3
- data/src/rules/style/multiline_method_signature.rs +1 -1
- data/src/rules/style/multiline_when_then.rs +2 -2
- data/src/rules/style/mutable_constant.rs +31 -35
- data/src/rules/style/negated_if.rs +2 -2
- data/src/rules/style/negated_if_else_condition.rs +5 -3
- data/src/rules/style/negated_while.rs +1 -1
- data/src/rules/style/negative_array_index.rs +25 -3
- data/src/rules/style/nested_modifier.rs +1 -1
- data/src/rules/style/nested_parenthesized_calls.rs +2 -2
- data/src/rules/style/nested_ternary_operator.rs +2 -2
- data/src/rules/style/next.rs +12 -12
- data/src/rules/style/nil_lambda.rs +2 -2
- data/src/rules/style/nodes.rs +21 -0
- data/src/rules/style/non_nil_check.rs +82 -2
- data/src/rules/style/numbered_parameters.rs +4 -1
- data/src/rules/style/numbered_parameters_limit.rs +2 -2
- data/src/rules/style/numeric_literals.rs +17 -1
- data/src/rules/style/numeric_predicate.rs +25 -6
- data/src/rules/style/one_line_conditional.rs +24 -7
- data/src/rules/style/operator_method_call.rs +5 -0
- data/src/rules/style/optional_arguments.rs +1 -1
- data/src/rules/style/or_assignment.rs +1 -1
- data/src/rules/style/parallel_assignment.rs +20 -9
- data/src/rules/style/parens.rs +1 -1
- data/src/rules/style/parentheses_around_condition.rs +3 -3
- data/src/rules/style/partition_instead_of_double_select.rs +3 -3
- data/src/rules/style/percent.rs +18 -9
- data/src/rules/style/percent_q_literals.rs +40 -7
- data/src/rules/style/preferred_hash_methods.rs +1 -1
- data/src/rules/style/quoted_symbols.rs +6 -0
- data/src/rules/style/raise_args.rs +26 -20
- data/src/rules/style/random_with_offset.rs +1 -1
- data/src/rules/style/reduce_to_hash.rs +6 -6
- data/src/rules/style/redundant_argument.rs +1 -1
- data/src/rules/style/redundant_assignment.rs +5 -5
- data/src/rules/style/redundant_begin.rs +5 -3
- data/src/rules/style/redundant_capital_w.rs +3 -2
- data/src/rules/style/redundant_condition.rs +17 -8
- data/src/rules/style/redundant_current_directory_in_path.rs +2 -2
- data/src/rules/style/redundant_double_splat_hash_braces.rs +15 -5
- data/src/rules/style/redundant_exception.rs +3 -1
- data/src/rules/style/redundant_file_extension_in_require.rs +2 -2
- data/src/rules/style/redundant_format.rs +98 -20
- data/src/rules/style/redundant_freeze.rs +1 -1
- data/src/rules/style/redundant_heredoc_delimiter_quotes.rs +1 -1
- data/src/rules/style/redundant_initialize.rs +6 -3
- data/src/rules/style/redundant_interpolation.rs +8 -8
- data/src/rules/style/redundant_interpolation_unfreeze.rs +10 -3
- data/src/rules/style/redundant_line_continuation.rs +10 -7
- data/src/rules/style/redundant_parentheses.rs +96 -19
- data/src/rules/style/redundant_regexp_argument.rs +1 -1
- data/src/rules/style/redundant_regexp_character_class.rs +4 -3
- data/src/rules/style/redundant_regexp_escape.rs +3 -2
- data/src/rules/style/redundant_return.rs +1 -2
- data/src/rules/style/redundant_self.rs +28 -16
- data/src/rules/style/redundant_sort.rs +1 -1
- data/src/rules/style/redundant_sort_by.rs +1 -1
- data/src/rules/style/redundant_string_escape.rs +6 -5
- data/src/rules/style/regexp_literal.rs +3 -2
- data/src/rules/style/require_order.rs +2 -2
- data/src/rules/style/rescue_modifier.rs +9 -4
- data/src/rules/style/rescue_standard_error.rs +1 -1
- data/src/rules/style/return_nil.rs +2 -2
- data/src/rules/style/return_nil_in_predicate_method_definition.rs +2 -2
- data/src/rules/style/safe_navigation.rs +2 -2
- data/src/rules/style/safe_navigation_chain_length.rs +8 -1
- data/src/rules/style/sample.rs +3 -3
- data/src/rules/style/select_by.rs +6 -2
- data/src/rules/style/select_by_range.rs +1 -1
- data/src/rules/style/semicolon.rs +77 -4
- data/src/rules/style/signal_exception.rs +60 -3
- data/src/rules/style/single_argument_dig.rs +10 -2
- data/src/rules/style/single_line_block_params.rs +14 -4
- data/src/rules/style/single_line_do_end_block.rs +13 -12
- data/src/rules/style/single_line_methods.rs +2 -2
- data/src/rules/style/slicing_with_range.rs +2 -2
- data/src/rules/style/sole_nested_conditional.rs +4 -4
- data/src/rules/style/special_global_vars.rs +2 -2
- data/src/rules/style/stabby_lambda_parentheses.rs +1 -1
- data/src/rules/style/statement_modifier.rs +3 -2
- data/src/rules/style/static_class.rs +7 -1
- data/src/rules/style/string_concatenation.rs +12 -7
- data/src/rules/style/string_hash_keys.rs +3 -2
- data/src/rules/style/string_literals.rs +3 -3
- data/src/rules/style/string_literals_in_interpolation.rs +4 -1
- data/src/rules/style/struct_inheritance.rs +3 -3
- data/src/rules/style/super_arguments.rs +15 -7
- data/src/rules/style/super_with_args_parentheses.rs +49 -12
- data/src/rules/style/swap_values.rs +1 -1
- data/src/rules/style/symbol_array.rs +9 -2
- data/src/rules/style/symbol_proc.rs +3 -3
- data/src/rules/style/tally_method.rs +4 -4
- data/src/rules/style/ternary_parentheses.rs +30 -15
- data/src/rules/style/top_level_method_definition.rs +10 -5
- data/src/rules/style/trailing_body.rs +1 -1
- data/src/rules/style/trailing_comma.rs +206 -10
- data/src/rules/style/trailing_comma_in_arguments.rs +9 -10
- data/src/rules/style/trailing_comma_in_array_literal.rs +2 -1
- data/src/rules/style/trailing_comma_in_hash_literal.rs +2 -1
- data/src/rules/style/trailing_method_end_statement.rs +6 -1
- data/src/rules/style/trailing_underscore_variable.rs +4 -5
- data/src/rules/style/trivial_accessors.rs +2 -2
- data/src/rules/style/unless_logical_operators.rs +1 -1
- data/src/rules/style/unpack_first.rs +11 -2
- data/src/rules/style/when_then.rs +4 -4
- data/src/rules/style/while_until_do.rs +1 -1
- data/src/rules/style/while_until_modifier.rs +3 -3
- data/src/rules/style/word_array.rs +9 -7
- data/src/rules/style/yoda_condition.rs +2 -2
- data/src/rules/style/zero_length_predicate.rs +5 -0
- data/src/rules/support.rs +128 -11
- data/src/source.rs +18 -15
- metadata +5 -1
data/src/config/mod.rs
CHANGED
|
@@ -7,6 +7,7 @@ mod store;
|
|
|
7
7
|
use std::collections::{HashMap, HashSet};
|
|
8
8
|
use std::fs;
|
|
9
9
|
use std::path::{Path, PathBuf};
|
|
10
|
+
use std::sync::{Arc, OnceLock};
|
|
10
11
|
|
|
11
12
|
use anyhow::{Context, Result, bail};
|
|
12
13
|
use serde::de::DeserializeOwned;
|
|
@@ -44,9 +45,39 @@ pub struct Config {
|
|
|
44
45
|
includes: PathPatterns,
|
|
45
46
|
excludes: HashMap<String, PathPatterns>,
|
|
46
47
|
cop_includes: HashMap<String, PathPatterns>,
|
|
48
|
+
/// The result cache's digest of this configuration, folded on first use.
|
|
49
|
+
///
|
|
50
|
+
/// Nothing here changes after the configuration is built, and every file in a run mixes the
|
|
51
|
+
/// digest into its own cache key -- so serializing the merged configuration again per file, all
|
|
52
|
+
/// several hundred kilobytes of it once the default set is in, cost a cached run more than
|
|
53
|
+
/// reading the files did. The `Arc` is what lets a cloned `Config` share the answer instead of
|
|
54
|
+
/// working it out again.
|
|
55
|
+
cache_digest: Arc<OnceLock<Option<[u8; 32]>>>,
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
impl Config {
|
|
59
|
+
/// Stable digest of the on-disk result cache's view of this configuration. The merged raw
|
|
60
|
+
/// configuration determines cop behaviour, while the resolved paths and Ruby version cover
|
|
61
|
+
/// behaviour derived from where the configuration was loaded and from the surrounding project.
|
|
62
|
+
pub(crate) fn cache_digest(&self) -> Result<&[u8; 32]> {
|
|
63
|
+
self.cache_digest
|
|
64
|
+
.get_or_init(|| {
|
|
65
|
+
let material = serde_json::to_vec(&(
|
|
66
|
+
&self.raw,
|
|
67
|
+
self.path_base.to_string_lossy(),
|
|
68
|
+
self.cwd.to_string_lossy(),
|
|
69
|
+
self.config_path
|
|
70
|
+
.as_deref()
|
|
71
|
+
.map(|path| path.to_string_lossy()),
|
|
72
|
+
self.target_ruby.version.to_string(),
|
|
73
|
+
))
|
|
74
|
+
.ok()?;
|
|
75
|
+
Some(*blake3::hash(&material).as_bytes())
|
|
76
|
+
})
|
|
77
|
+
.as_ref()
|
|
78
|
+
.context("failed to fingerprint the resolved configuration")
|
|
79
|
+
}
|
|
80
|
+
|
|
50
81
|
pub fn load(explicit: Option<&Path>, cwd: &Path) -> Result<Self> {
|
|
51
82
|
Self::load_with_options(explicit, cwd, false)
|
|
52
83
|
}
|
|
@@ -117,6 +148,7 @@ impl Config {
|
|
|
117
148
|
includes,
|
|
118
149
|
excludes,
|
|
119
150
|
cop_includes,
|
|
151
|
+
cache_digest: Arc::new(OnceLock::new()),
|
|
120
152
|
})
|
|
121
153
|
}
|
|
122
154
|
|
|
@@ -124,6 +156,15 @@ impl Config {
|
|
|
124
156
|
&self.cwd
|
|
125
157
|
}
|
|
126
158
|
|
|
159
|
+
/// Project boundary used by the result cache.
|
|
160
|
+
///
|
|
161
|
+
/// RuboCop resolves every configured path against this directory. Keeping it in the cache
|
|
162
|
+
/// identity prevents unrelated projects that happen to use the same cop selection from
|
|
163
|
+
/// accumulating in one ever-growing index.
|
|
164
|
+
pub(crate) fn path_base(&self) -> &Path {
|
|
165
|
+
&self.path_base
|
|
166
|
+
}
|
|
167
|
+
|
|
127
168
|
pub fn config_path(&self) -> Option<&Path> {
|
|
128
169
|
self.config_path.as_deref()
|
|
129
170
|
}
|
|
@@ -199,8 +240,52 @@ impl Config {
|
|
|
199
240
|
.unwrap_or(true)
|
|
200
241
|
}
|
|
201
242
|
|
|
243
|
+
/// Whether the run may use this cop's corrector at all, which is the cop's own `AutoCorrect`
|
|
244
|
+
/// setting rather than anything the command line asked for.
|
|
245
|
+
///
|
|
246
|
+
/// This answers two upstream questions at once, because for every value RuboCop accepts they
|
|
247
|
+
/// have the same answer. `AutocorrectLogic#autocorrect_enabled?`
|
|
248
|
+
/// (`cop/autocorrect_logic.rb:31-46`) refuses `'disabled'` and `false` outright, and refuses
|
|
249
|
+
/// `'contextual'` while `LSP.enabled?` -- which `--editor-mode` and `--lsp` set. `Base#use_corrector`
|
|
250
|
+
/// (`cop/base.rb:445-453`) then decides what the offense is reported as, and its condition
|
|
251
|
+
/// `always_autocorrect? || (contextual_autocorrect? && !LSP.enabled?)` is false in exactly
|
|
252
|
+
/// those cases: the offense keeps status `:unsupported`, so it is **not** `correctable?` and no
|
|
253
|
+
/// `-a`/`-A` run rewrites it. Answering `false` here therefore has to do both -- withhold the
|
|
254
|
+
/// edits and clear the correctable marker -- or a user who opted out of a cop's autocorrection
|
|
255
|
+
/// still gets their code rewritten.
|
|
256
|
+
///
|
|
257
|
+
/// `editor_mode` is `LSP.enabled?`. `AutoCorrect: contextual` is not an oddity to guard
|
|
258
|
+
/// against: `config/default.yml` ships it on 19 cops, `Lint/UselessAssignment` among them, and
|
|
259
|
+
/// deleting a half-typed assignment is precisely what an editor must not do.
|
|
260
|
+
///
|
|
261
|
+
/// An absent key means `'always'` (`cop_config.fetch('AutoCorrect', 'always')`). A boolean is
|
|
262
|
+
/// the backward-compatible spelling of `'always'`/`'disabled'`, and
|
|
263
|
+
/// `ConfigValidator::CONFIG_CHECK_AUTOCORRECTS` refuses any other string, so the values below
|
|
264
|
+
/// are the whole reachable set. Anything else -- a number, a list -- is read as `'always'`:
|
|
265
|
+
/// upstream's `autocorrect_enabled?` says the same, and folding it the other way would let a
|
|
266
|
+
/// value RuboCop rejects outright silently switch a cop's corrections off.
|
|
267
|
+
pub fn rule_autocorrect_enabled(&self, name: &str, editor_mode: bool) -> bool {
|
|
268
|
+
match self.cop_raw_value(name, "AutoCorrect") {
|
|
269
|
+
Some(Value::Bool(value)) => *value,
|
|
270
|
+
Some(Value::String(value)) => match value.as_str() {
|
|
271
|
+
"disabled" => false,
|
|
272
|
+
"contextual" => !editor_mode,
|
|
273
|
+
_ => true,
|
|
274
|
+
},
|
|
275
|
+
_ => true,
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
202
279
|
pub fn cop_value<T: DeserializeOwned>(&self, name: &str, key: &str) -> Option<T> {
|
|
203
|
-
|
|
280
|
+
// Deserialized from the borrowed value rather than a clone of it. Every cop reads its
|
|
281
|
+
// settings once per file, so a clone here is one deep copy of the value per cop per file
|
|
282
|
+
// -- and the values are not all small: `Lint/Debugger`'s method list is a nested map.
|
|
283
|
+
//
|
|
284
|
+
// Measured 2026-08-19: this cuts the profiler's per-cop CPU total from 44.4s to 17.7s on
|
|
285
|
+
// rubocop/rubocop, but an A/B of the two binaries showed **no wall-clock difference**
|
|
286
|
+
// outside the noise. The saving is real and the copy was pointless, so it stays -- but it
|
|
287
|
+
// is not what the run is waiting on.
|
|
288
|
+
T::deserialize(self.cop_raw_value(name, key)?).ok()
|
|
204
289
|
}
|
|
205
290
|
|
|
206
291
|
pub fn all_cops_value<T: DeserializeOwned>(&self, key: &str) -> Option<T> {
|
|
@@ -224,6 +309,25 @@ impl Config {
|
|
|
224
309
|
self.includes.is_empty() || self.includes.matches_includes(path, &self.path_base)
|
|
225
310
|
}
|
|
226
311
|
|
|
312
|
+
/// `Config#allowed_camel_case_file?`: a gemspec may use dashes to spell a namespace, and a file
|
|
313
|
+
/// that only reaches the run through an `Include` pattern written with capitals -- `Rakefile`,
|
|
314
|
+
/// `Gemfile` -- is named after that pattern rather than after Ruby's conventions.
|
|
315
|
+
///
|
|
316
|
+
/// This belongs to the configuration rather than to `Naming/FileName`, exactly as upstream has
|
|
317
|
+
/// it, and the reason is not only tidiness: the cop is put to every file in the run, so
|
|
318
|
+
/// answering it from the cop meant re-reading `AllCops.Include` and recompiling its globs once
|
|
319
|
+
/// per file. Measured on rubocop/rubocop, that was 1.0 of the run's 19.0 seconds of cop time.
|
|
320
|
+
pub fn allowed_camel_case_file(&self, path: &Path) -> bool {
|
|
321
|
+
if path
|
|
322
|
+
.extension()
|
|
323
|
+
.is_some_and(|extension| extension == "gemspec")
|
|
324
|
+
{
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
self.includes
|
|
328
|
+
.matches_uppercase_includes(path, &self.path_base)
|
|
329
|
+
}
|
|
330
|
+
|
|
227
331
|
fn top_level_hidden(&self, path: &Path) -> bool {
|
|
228
332
|
paths::project_relative(path, &self.path_base).is_some_and(|relative| {
|
|
229
333
|
relative
|
|
@@ -500,6 +604,31 @@ mod tests {
|
|
|
500
604
|
assert!(Config::load(None, directory.path()).is_err());
|
|
501
605
|
}
|
|
502
606
|
|
|
607
|
+
#[test]
|
|
608
|
+
fn autocorrect_is_read_per_cop_and_contextual_defers_to_the_editor() {
|
|
609
|
+
let directory = tempdir().unwrap();
|
|
610
|
+
fs::write(directory.path().join("Gemfile"), "").unwrap();
|
|
611
|
+
fs::write(
|
|
612
|
+
directory.path().join(".rubocop.yml"),
|
|
613
|
+
"Layout/TrailingWhitespace:\n AutoCorrect: false\nStyle/StringLiterals:\n AutoCorrect: disabled\nStyle/HashSyntax:\n AutoCorrect: always\n",
|
|
614
|
+
)
|
|
615
|
+
.unwrap();
|
|
616
|
+
|
|
617
|
+
let config = Config::load(None, directory.path()).unwrap();
|
|
618
|
+
|
|
619
|
+
for editor_mode in [false, true] {
|
|
620
|
+
assert!(!config.rule_autocorrect_enabled("Layout/TrailingWhitespace", editor_mode));
|
|
621
|
+
assert!(!config.rule_autocorrect_enabled("Style/StringLiterals", editor_mode));
|
|
622
|
+
assert!(config.rule_autocorrect_enabled("Style/HashSyntax", editor_mode));
|
|
623
|
+
// No `AutoCorrect` key at all, which upstream reads as `'always'`.
|
|
624
|
+
assert!(config.rule_autocorrect_enabled("Layout/SpaceAfterComma", editor_mode));
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// `AutoCorrect: contextual` ships in the default configuration for this cop.
|
|
628
|
+
assert!(config.rule_autocorrect_enabled("Lint/UselessAssignment", false));
|
|
629
|
+
assert!(!config.rule_autocorrect_enabled("Lint/UselessAssignment", true));
|
|
630
|
+
}
|
|
631
|
+
|
|
503
632
|
#[test]
|
|
504
633
|
fn relative_excludes_do_not_match_paths_outside_the_project_root() {
|
|
505
634
|
let project = tempdir().unwrap();
|