Module: Shirobai::Dispatch
- Defined in:
- lib/shirobai/dispatch.rb
Overview
Per-file coordinator: computes every cop’s offenses in ONE bundled ext call (‘Shirobai.check_all`), memoized by source. The first participating cop on a file triggers the bundled run; the rest read their slice from the cache.
The cache key is the ‘raw_source` identity (`equal?`, not `==`), so the autocorrect loop (which re-investigates a freshly built `ProcessedSource`) naturally recomputes, and a different file never reuses stale results.
A cop whose per-investigation config/state cannot be represented in the bundle (see each wrapper’s ‘bundle_eligible?`) skips this coordinator and calls its standalone entry point directly instead.
Constant Summary collapse
- SLOTS =
Slot order of the ‘Shirobai.check_all` result Array. Mirrors the order documented on `BundleConfig` and built by `check_all` in `ext/shirobai/src/lib.rs`; each slot carries the same shape as the cop’s standalone ‘Shirobai.check_*` return value.
{ debugger: 0, block_length: 1, block_nesting: 2, complexity: 3, variable_number: 4, method_name: 5, safe_navigation_chain: 6, multiline_operation: 7, multiline_method_call: 8, dot_position: 9, line_length: 10, line_length_breakables: 11, line_end_concatenation: 12, argument_alignment: 13, first_argument_indentation: 14, redundant_self: 15, indentation_width: 16, predicate_prefix: 17, closing_parenthesis_indentation: 18, first_array_element_indentation: 19, hash_each_methods: 20, void: 21, useless_access_modifier: 22, empty_lines_around_method_body: 23, empty_lines_around_class_body: 24, empty_lines_around_module_body: 25, empty_lines_around_block_body: 26, empty_lines_around_begin_body: 27, empty_lines_around_exception_handling_keywords: 28, block_delimiters: 29, abc_size: 30, indentation_consistency: 31, empty_line_between_defs: 32, end_alignment: 33, block_alignment: 34, else_alignment: 35, first_hash_element_indentation: 36, hash_alignment: 37, empty_lines_around_arguments: 38, hash_syntax: 39, string_literals: 40, trailing_comma_in_arguments: 41, string_literals_in_interpolation: 42, trailing_empty_lines: 43, space_around_method_call_operator: 44, space_around_keyword: 45, space_inside_block_braces: 46, method_length: 47, def_end_alignment: 48, require_parentheses: 49, self_assignment: 50, nested_parenthesized_calls: 51, parentheses_as_grouped_expression: 52, percent_literal_delimiters: 53, multiline_method_call_brace_layout: 54, access_modifier_indentation: 55, assignment_indentation: 56, redundant_self_assignment: 57, colon_method_call: 58, stabby_lambda_parentheses: 59, unreachable_code: 60, hash_transform_keys: 61, ambiguous_block_association: 62 }.freeze
Class Method Summary collapse
-
.bundle_token(config) ⇒ Object
The Rust-side token for ‘config`, registering its packed bundle config on first sight.
-
.offenses_for(processed_source, config, cop_key) ⇒ Object
Returns the raw Rust result for ‘cop_key` on this source.
Class Method Details
.bundle_token(config) ⇒ Object
The Rust-side token for ‘config`, registering its packed bundle config on first sight. Memoized per config object identity: a lint run shares one `Config` object across all cops in the team, so a run registers O(#distinct configs) entries (each spec example registers one; entries are small and never evicted).
104 105 106 107 |
# File 'lib/shirobai/dispatch.rb', line 104 def bundle_token(config) @bundle_tokens ||= {}.compare_by_identity @bundle_tokens[config] ||= Shirobai.register_bundle_config(*packed_config(config)) end |
.offenses_for(processed_source, config, cop_key) ⇒ Object
Returns the raw Rust result for ‘cop_key` on this source.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/shirobai/dispatch.rb', line 88 def offenses_for(processed_source, config, cop_key) src = processed_source.raw_source unless defined?(@cached_source) && @cached_source.equal?(src) && @cached_config.equal?(config) result = Shirobai.check_all(src, bundle_token(config)) @cached_source = src @cached_config = config @cached_result = result end @cached_result.fetch(SLOTS.fetch(cop_key)) end |