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/README.ja.md
CHANGED
|
@@ -32,22 +32,80 @@ CI へ最小限の変更で導入できます。
|
|
|
32
32
|
|
|
33
33
|
## 主な機能
|
|
34
34
|
|
|
35
|
-
Bundler、Gemspec、Layout、Lint、Metrics、Migration、Naming、Security、Style
|
|
36
|
-
|
|
35
|
+
Bundler、Gemspec、Layout、Lint、Metrics、Migration、Naming、Security、Style の各デパートメントの
|
|
36
|
+
Cop を実装しています。一覧はバイナリ自身が正本です。
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
# 認識済み Cop と実装状況の一覧
|
|
40
40
|
sonicop --show-cops
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
**RuboCop 1.89 の全 609 Cop を実装しています。**
|
|
44
|
-
ただしこれは**レジストリについての主張**であって、すべての設定についての主張ではありません。
|
|
45
|
-
`Style/HashSyntax` は存在し既定の届く範囲では一致しますが、`EnforcedShorthandSyntax` の
|
|
46
|
-
既定以外の 4 つの値はいずれも未実装です。**Cop は半分欠けたまま、既定の届く範囲では
|
|
47
|
-
一致し続けられます** — [CONFORMANCE.md](CONFORMANCE.md) の *Limits* を参照してください。
|
|
43
|
+
**RuboCop 1.89 の全 609 Cop を実装しています。** 本家のレジストリと名前まで一致しています。
|
|
48
44
|
`Enabled: pending` の 159 個と `Enabled: false` の 56 個も含みます。この 215 個は本家でも
|
|
49
|
-
既定の実行では走らないので、`--only`
|
|
50
|
-
|
|
45
|
+
既定の実行では走らないので、`--only` で名指しするか設定で有効にしてください。本家に存在しない
|
|
46
|
+
Cop 名を書いた場合だけエラーで止まります(`--ignore-unrecognized-cops` で続行できます)。
|
|
47
|
+
|
|
48
|
+
### Cop 別の一致状況
|
|
49
|
+
|
|
50
|
+
全 609 Cop を両者で有効にし、本家の spec が供給する 37,491 ケースを、それぞれの spec が
|
|
51
|
+
指定した `TargetRubyVersion` で走らせて比較した結果です。**完全一致**とは、その Cop の offense が
|
|
52
|
+
位置・メッセージ・重大度・修正可否まで 1 件残らず一致し、どちらにも余りがないことを指します。
|
|
53
|
+
|
|
54
|
+
<!-- conformance:start -->
|
|
55
|
+
| デパートメント | Cop 数 | 検証済み | 完全一致 | 相違 |
|
|
56
|
+
|---|---:|---:|---:|---:|
|
|
57
|
+
| Bundler | 7 | 7 | **7 ✓** | 0 |
|
|
58
|
+
| Gemspec | 10 | 10 | **10 ✓** | 0 |
|
|
59
|
+
| Layout | 100 | 100 | 90 | 10 |
|
|
60
|
+
| Lint | 157 | 157 | 147 | 10 |
|
|
61
|
+
| Metrics | 10 | 10 | **10 ✓** | 0 |
|
|
62
|
+
| Migration | 1 | 1 | **1 ✓** | 0 |
|
|
63
|
+
| Naming | 19 | 19 | **19 ✓** | 0 |
|
|
64
|
+
| Security | 7 | 7 | **7 ✓** | 0 |
|
|
65
|
+
| Style | 298 | 298 | 288 | 10 |
|
|
66
|
+
| **合計** | **609** | **609** | **579** | **30** |
|
|
67
|
+
<!-- conformance:end -->
|
|
68
|
+
|
|
69
|
+
**先に読むべきは「検証済み」の列です。** ここで一度も発火しなかった Cop は、沈黙が一致と
|
|
70
|
+
見分けられないため、訊かれないまま一致に数えられてしまいます。**609 個すべてがここで発火します**。
|
|
71
|
+
それが「完全一致」の列を意味あるものにしています。
|
|
72
|
+
|
|
73
|
+
そのうち 3 個は専用の run を要しました。`Lint/DeprecatedReference`・`Lint/NameTypo`・
|
|
74
|
+
`Lint/UnusedPrivateMethod` は `rubydex` のプロジェクトインデックスが無ければ何も報告せず、
|
|
75
|
+
gem の導入と `AllCops/UseProjectIndex` の有効化が要ります。`Lint/DeprecatedReference` は
|
|
76
|
+
さらに条件があり、`@deprecated` を持つメソッドの定義クラスを**継承したクラスの中**から
|
|
77
|
+
呼ぶ必要があります。本家の spec は「インデックス無しでは offense を出さない」という
|
|
78
|
+
`expect_no_offenses` で始まるので「到達不能」と読みたくなりますが、そうではありません。
|
|
79
|
+
|
|
80
|
+
「完全一致」を 609 にし、「相違」をゼロにすることが現在の目標です。実コードを足しても
|
|
81
|
+
届きません。RuboCop が既定で無効にしている 56 Cop と、pending として出荷している Cop の多くは、
|
|
82
|
+
ツリーがどれだけ大きくても素の実行では発火しないためです。そこに届くのは本家の spec が
|
|
83
|
+
供給する入力の方で、`tests/fixtures/upstream_spec_capture.jsonl` に記録したケースは
|
|
84
|
+
**609 Cop すべてに到達します**(実測)。走らせ方には間違えやすい点が 2 つあり、
|
|
85
|
+
**どちらも失敗せずに表を縮めます**。
|
|
86
|
+
|
|
87
|
+
- **`TargetRubyVersion` は入力の一部であって、全体の設定ではありません。** 2.7 に固定すると
|
|
88
|
+
`Style/ArrayIntersect`・`Naming/BlockForwarding`・`Style/ItBlockParameter` ほか 11 個が
|
|
89
|
+
そもそも発火できません。各ケースはその spec が指定した版で走らせます。
|
|
90
|
+
- **ファイル名そのものを見る Cop があります。** `Bundler/*` は `Gemfile`、`Gemspec/*` は
|
|
91
|
+
`.gemspec`、`Naming/FileName` は名前自体を読みます。全ケースを `.rb` で書き出すと、
|
|
92
|
+
この 17 Cop が何にも一致しませんでした。
|
|
93
|
+
|
|
94
|
+
これとは別に、2026-08-29 に本家 Cop spec から直接抽出できた 11,506 ケースを oracle で
|
|
95
|
+
照合しました。本家が入力を読めなかった 226 ケースとクラッシュした 1 ケースを除き、測定できた
|
|
96
|
+
範囲では Sonicop の**検出差分・訂正差分ともにゼロ**でした。この結果は上の表には加えていません。
|
|
97
|
+
直接抽出できるケースが無い Cop が 51 個あり、ディレクティブ系 3 Cop は `--only` では測定不能な
|
|
98
|
+
ため、この掃引だけで全 609 Cop の完全一致を証明できないからです。また、この直接掃引は各例の
|
|
99
|
+
`TargetRubyVersion` をすべて再現せず、中立的な既定条件で実行しています。そのため、今回変更した
|
|
100
|
+
Ruby 3.4 依存の 4 Cop は 3.4 で別途比較し、メッセージと位置が本家に完全一致することを確認しました。
|
|
101
|
+
|
|
102
|
+
設定値については別に測っています。既定値でしか一致しない Cop は半分しか実装していないのと
|
|
103
|
+
同じだからです。`Enforced*` 系の設定を持つ 111 Cop すべてを**既定以外の値**に倒して同じコーパスを
|
|
104
|
+
流すと、**622,317 件の offense のうち 99.995% が一致**し、発火した 96 Cop のうち 85 個が完全一致です。
|
|
105
|
+
残るのは 10 Cop(いずれも 17 件以下)と、本家がクラッシュして sonicop が正常に検出する 1 Cop です。
|
|
106
|
+
内訳は [CONFORMANCE.md](CONFORMANCE.md) にあります。
|
|
107
|
+
|
|
108
|
+
どちらの表も `scripts/conformance_table.rb` で再現できます。
|
|
51
109
|
|
|
52
110
|
## インストール
|
|
53
111
|
|
|
@@ -70,7 +128,7 @@ cargo install --git https://github.com/owayo/sonicop
|
|
|
70
128
|
# 現在のプロジェクトを検査
|
|
71
129
|
sonicop
|
|
72
130
|
|
|
73
|
-
# Cop
|
|
131
|
+
# Cop/デパートメントを指定
|
|
74
132
|
sonicop --only Layout,Style/StringLiterals app spec
|
|
75
133
|
|
|
76
134
|
# 安全な自動修正/全自動修正
|
|
@@ -95,6 +153,8 @@ sonicop --show-cops
|
|
|
95
153
|
`AllCops/DisabledByDefault`、`Include`/`Exclude`、Cop ごとの `Enabled`、`Exclude`、
|
|
96
154
|
`Severity`、`Safe`、`SafeAutoCorrect` と設定値に対応します。宣言されたプラグイン由来の
|
|
97
155
|
Cop は「認識済み・未実装」として受理し、Ruby プラグインコード自体は実行しません。
|
|
156
|
+
リモート設定のリクエストには 30 秒のネットワークタイムアウトを設け、応答は 1 件あたり
|
|
157
|
+
5 MiB に制限します。
|
|
98
158
|
|
|
99
159
|
```yaml
|
|
100
160
|
inherit_from: .rubocop_todo.yml
|
|
@@ -106,24 +166,30 @@ Style/StringLiterals:
|
|
|
106
166
|
EnforcedStyle: single_quotes
|
|
107
167
|
```
|
|
108
168
|
|
|
109
|
-
既存コマンドとの互換性を保つため、server/LSP/MCP、plugin
|
|
110
|
-
サーバートランスポート、Ruby
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
`
|
|
124
|
-
|
|
169
|
+
既存コマンドとの互換性を保つため、server/LSP/MCP、plugin 系の引数も受理します。
|
|
170
|
+
サーバートランスポート、Ruby プラグイン実行、カスタム Cop、実装済み以外の Cop は実行しません。
|
|
171
|
+
これらはその旨を出力します。`--server` / `--no-server` / `--lsp` / `--mcp` / `--plugin` は
|
|
172
|
+
stderr に 1 行の注記を出します。
|
|
173
|
+
|
|
174
|
+
cache 系の引数は、受理するだけでなく実際に効きます。sonicop は独自の結果キャッシュを持ち、
|
|
175
|
+
検査時からサイズ・更新時刻・パーミッションのいずれも動いていないファイルには、
|
|
176
|
+
保存済みのレポートをそのまま返します。
|
|
177
|
+
|
|
178
|
+
- キャッシュは既定で有効です。`--cache false` で無効化できます。設定ファイルの
|
|
179
|
+
`AllCops/MaxFilesInCache: 0` でも同じです。
|
|
180
|
+
- 置き場所は `--cache-root DIR` で指定します。省略時は `$XDG_CACHE_HOME/sonicop`、
|
|
181
|
+
macOS では `~/Library/Caches/sonicop`、それ以外は `~/.cache/sonicop` です。
|
|
182
|
+
`--cache-root` は `--cache false` とは併用できません。
|
|
183
|
+
- 保持するレポート数の上限は `AllCops/MaxFilesInCache` で、既定は本家と同じ 20,000 件です。
|
|
184
|
+
- autocorrect 実行、`--stdin`、`--profile`、`--memory` では読み書きしません。
|
|
185
|
+
- 本家のキャッシュとは共有しません。形式が別物であり、書いたときとまったく同じ
|
|
186
|
+
ビルドの sonicop にしかエントリを返さないためです。
|
|
187
|
+
|
|
188
|
+
無言なのは Cop の設定値のほうです。sonicop が実装していない設定値は**警告なしに無視されます**。
|
|
189
|
+
名前を綴り間違えた設定値も同様です。つまり
|
|
125
190
|
**offense が 0 件であることは、その設定が効いた証拠にはなりません**。
|
|
126
191
|
無視された設定値と、違反の無いファイルが、同じ出力になるためです。
|
|
192
|
+
どの設定値まで検証済みかは上の *Cop 別の一致状況* を参照してください。
|
|
127
193
|
|
|
128
194
|
Cop の*名前*は検査されます。設定ファイルに未知の Cop 名があれば、実行はエラーで止まります。
|
|
129
195
|
素通りするのは、既知の Cop の中の設定値です。
|
|
@@ -139,11 +205,13 @@ Mastodon(15,286 件)で、過剰も不足もメタデータ差もありま
|
|
|
139
205
|
**件数だけでなくパスまで**一致します(集合として比較。どの側にも余りはありません)。
|
|
140
206
|
残る差分は `Lint/Syntax` に集中しています。その大半は、本家の LALR パーサが
|
|
141
207
|
構文エラーから回復して出す追加診断を tree-sitter では再現できないことによるもので、
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
208
|
+
診断位置の差は不足と過剰の両方に出ます。Homebrew の不足 997 件・過剰 263 件はすべて
|
|
209
|
+
`Lint/Syntax` ですが、**構文エラーと判定したファイル集合は 569 対 569 で完全一致**し、
|
|
210
|
+
移植版だけが拒否したファイルは 0 件です。過剰 263 件は共有エラーファイル 135 件にあり、
|
|
211
|
+
すべて同じファイル内の共通診断より後ろにあるため、別の受理判定バグではなく回復後の診断位置差です。
|
|
212
|
+
Homebrew を問題の構文をサポートする Ruby 3.1 として測ると、両者とも `Lint/Syntax` は 0 件になります。
|
|
213
|
+
autocorrect は RuboCop 自身のツリーと Mastodon でバイト単位に一致します。この 2 つは死守ラインと
|
|
214
|
+
して扱い、バイト一致が崩れた場合は既知差分ではなく退行として直します。
|
|
147
215
|
|
|
148
216
|
コマンド、この数値を測ったコーパスのコミット、この種の計測が誤った結論を導く 2 つの罠は
|
|
149
217
|
[CONFORMANCE.md](CONFORMANCE.md) にまとめています。
|
|
@@ -163,49 +231,63 @@ Mastodon でバイト単位に一致します。この 2 つは死守ライン
|
|
|
163
231
|
既定の実行はどちらの群にも届きません。)
|
|
164
232
|
各値は暖機後 2 回の最速値です。
|
|
165
233
|
|
|
166
|
-
| コーパス | ファイル | RuboCop 並列 | Sonicop 並列 | RuboCop 単一 | Sonicop 単一 |
|
|
167
|
-
|
|
168
|
-
| rubocop/rubocop | 1,
|
|
169
|
-
| mastodon/mastodon | 3,
|
|
170
|
-
| Homebrew/brew | 2,
|
|
171
|
-
| rails/rails | 3,
|
|
172
|
-
| ruby/ruby | 7,
|
|
234
|
+
| コーパス | ファイル | offense | RuboCop 並列 | Sonicop 並列 | RuboCop 単一 | Sonicop 単一 |
|
|
235
|
+
|---|---:|---:|---:|---:|---:|---:|
|
|
236
|
+
| rubocop/rubocop | 1,780 | 5,826 | 10.85 秒 | **1.53 秒** | 41.44 秒 | **8.96 秒** |
|
|
237
|
+
| mastodon/mastodon | 3,292 | 15,293 | 22.59 秒 | **3.04 秒** | 34.74 秒 | **6.86 秒** |
|
|
238
|
+
| Homebrew/brew | 2,296 | 51,527 | 13.56 秒 | **2.21 秒** | 40.36 秒 | **6.51 秒** |
|
|
239
|
+
| rails/rails | 3,562 | 168,615 | 32.90 秒 | **8.84 秒** | 85.71 秒 | **19.17 秒** |
|
|
240
|
+
| ruby/ruby | 7,477 | 765,975 | 86.89 秒 | **15.59 秒** | 193.59 秒 | **37.98 秒** |
|
|
173
241
|
|
|
174
|
-
差は並列で
|
|
242
|
+
差は並列で 3.7〜7.4 倍、単一プロセスで 4.5〜6.2 倍と幅があり、1 コーパスでは代表できません。
|
|
175
243
|
**単一プロセスの列を読み、並列は目安として扱ってください。** 同じ 2 つのバイナリを 1 日に
|
|
176
244
|
3 回測ったところ、単一プロセスの値は毎回 16% 以内に収まったのに対し、RuboCop 自身のツリーでの
|
|
177
245
|
並列の倍率は、マシンが他に何をしていたかだけで 3.3 倍から 9.2 倍まで動きました。単一プロセスは
|
|
178
246
|
エンジンを測っていますが、並列はエンジンに加えて「その実行でスケジューリングがそのツリーに
|
|
179
247
|
どれだけ噛み合ったか」を測っています。
|
|
180
248
|
|
|
181
|
-
仕事を省いて速いわけではありません。この同じ 394 Cop
|
|
182
|
-
|
|
183
|
-
|
|
249
|
+
仕事を省いて速いわけではありません。この同じ 394 Cop について、表のどのコーパスでも
|
|
250
|
+
**offense の総数が一致**し、RuboCop 自身のツリーと Mastodon ではその 1 件ずつが同じ位置・
|
|
251
|
+
同じメッセージ・同じ severity です。Rails は 168,615 件のうち 2 件だけ食い違います
|
|
252
|
+
(Sonicop が出す `Style/CaseLikeIf` 1 件と、出さない `Metrics/AbcSize` 1 件)。
|
|
253
|
+
RuboCop 自身のツリーでは 1 件の `correctable` フラグが違います。
|
|
254
|
+
autocorrect は前者と後者でバイト単位に一致します。
|
|
184
255
|
|
|
185
|
-
再現時に注意が必要な点が
|
|
256
|
+
再現時に注意が必要な点が 4 つあります。RuboCop は **`--cache false` と併用すると
|
|
186
257
|
`--parallel` を黙って無効化します**。そのためここでの並列実行はキャッシュを有効にしたうえで
|
|
187
258
|
実行ごとにキャッシュディレクトリを消しており、`--cache false --parallel` で計測すると
|
|
188
259
|
単一プロセスを測ることになり差が過大に出ます。また RuboCop の既定は単一プロセス、
|
|
189
|
-
Sonicop は `--no-parallel`
|
|
260
|
+
Sonicop は `--no-parallel` を渡さない限り並列です。そして**両方ともキャッシュを空にする**
|
|
261
|
+
必要があります。Sonicop も既定でキャッシュするため、同じツリーを 2 回目に流すと自分の
|
|
262
|
+
キャッシュが答えてしまい、エンジンについては何も測れません。どちらにも使い捨ての
|
|
263
|
+
キャッシュディレクトリを渡してください。最後に、そのキャッシュディレクトリは**実パス**である
|
|
264
|
+
必要があります。macOS の `mktemp -d` は `/var/folders/…` を返し、その `/var` は symlink なので
|
|
265
|
+
RuboCop はそこを拒み、キャッシュ無しで走ってしまいます。
|
|
190
266
|
|
|
191
267
|
```bash
|
|
192
268
|
# RuboCop(並列・キャッシュは毎回空・既定の全 394 Cop)
|
|
193
|
-
|
|
269
|
+
root=$(mktemp -d /private/tmp/bench.XXXXXX)
|
|
270
|
+
rubocop --force-default-config --cache true --cache-root "$root" \
|
|
194
271
|
--no-color --parallel -f quiet
|
|
195
272
|
|
|
196
|
-
# Sonicop
|
|
197
|
-
sonicop --force-default-config --format quiet
|
|
273
|
+
# Sonicop(キャッシュは毎回空)
|
|
274
|
+
sonicop --force-default-config --cache-root "$root" --format quiet
|
|
198
275
|
```
|
|
199
276
|
|
|
277
|
+
キャッシュの書き込みもこの数値に含まれており、無料ではありません。索引は全 offense を
|
|
278
|
+
「見つかった行のテキスト」付きで保持するため、`ruby/ruby` では 336 MB になります。
|
|
279
|
+
2 回目の実行(キャッシュ命中)は `ruby/ruby` で 1.59 秒、Rails で 0.42 秒です。
|
|
280
|
+
|
|
200
281
|
測定機は Apple M2(8 コア)、Ruby 4.0.6(YJIT 利用可)、RubyGems 導入の RuboCop 1.89.0。
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
282
|
+
2026-08-31 に、`rubocop_rubocop` 2693129 / `mastodon_mastodon` b59ddc7 / `Homebrew_brew` b42173b /
|
|
283
|
+
`rails_rails` a19f07f / `ruby_ruby` 22e4a75 の各リビジョンに対して測定しました。
|
|
284
|
+
1 分平均のロードアベレージは各行の測定時点で 4.5〜7.1 で、その大半は RuboCop 自身の並列
|
|
285
|
+
ワーカーです(計測する以上避けられません)。**アイドル状態ではありません。**
|
|
286
|
+
各コーパスで両者を連続して同じ条件で測っているため倍率は保たれますが、秒数そのものは下限ではなく、
|
|
287
|
+
静かなマシンならより速く出ます。コアを奪い合うものが動いていると両者とも膨らみ、その度合いは
|
|
288
|
+
一致しません。それが並列の列があれだけ動く理由です。秒数そのものが重要なときは、他に負荷のない
|
|
289
|
+
状態で測り、**実行の前後でロードアベレージを記録してください** — その情報が無い数値は、
|
|
290
|
+
別の数値と比べられません。
|
|
209
291
|
|
|
210
292
|
## 開発
|
|
211
293
|
|
|
@@ -220,8 +302,8 @@ make gem # source gem
|
|
|
220
302
|
|
|
221
303
|
### Cop の追加
|
|
222
304
|
|
|
223
|
-
Cop は `src/rules
|
|
224
|
-
1
|
|
305
|
+
Cop は `src/rules/<デパートメント>/<cop>.rs` の 1 ファイルで、公開するのは
|
|
306
|
+
`check(context, offenses)` の 1 関数だけです。登録はデパートメントの `mod.rs` に 1 行を足します。
|
|
225
307
|
|
|
226
308
|
```rust
|
|
227
309
|
department_rules! {
|
|
@@ -245,6 +327,12 @@ Cop ごとの全走査はファイル規模ではなく Cop 数に比例して
|
|
|
245
327
|
`scripts/sync_default_yml.sh <rubocop-version>` で行い、由来のバージョンがファイル先頭に
|
|
246
328
|
記録されます。
|
|
247
329
|
|
|
330
|
+
`src/display_width_table.rs` も生成物で、コミットします。RuboCop は表示桁を
|
|
331
|
+
`unicode-display_width` gem で数えるため、この表は手書きせず gem から生成しています。
|
|
332
|
+
手書きの例外表は実際にずれており、NFD 分解された日本語でキャレットの本数が合わなくなっていました。
|
|
333
|
+
再生成は `ruby scripts/dump_display_width.rb > src/display_width_table.rs` で行い、
|
|
334
|
+
gem と Unicode のバージョンがファイル先頭に記録されます。
|
|
335
|
+
|
|
248
336
|
依存更新には `depup --install` を使います。Ruby grammar は再現可能性のため `Cargo.toml` で
|
|
249
337
|
fork のコミットを固定しています。
|
|
250
338
|
|
data/README.md
CHANGED
|
@@ -41,15 +41,76 @@ sonicop --show-cops
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
**All 609 RuboCop 1.89 cops are implemented**, matched name for name against the upstream registry.
|
|
44
|
-
That is a claim about the registry, not about every configuration: `Style/HashSyntax` is present and
|
|
45
|
-
matches everywhere its default reaches, yet none of the four non-default values of its
|
|
46
|
-
`EnforcedShorthandSyntax` are implemented. **A cop can be half absent and still match everywhere the
|
|
47
|
-
default reaches** — see *Limits* in [CONFORMANCE.md](CONFORMANCE.md).
|
|
48
44
|
That includes the 159 shipped as `Enabled: pending` and the 56 shipped as `Enabled: false`, which a
|
|
49
45
|
default run does not reach on either side — name them with `--only` or switch them on in a
|
|
50
46
|
configuration, exactly as with RuboCop. Unknown cop names still fail validation unless
|
|
51
47
|
`--ignore-unrecognized-cops` is supplied.
|
|
52
48
|
|
|
49
|
+
### Cop conformance
|
|
50
|
+
|
|
51
|
+
All 609 cops switched on, on both sides, over the 37,491 cases RuboCop's own specs supply, each
|
|
52
|
+
run at the `TargetRubyVersion` its spec asked for. A cop counts as an **exact match** only when its
|
|
53
|
+
offenses agree completely: every position, message, severity and correctable flag, with nothing
|
|
54
|
+
extra on either side.
|
|
55
|
+
|
|
56
|
+
<!-- conformance:start -->
|
|
57
|
+
| Department | Cops | Exercised | Exact match | Diverging |
|
|
58
|
+
|---|---:|---:|---:|---:|
|
|
59
|
+
| Bundler | 7 | 7 | **7 ✓** | 0 |
|
|
60
|
+
| Gemspec | 10 | 10 | **10 ✓** | 0 |
|
|
61
|
+
| Layout | 100 | 100 | 90 | 10 |
|
|
62
|
+
| Lint | 157 | 157 | 147 | 10 |
|
|
63
|
+
| Metrics | 10 | 10 | **10 ✓** | 0 |
|
|
64
|
+
| Migration | 1 | 1 | **1 ✓** | 0 |
|
|
65
|
+
| Naming | 19 | 19 | **19 ✓** | 0 |
|
|
66
|
+
| Security | 7 | 7 | **7 ✓** | 0 |
|
|
67
|
+
| Style | 298 | 298 | 288 | 10 |
|
|
68
|
+
| **Total** | **609** | **609** | **579** | **30** |
|
|
69
|
+
<!-- conformance:end -->
|
|
70
|
+
|
|
71
|
+
**Read the *Exercised* column first.** A cop nothing here made fire contributes neither way — its
|
|
72
|
+
silence is indistinguishable from agreement, so it would be counted as agreement without ever
|
|
73
|
+
being asked. **Every one of the 609 fires here**, which is what makes the *Exact match* column
|
|
74
|
+
mean what it says.
|
|
75
|
+
|
|
76
|
+
Three of them took a run of their own. `Lint/DeprecatedReference`, `Lint/NameTypo` and
|
|
77
|
+
`Lint/UnusedPrivateMethod` report nothing without a `rubydex` project index, which needs the gem
|
|
78
|
+
installed and `AllCops/UseProjectIndex` switched on — and `Lint/DeprecatedReference` needs more
|
|
79
|
+
than that: the call has to sit inside a class inheriting the one whose method carries the
|
|
80
|
+
`@deprecated` tag. Upstream's own specs open with an `expect_no_offenses` saying the cop is silent
|
|
81
|
+
without the index, which is easy to read as "unreachable"; it is not.
|
|
82
|
+
|
|
83
|
+
Getting *Exact match* to 609 while reducing *Diverging* to zero is the current goal. More real Ruby
|
|
84
|
+
does not get there: the 56 cops RuboCop ships disabled, and much of what it ships as pending, never
|
|
85
|
+
fire in a plain run however large the tree. What does reach every one of them is the input its own
|
|
86
|
+
specs supply — the cases recorded in `tests/fixtures/upstream_spec_capture.jsonl` touch **609 of 609
|
|
87
|
+
cops**, measured. Two things about running them are easy to get wrong, and both silently shrink the
|
|
88
|
+
table rather than failing:
|
|
89
|
+
|
|
90
|
+
- **`TargetRubyVersion` is part of the input, not a global.** Pinning everything at 2.7 leaves
|
|
91
|
+
`Style/ArrayIntersect`, `Naming/BlockForwarding`, `Style/ItBlockParameter` and eleven others
|
|
92
|
+
unable to fire at all. Each case is run at the version its spec asked for.
|
|
93
|
+
- **The filename is what several cops inspect.** `Bundler/*` needs a `Gemfile`, `Gemspec/*` a
|
|
94
|
+
`.gemspec`, and `Naming/FileName` reads the name itself. Writing every case as `.rb` had all 17
|
|
95
|
+
of those cops matching nothing.
|
|
96
|
+
|
|
97
|
+
A separate direct oracle sweep on 2026-08-29 examined 11,506 cases extractable from the upstream
|
|
98
|
+
cop specs. RuboCop could not read 226 of those inputs and crashed on one; among the measurable
|
|
99
|
+
cases, Sonicop had **zero detection differences and zero correction differences**. This result is
|
|
100
|
+
not folded into the table above: 51 cops had no directly extractable case, and three directive cops
|
|
101
|
+
cannot be measured under `--only`, so the sweep does not prove that all 609 cops are exact. The
|
|
102
|
+
direct sweep also uses neutral/default conditions rather than preserving every example's
|
|
103
|
+
`TargetRubyVersion`. The four Ruby 3.4-sensitive cops changed in this pass were therefore compared
|
|
104
|
+
separately at 3.4, where their messages and locations matched RuboCop exactly.
|
|
105
|
+
|
|
106
|
+
Configuration is measured separately, because a cop that only matches at its default value is half
|
|
107
|
+
a cop. Every one of the 111 cops carrying an `Enforced*` setting was switched to a **non-default**
|
|
108
|
+
value at once and the corpus re-run: **99.995% of 622,317 offenses match**, with 85 of the 96 cops
|
|
109
|
+
that fired matching exactly. The residue is 10 cops of at most 17 offenses each, plus one where
|
|
110
|
+
RuboCop crashes and sonicop does not; the list is in [CONFORMANCE.md](CONFORMANCE.md).
|
|
111
|
+
|
|
112
|
+
Reproduce either table with `scripts/conformance_table.rb`.
|
|
113
|
+
|
|
53
114
|
## Installation
|
|
54
115
|
|
|
55
116
|
```bash
|
|
@@ -99,6 +160,8 @@ run. Local and HTTPS `inherit_from`, `inherit_gem`, `inherit_mode`,
|
|
|
99
160
|
`AllCops/DisabledByDefault`, `Include`, and `Exclude`, plus per-cop `Enabled`, `Exclude`,
|
|
100
161
|
`Severity`, `Safe`, `SafeAutoCorrect`, and cop settings are supported. Cops supplied by declared
|
|
101
162
|
plugins are accepted as recognized-but-unimplemented without executing Ruby plugin code.
|
|
163
|
+
Remote configuration requests use 30-second network timeouts, and each response is limited to
|
|
164
|
+
5 MiB.
|
|
102
165
|
|
|
103
166
|
```yaml
|
|
104
167
|
inherit_from: .rubocop_todo.yml
|
|
@@ -114,22 +177,29 @@ Style/StringLiterals:
|
|
|
114
177
|
EnforcedStyle: single_quotes
|
|
115
178
|
```
|
|
116
179
|
|
|
117
|
-
The CLI accepts RuboCop's server/LSP/MCP
|
|
118
|
-
parse-compatible. Sonicop does not provide server transports, Ruby plugin execution,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
180
|
+
The CLI accepts RuboCop's server/LSP/MCP and plugin flags to keep existing command lines
|
|
181
|
+
parse-compatible. Sonicop does not provide server transports, Ruby plugin execution, custom Ruby
|
|
182
|
+
cops, or cops outside the implemented set. Each of those flags says so: `--server`, `--no-server`,
|
|
183
|
+
`--lsp`, `--mcp`, and `--plugin` print a one-line notice on stderr.
|
|
184
|
+
|
|
185
|
+
The cache flags are honoured rather than merely parsed. Sonicop keeps a result cache of its own and
|
|
186
|
+
serves a stored report for a file whose size, modification time and permission bits have not moved
|
|
187
|
+
since it was inspected.
|
|
188
|
+
|
|
189
|
+
- Caching is on by default. `--cache false` turns it off, as does `AllCops/MaxFilesInCache: 0` in a
|
|
190
|
+
configuration file.
|
|
191
|
+
- `--cache-root DIR` chooses where it lives. Without it the root is `$XDG_CACHE_HOME/sonicop`, or
|
|
192
|
+
`~/Library/Caches/sonicop` on macOS, or `~/.cache/sonicop`. `--cache-root` cannot be combined
|
|
193
|
+
with `--cache false`.
|
|
194
|
+
- `AllCops/MaxFilesInCache` bounds how many reports are kept, defaulting to RuboCop's 20,000.
|
|
195
|
+
- Autocorrect runs, `--stdin`, `--profile` and `--memory` neither read nor write it.
|
|
196
|
+
- It is not shared with RuboCop's cache: the formats are unrelated, and an entry is only served back
|
|
197
|
+
to a build of Sonicop identical to the one that wrote it.
|
|
198
|
+
|
|
199
|
+
Cop settings are the silent case. A setting sonicop does not implement is ignored without
|
|
200
|
+
any warning, and so is a setting whose name is simply misspelled. **A run that reports no offenses
|
|
201
|
+
is therefore not evidence that a setting took effect**, because an ignored setting and a clean file
|
|
202
|
+
produce the same output. *Cop conformance* above says which values have been measured.
|
|
133
203
|
|
|
134
204
|
Cop *names* are checked: an unrecognised cop in a configuration file stops the run with an error.
|
|
135
205
|
It is the settings inside a recognised cop that pass unvalidated.
|
|
@@ -146,9 +216,12 @@ Mastodon (15,286), with no excess, no shortfall and no metadata differences. The
|
|
|
146
216
|
match exactly on all five — paths, not just counts, compared as sets. What remains is concentrated in
|
|
147
217
|
`Lint/Syntax`. Most of it is RuboCop's
|
|
148
218
|
LALR parser recovering from an error and emitting diagnostics a tree-sitter parse cannot
|
|
149
|
-
reconstruct
|
|
150
|
-
|
|
151
|
-
|
|
219
|
+
reconstruct, and the resulting position differences go in both directions. On Homebrew all 997
|
|
220
|
+
missing and 263 excess positions are `Lint/Syntax`, but the **sets of files rejected as syntax
|
|
221
|
+
errors are exactly the same: 569 versus 569**, with no file rejected only by Sonicop. The 263 excess
|
|
222
|
+
positions occur in 135 shared syntax-error files and every one follows a diagnostic at a position
|
|
223
|
+
shared by both tools, so they are recovery-position differences rather than a separate acceptance
|
|
224
|
+
bug. At Ruby 3.1, which supports the syntax used there, both tools report zero `Lint/Syntax` offenses.
|
|
152
225
|
Autocorrect is byte-identical on RuboCop's own tree and on Mastodon, the two corpora held as a hard
|
|
153
226
|
line: a change that breaks byte equality there is a regression, not a new known divergence.
|
|
154
227
|
|
|
@@ -169,50 +242,62 @@ once the 159 RuboCop ships as `Enabled: pending` and the 56 it ships as `Enabled
|
|
|
169
242
|
aside; a default run reaches neither group on either side.) Times are the fastest of two
|
|
170
243
|
warmed runs.
|
|
171
244
|
|
|
172
|
-
| Corpus | Files | RuboCop parallel | Sonicop parallel | RuboCop single | Sonicop single |
|
|
173
|
-
|
|
174
|
-
| rubocop/rubocop | 1,
|
|
175
|
-
| mastodon/mastodon | 3,
|
|
176
|
-
| Homebrew/brew | 2,
|
|
177
|
-
| rails/rails | 3,
|
|
178
|
-
| ruby/ruby | 7,
|
|
245
|
+
| Corpus | Files | Offenses | RuboCop parallel | Sonicop parallel | RuboCop single | Sonicop single |
|
|
246
|
+
|---|---:|---:|---:|---:|---:|---:|
|
|
247
|
+
| rubocop/rubocop | 1,780 | 5,826 | 10.85 s | **1.53 s** | 41.44 s | **8.96 s** |
|
|
248
|
+
| mastodon/mastodon | 3,292 | 15,293 | 22.59 s | **3.04 s** | 34.74 s | **6.86 s** |
|
|
249
|
+
| Homebrew/brew | 2,296 | 51,527 | 13.56 s | **2.21 s** | 40.36 s | **6.51 s** |
|
|
250
|
+
| rails/rails | 3,562 | 168,615 | 32.90 s | **8.84 s** | 85.71 s | **19.17 s** |
|
|
251
|
+
| ruby/ruby | 7,477 | 765,975 | 86.89 s | **15.59 s** | 193.59 s | **37.98 s** |
|
|
179
252
|
|
|
180
|
-
The gap is
|
|
253
|
+
The gap is 3.7x to 7.4x in parallel and 4.5x to 6.2x single-process, so no single corpus summarizes
|
|
181
254
|
it. **Read the single-process column and treat the parallel one as indicative.** Measuring the same
|
|
182
255
|
two binaries three times over a day put the single-process figures within 16% of each other every
|
|
183
256
|
time, while the parallel ratio on RuboCop's own tree moved between 3.3x and 9.2x purely with what
|
|
184
257
|
else the machine was doing. Single-process measures the engines; parallel measures the engines plus
|
|
185
258
|
how well each one's scheduling happens to fit that tree on that run.
|
|
186
259
|
|
|
187
|
-
The speed is not bought by skipping work
|
|
188
|
-
on
|
|
189
|
-
|
|
260
|
+
The speed is not bought by skipping work. Over those same 394 cops the two find the **same number of
|
|
261
|
+
offenses** on every corpus in the table, and on RuboCop's own tree and on Mastodon every one of them
|
|
262
|
+
is at the same position with the same message and severity. Rails, at 168,615 offenses, differs in
|
|
263
|
+
two of them — one `Style/CaseLikeIf` Sonicop reports and one `Metrics/AbcSize` it does not — and
|
|
264
|
+
RuboCop's own tree differs in one offense's `correctable` flag. Autocorrect is byte-identical on the
|
|
265
|
+
first and the last.
|
|
190
266
|
|
|
191
|
-
|
|
267
|
+
Four details matter for reproducing this. RuboCop **silently turns `--parallel` off when combined
|
|
192
268
|
with `--cache false`**, so its parallel runs here use a cache directory that is deleted before each
|
|
193
269
|
run rather than disabled; timing it with `--cache false --parallel` measures a single process and
|
|
194
270
|
overstates the difference. RuboCop's default is a single process, while Sonicop is parallel unless
|
|
195
|
-
`--no-parallel` is passed.
|
|
271
|
+
`--no-parallel` is passed. Both sides need a **cold** cache: Sonicop caches by default too, so a
|
|
272
|
+
second run over the same tree answers from its own cache and measures nothing about the engine —
|
|
273
|
+
give each tool a throwaway cache root. And the cache root must be a **real path**: macOS `mktemp -d`
|
|
274
|
+
returns `/var/folders/…`, whose `/var` is a symlink, and RuboCop refuses such a location and runs
|
|
275
|
+
with no cache at all.
|
|
196
276
|
|
|
197
277
|
```bash
|
|
198
278
|
# RuboCop, parallel, cold cache, its full default set of 394 cops
|
|
199
|
-
|
|
279
|
+
root=$(mktemp -d /private/tmp/bench.XXXXXX)
|
|
280
|
+
rubocop --force-default-config --cache true --cache-root "$root" \
|
|
200
281
|
--no-color --parallel -f quiet
|
|
201
282
|
|
|
202
|
-
# Sonicop
|
|
203
|
-
sonicop --force-default-config --format quiet
|
|
283
|
+
# Sonicop, cold cache
|
|
284
|
+
sonicop --force-default-config --cache-root "$root" --format quiet
|
|
204
285
|
```
|
|
205
286
|
|
|
287
|
+
Writing the cache is part of these numbers, and it is not free: the index holds every offense with
|
|
288
|
+
the source line it was found on, which is 336 MB over `ruby/ruby`. A second run against a warm cache
|
|
289
|
+
answers in 1.59 s there, and in 0.42 s over Rails.
|
|
290
|
+
|
|
206
291
|
Machine: Apple M2 (8 cores), Ruby 4.0.6 with YJIT available, RubyGems-installed RuboCop 1.89.0.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
292
|
+
Measured on 2026-08-31 against the corpora at `rubocop_rubocop` 2693129, `mastodon_mastodon` b59ddc7,
|
|
293
|
+
`Homebrew_brew` b42173b, `rails_rails` a19f07f and `ruby_ruby` 22e4a75. The one-minute load average
|
|
294
|
+
was between 4.5 and 7.1 as each row was taken — most of it RuboCop's own parallel workers, which is
|
|
295
|
+
inherent to measuring them. **The machine was in use, not idle.** Both tools ran back to back under
|
|
296
|
+
the same conditions on each corpus, so the ratios hold, but the absolute seconds are not a floor:
|
|
297
|
+
expect better on a quiet machine. Anything competing for cores inflates both sides, and not by the
|
|
298
|
+
same factor on each, which is what makes the parallel column move as much as it does. If the
|
|
299
|
+
absolute numbers matter to you, measure on an idle machine and record the load either side of the
|
|
300
|
+
run — a figure without that context cannot be compared with another one.
|
|
216
301
|
|
|
217
302
|
## Development
|
|
218
303
|
|
|
@@ -254,6 +339,13 @@ fails when the two disagree.
|
|
|
254
339
|
`scripts/sync_default_yml.sh <rubocop-version>`, which records the source version in the file
|
|
255
340
|
header.
|
|
256
341
|
|
|
342
|
+
`src/display_width_table.rs` is generated and committed too. RuboCop measures display columns with
|
|
343
|
+
the `unicode-display_width` gem, so the table is taken from the gem rather than restated by hand —
|
|
344
|
+
an exception table written out by hand had already drifted far enough to draw the wrong number of
|
|
345
|
+
carets under decomposed Japanese. Regenerate it with
|
|
346
|
+
`ruby scripts/dump_display_width.rb > src/display_width_table.rs`, which records the gem and Unicode
|
|
347
|
+
versions in the file header.
|
|
348
|
+
|
|
257
349
|
Dependencies are updated with `depup --install`. The Ruby grammar dependency is pinned to an exact
|
|
258
350
|
fork commit in `Cargo.toml` for reproducible builds.
|
|
259
351
|
|