rigortype 0.4.8 → 0.4.9
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/docs/handbook/01-getting-started.md +1 -1
- data/docs/handbook/04-tuples-and-shapes.md +6 -1
- data/docs/handbook/12-lightweight-hkt.md +1 -1
- data/docs/handbook/appendix-typescript.md +28 -17
- data/docs/manual/02-cli-reference.md +10 -0
- data/docs/manual/03-configuration.md +1 -1
- data/docs/manual/04-diagnostics.md +1 -1
- data/docs/manual/10-mcp-server.md +122 -10
- data/docs/manual/plugins/rigor-activerecord.md +7 -0
- data/lib/rigor/analysis/check_rules/always_raises.rb +95 -0
- data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +32 -2
- data/lib/rigor/analysis/check_rules/argument_type.rb +802 -0
- data/lib/rigor/analysis/check_rules/call_facts.rb +2 -2
- data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +30 -1
- data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -5
- data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +34 -0
- data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +131 -4
- data/lib/rigor/analysis/check_rules/nil_receiver.rb +195 -0
- data/lib/rigor/analysis/check_rules/override_param_narrowed.rb +111 -0
- data/lib/rigor/analysis/check_rules/override_return_widened.rb +88 -0
- data/lib/rigor/analysis/check_rules/override_support.rb +246 -0
- data/lib/rigor/analysis/check_rules/override_visibility.rb +135 -0
- data/lib/rigor/analysis/check_rules/published_constant_guard.rb +75 -31
- data/lib/rigor/analysis/check_rules/raise_non_exception.rb +198 -0
- data/lib/rigor/analysis/check_rules/receiver_predicates.rb +576 -0
- data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +52 -4
- data/lib/rigor/analysis/check_rules/return_type.rb +225 -0
- data/lib/rigor/analysis/check_rules/rigor_testing.rb +119 -0
- data/lib/rigor/analysis/check_rules/rule_ids.rb +7 -7
- data/lib/rigor/analysis/check_rules/rule_walk.rb +4 -3
- data/lib/rigor/analysis/check_rules/self_closedness_scanner.rb +2 -0
- data/lib/rigor/analysis/check_rules/self_undefined_method.rb +165 -0
- data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +34 -0
- data/lib/rigor/analysis/check_rules/source_arity.rb +2 -2
- data/lib/rigor/analysis/check_rules/special_global_write.rb +256 -0
- data/lib/rigor/analysis/check_rules/suppression.rb +275 -0
- data/lib/rigor/analysis/check_rules/undefined_method.rb +882 -0
- data/lib/rigor/analysis/check_rules/unreachable_branch.rb +97 -0
- data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +42 -0
- data/lib/rigor/analysis/check_rules/unresolved_toplevel.rb +140 -0
- data/lib/rigor/analysis/check_rules/visibility_mismatch.rb +252 -0
- data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +27 -0
- data/lib/rigor/analysis/check_rules/wrong_arity.rb +303 -0
- data/lib/rigor/analysis/check_rules.rb +66 -4931
- data/lib/rigor/analysis/dependency_recorder.rb +1 -1
- data/lib/rigor/analysis/dependency_source_inference/builder.rb +2 -4
- data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -2
- data/lib/rigor/analysis/dependency_source_inference/walker.rb +15 -15
- data/lib/rigor/analysis/incremental_session.rb +4 -4
- data/lib/rigor/analysis/path_expansion.rb +1 -1
- data/lib/rigor/analysis/plugin_fact_fingerprint.rb +5 -5
- data/lib/rigor/analysis/reachability/graph.rb +2 -3
- data/lib/rigor/analysis/reachability/plugin_roots.rb +2 -2
- data/lib/rigor/analysis/reachability/scan.rb +2 -2
- data/lib/rigor/analysis/rule_catalog.rb +2 -1
- data/lib/rigor/analysis/run_cache_key.rb +9 -8
- data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
- data/lib/rigor/analysis/runner/dependency_rows.rb +206 -0
- data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +24 -22
- data/lib/rigor/analysis/runner/effect_cache_entries.rb +69 -0
- data/lib/rigor/analysis/runner/pool_coordinator.rb +6 -8
- data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -5
- data/lib/rigor/analysis/runner/scope_seed.rb +144 -0
- data/lib/rigor/analysis/runner.rb +49 -296
- data/lib/rigor/analysis/template_unit_collector.rb +1 -1
- data/lib/rigor/analysis/template_units.rb +10 -10
- data/lib/rigor/analysis/worker_session.rb +7 -7
- data/lib/rigor/bleeding_edge.rb +3 -2
- data/lib/rigor/builtins/hkt_builtins.rb +17 -17
- data/lib/rigor/builtins/imported_refinements.rb +8 -16
- data/lib/rigor/builtins/regex_refinement.rb +3 -3
- data/lib/rigor/builtins/static_return_refinements.rb +143 -19
- data/lib/rigor/cache/incremental_snapshot.rb +21 -8
- data/lib/rigor/cache/rbs_descriptor.rb +18 -1
- data/lib/rigor/cli/coverage_renderer.rb +15 -1
- data/lib/rigor/cli/coverage_report.rb +19 -1
- data/lib/rigor/cli/diagnostic_formats.rb +3 -2
- data/lib/rigor/cli/docs_command.rb +5 -5
- data/lib/rigor/cli/effects_command.rb +7 -6
- data/lib/rigor/cli/fused_protection_report.rb +7 -7
- data/lib/rigor/cli/lsp_command.rb +1 -1
- data/lib/rigor/cli/mcp_command.rb +5 -2
- data/lib/rigor/cli/options.rb +4 -0
- data/lib/rigor/cli/plugins_command.rb +1 -1
- data/lib/rigor/cli/sig_gen_command.rb +1 -1
- data/lib/rigor/cli/skill_command.rb +5 -4
- data/lib/rigor/cli/triage_renderer.rb +3 -2
- data/lib/rigor/cli/unused_command.rb +4 -4
- data/lib/rigor/cli.rb +14 -0
- data/lib/rigor/configuration/coercion.rb +418 -0
- data/lib/rigor/configuration/defaults.rb +248 -0
- data/lib/rigor/configuration/dependencies.rb +1 -1
- data/lib/rigor/configuration/loader.rb +354 -0
- data/lib/rigor/configuration/severity_profile.rb +4 -4
- data/lib/rigor/configuration.rb +51 -860
- data/lib/rigor/effects/attribution.rb +1 -1
- data/lib/rigor/effects/effect_table.rb +1 -1
- data/lib/rigor/effects/identity.rb +3 -3
- data/lib/rigor/effects/local_ownership.rb +2 -2
- data/lib/rigor/effects/snapshot.rb +1 -1
- data/lib/rigor/effects/summary.rb +5 -4
- data/lib/rigor/environment/member_consistency.rb +10 -0
- data/lib/rigor/environment/rbs_loader.rb +19 -22
- data/lib/rigor/environment/reflection.rb +1 -1
- data/lib/rigor/environment/unreadable_signature.rb +21 -0
- data/lib/rigor/environment.rb +8 -8
- data/lib/rigor/flow_contribution/merger.rb +1 -0
- data/lib/rigor/hashing/xxh3.rb +1 -1
- data/lib/rigor/inference/acceptance.rb +23 -2
- data/lib/rigor/inference/alias_mutation_floor/site_collector.rb +5 -0
- data/lib/rigor/inference/alias_mutation_floor.rb +0 -5
- data/lib/rigor/inference/anonymous_meta_class.rb +2 -2
- data/lib/rigor/inference/block_call_timing.rb +6 -0
- data/lib/rigor/inference/budget_trace.rb +3 -2
- data/lib/rigor/inference/builtins/date_catalog.rb +3 -3
- data/lib/rigor/inference/builtins/method_catalog.rb +3 -3
- data/lib/rigor/inference/builtins/time_catalog.rb +3 -3
- data/lib/rigor/inference/call_ladder/literal_send.rb +98 -0
- data/lib/rigor/inference/call_ladder/overriding_def.rb +98 -0
- data/lib/rigor/inference/call_ladder/project_singleton.rb +362 -0
- data/lib/rigor/inference/call_ladder/refined.rb +212 -0
- data/lib/rigor/inference/call_ladder/top_level_def.rb +222 -0
- data/lib/rigor/inference/call_ladder/user_method.rb +247 -0
- data/lib/rigor/inference/call_ladder.rb +219 -0
- data/lib/rigor/inference/callee_write_census.rb +2 -2
- data/lib/rigor/inference/captured_locals.rb +2 -2
- data/lib/rigor/inference/clause_widening.rb +63 -1
- data/lib/rigor/inference/declaration_walk/context.rb +12 -12
- data/lib/rigor/inference/declaration_walk/rules.rb +750 -0
- data/lib/rigor/inference/declaration_walk/traversal.rb +9 -8
- data/lib/rigor/inference/declaration_walk.rb +4 -3
- data/lib/rigor/inference/def_node_resolver.rb +2 -2
- data/lib/rigor/inference/def_return_typer.rb +14 -6
- data/lib/rigor/inference/deferred_mutation.rb +120 -0
- data/lib/rigor/inference/define_method_block_self.rb +1 -1
- data/lib/rigor/inference/definer_resolution.rb +4 -4
- data/lib/rigor/inference/error_info.rb +8 -8
- data/lib/rigor/inference/expression_typer/composites.rb +348 -0
- data/lib/rigor/inference/expression_typer/per_element_assemblers.rb +233 -0
- data/lib/rigor/inference/expression_typer/writes.rb +218 -0
- data/lib/rigor/inference/expression_typer.rb +275 -1825
- data/lib/rigor/inference/external_ancestor_resolution.rb +2 -2
- data/lib/rigor/inference/fallback.rb +1 -0
- data/lib/rigor/inference/for_yield_slots.rb +126 -0
- data/lib/rigor/inference/genuine_send.rb +92 -0
- data/lib/rigor/inference/global_write_census.rb +2 -2
- data/lib/rigor/inference/hkt_body.rb +2 -0
- data/lib/rigor/inference/in_effect_refinements/walk.rb +2 -2
- data/lib/rigor/inference/index_write_widening.rb +4 -4
- data/lib/rigor/inference/indexed_narrowing.rb +1 -1
- data/lib/rigor/inference/intervening_ivar_reset.rb +46 -9
- data/lib/rigor/inference/ivar_writer_census.rb +1 -1
- data/lib/rigor/inference/loop_store_sites.rb +239 -0
- data/lib/rigor/inference/macro_block_self_type.rb +4 -3
- data/lib/rigor/inference/method_dispatcher/block_folding.rb +3 -2
- data/lib/rigor/inference/method_dispatcher/call_context.rb +84 -14
- data/lib/rigor/inference/method_dispatcher/composite_receiver.rb +144 -0
- data/lib/rigor/inference/method_dispatcher/constant_folding.rb +7 -5
- data/lib/rigor/inference/method_dispatcher/declared_constructor.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/dependency_source.rb +90 -0
- data/lib/rigor/inference/method_dispatcher/discovered_method.rb +78 -0
- data/lib/rigor/inference/method_dispatcher/file_folding.rb +2 -2
- data/lib/rigor/inference/method_dispatcher/hkt_builtin_return.rb +40 -0
- data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -6
- data/lib/rigor/inference/method_dispatcher/literal_string_folding.rb +4 -2
- data/lib/rigor/inference/method_dispatcher/match_data_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/meta_introspection.rb +506 -0
- data/lib/rigor/inference/method_dispatcher/overload_selector.rb +2 -0
- data/lib/rigor/inference/method_dispatcher/plugin_contribution.rb +134 -0
- data/lib/rigor/inference/method_dispatcher/project_patched.rb +134 -0
- data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +125 -43
- data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +3 -4
- data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/set_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +19 -6
- data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +3 -3
- data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +7 -4
- data/lib/rigor/inference/method_dispatcher/static_refinement.rb +106 -0
- data/lib/rigor/inference/method_dispatcher/synthesized_stub.rb +41 -0
- data/lib/rigor/inference/method_dispatcher/synthetic_method_dispatch.rb +133 -0
- data/lib/rigor/inference/method_dispatcher/universal_object_dispatch.rb +2 -1
- data/lib/rigor/inference/method_dispatcher/user_class_fallback.rb +216 -0
- data/lib/rigor/inference/method_dispatcher.rb +175 -1361
- data/lib/rigor/inference/method_parameter_binder.rb +18 -18
- data/lib/rigor/inference/module_function_state.rb +5 -4
- data/lib/rigor/inference/mutation_widening.rb +20 -7
- data/lib/rigor/inference/narrowing/case_literals.rb +58 -0
- data/lib/rigor/inference/narrowing/class_dispatch.rb +302 -0
- data/lib/rigor/inference/narrowing/complements.rb +322 -0
- data/lib/rigor/inference/narrowing/presence_predicates.rb +205 -0
- data/lib/rigor/inference/narrowing/regex_match.rb +499 -0
- data/lib/rigor/inference/narrowing.rb +86 -1269
- data/lib/rigor/inference/object_mixins.rb +2 -2
- data/lib/rigor/inference/opaque_mutation.rb +214 -0
- data/lib/rigor/inference/optimistic_origin.rb +52 -14
- data/lib/rigor/inference/parameter_inference_collector.rb +1 -1
- data/lib/rigor/inference/pre_eval_constants.rb +11 -9
- data/lib/rigor/inference/precision_scanner.rb +27 -2
- data/lib/rigor/inference/project_patched_methods.rb +3 -3
- data/lib/rigor/inference/range_constant.rb +3 -3
- data/lib/rigor/inference/rbs_type_translator.rb +2 -2
- data/lib/rigor/inference/refine_self.rb +8 -7
- data/lib/rigor/inference/refined_dispatch.rb +2 -2
- data/lib/rigor/inference/return_barrier.rb +24 -9
- data/lib/rigor/inference/scope_indexer/alias_def_nodes.rb +311 -0
- data/lib/rigor/inference/scope_indexer/census_scope.rb +47 -0
- data/lib/rigor/inference/scope_indexer/certainty.rb +2 -2
- data/lib/rigor/inference/scope_indexer/class_cvar_census.rb +282 -0
- data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +12 -5
- data/lib/rigor/inference/scope_indexer/class_declarations.rb +228 -0
- data/lib/rigor/inference/scope_indexer/class_ivar_index.rb +2028 -0
- data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +4 -3
- data/lib/rigor/inference/scope_indexer/constant_tables.rb +844 -0
- data/lib/rigor/inference/scope_indexer/cvar_hierarchy.rb +159 -0
- data/lib/rigor/inference/scope_indexer/declaration_artifacts.rb +219 -0
- data/lib/rigor/inference/scope_indexer/declaration_signature.rb +212 -0
- data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +2 -2
- data/lib/rigor/inference/scope_indexer/factory_call_resolver.rb +53 -0
- data/lib/rigor/inference/scope_indexer/literal_receiver_mutations.rb +266 -0
- data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +8 -7
- data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +1 -1
- data/lib/rigor/inference/scope_indexer/mixin_effects.rb +470 -0
- data/lib/rigor/inference/scope_indexer/mixin_tables.rb +388 -0
- data/lib/rigor/inference/scope_indexer/mutated_carrier_widening.rb +163 -0
- data/lib/rigor/inference/scope_indexer/mutated_element_census.rb +211 -0
- data/lib/rigor/inference/scope_indexer/node_propagation.rb +520 -0
- data/lib/rigor/inference/scope_indexer/program_globals.rb +154 -0
- data/lib/rigor/inference/scope_indexer/published_constant_cvars.rb +146 -0
- data/lib/rigor/inference/scope_indexer/published_constant_ivars.rb +181 -0
- data/lib/rigor/inference/scope_indexer/shared_walk_tables.rb +823 -0
- data/lib/rigor/inference/scope_indexer/singleton_class_sources.rb +85 -0
- data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +5 -5
- data/lib/rigor/inference/scope_indexer.rb +2657 -9558
- data/lib/rigor/inference/self_call_ivar_writes.rb +22 -3
- data/lib/rigor/inference/set_mutation.rb +2 -2
- data/lib/rigor/inference/singleton_hook_definers.rb +185 -0
- data/lib/rigor/inference/statement_evaluator/def_arguments_and_assertions.rb +365 -0
- data/lib/rigor/inference/statement_evaluator/pattern_bindings.rb +581 -0
- data/lib/rigor/inference/statement_evaluator.rb +201 -1008
- data/lib/rigor/inference/synthetic_method_scanner.rb +0 -3
- data/lib/rigor/language_server/completion_provider.rb +8 -8
- data/lib/rigor/language_server/diagnostic_publisher.rb +6 -7
- data/lib/rigor/language_server/document_symbol_provider.rb +4 -6
- data/lib/rigor/language_server/folding_range_provider.rb +3 -3
- data/lib/rigor/language_server/hover_provider.rb +2 -2
- data/lib/rigor/language_server/loop.rb +2 -2
- data/lib/rigor/language_server/server.rb +3 -2
- data/lib/rigor/language_server/signature_help_provider.rb +7 -9
- data/lib/rigor/lens/document.rb +10 -1
- data/lib/rigor/lens/file_reader.rb +2 -1
- data/lib/rigor/mcp/loop.rb +48 -6
- data/lib/rigor/mcp/server.rb +248 -23
- data/lib/rigor/mcp/skill_catalog.rb +157 -0
- data/lib/rigor/plugin/base.rb +22 -4
- data/lib/rigor/plugin/effect_attribution.rb +1 -1
- data/lib/rigor/plugin/inflector.rb +2 -2
- data/lib/rigor/plugin/io_boundary.rb +1 -1
- data/lib/rigor/plugin/loader.rb +4 -4
- data/lib/rigor/plugin/macro/heredoc_template.rb +4 -3
- data/lib/rigor/plugin/optimistic_return.rb +20 -0
- data/lib/rigor/plugin/registry.rb +2 -2
- data/lib/rigor/plugin/template_unit.rb +4 -2
- data/lib/rigor/plugin/trust_policy.rb +2 -1
- data/lib/rigor/plugin.rb +1 -1
- data/lib/rigor/protection/mutator.rb +8 -9
- data/lib/rigor/rbs_extended/reporter.rb +2 -2
- data/lib/rigor/rbs_extended.rb +2 -2
- data/lib/rigor/reflection/constant_ancestors.rb +1 -1
- data/lib/rigor/reflection/project_method.rb +2 -2
- data/lib/rigor/reflection.rb +4 -4
- data/lib/rigor/scope/discovery_index.rb +15 -10
- data/lib/rigor/scope/resolution_chain.rb +29 -6
- data/lib/rigor/scope.rb +89 -32
- data/lib/rigor/sig_gen/generator.rb +5 -4
- data/lib/rigor/sig_gen/renderer.rb +3 -3
- data/lib/rigor/sig_gen/writer.rb +8 -6
- data/lib/rigor/source/parameter_envelope.rb +1 -1
- data/lib/rigor/triage/catalogue.rb +4 -4
- data/lib/rigor/type/combinator.rb +2 -2
- data/lib/rigor/type/data_instance.rb +2 -2
- data/lib/rigor/type/struct_instance.rb +3 -3
- data/lib/rigor/type_node/generic.rb +2 -1
- data/lib/rigor/type_of_memo.rb +2 -1
- data/lib/rigor/typing_state.rb +3 -2
- data/lib/rigor/version.rb +1 -1
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/analyzer.rb +2 -2
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +1 -1
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +4 -4
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_discoverer.rb +4 -3
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/effects.rb +7 -5
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +4 -2
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/render_locals.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +3 -2
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +7 -7
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob/job_discoverer.rb +1 -1
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +2 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +9 -8
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +3 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +15 -7
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +10 -3
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/structure_sql_parser.rb +12 -1
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +20 -5
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +1 -1
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +3 -2
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext/effects.rb +1 -1
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +8 -7
- data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema.rb +1 -1
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +1 -1
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +6 -7
- data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +3 -2
- data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +4 -3
- data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +4 -2
- data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +1 -1
- data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +1 -1
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +5 -3
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +1 -1
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +4 -5
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/doorkeeper_routes.rb +2 -2
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +5 -4
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_table.rb +3 -2
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +30 -31
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +13 -15
- data/plugins/rigor-rbnacl/lib/rigor/plugin/rbnacl.rb +1 -1
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +4 -3
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +16 -13
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/scope_walker.rb +3 -2
- data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -6
- data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq/analyzer.rb +3 -3
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +3 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog_walker.rb +6 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +4 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/type_translator.rb +1 -1
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +3 -4
- data/sig/rigor/analysis/check_rules/suppression.rbs +9 -0
- data/sig/rigor/analysis/dependency_recorder.rbs +9 -0
- data/sig/rigor/inference.rbs +275 -11
- data/sig/rigor/plugin/base.rbs +14 -5
- data/sig/rigor/plugin/optimistic_return.rbs +16 -0
- data/sig/rigor/scope.rbs +7 -1
- data/sig/rigor/source.rbs +4 -0
- data/skills/rigor-mcp-setup/SKILL.md +20 -6
- data/skills/rigor-plugin-review/SKILL.md +3 -3
- data/skills/rigor-type-oracle/references/01-oracle-commands.md +1 -1
- metadata +90 -3
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
require "prism"
|
|
4
4
|
|
|
5
|
+
require_relative "../../source/literals"
|
|
5
6
|
require_relative "../../source/node_children"
|
|
7
|
+
require_relative "../diagnostic"
|
|
8
|
+
require_relative "rule_ids"
|
|
6
9
|
|
|
7
10
|
module Rigor
|
|
8
11
|
module Analysis
|
|
@@ -15,7 +18,8 @@ module Rigor
|
|
|
15
18
|
# The check is purely syntactic (no type engine involved) with a frame-aware envelope so it only
|
|
16
19
|
# flags a `return` that actually belongs to the frame whose `ensure` it sits in:
|
|
17
20
|
#
|
|
18
|
-
# - A `return` inside a nested `def`, a lambda (`-> {}` / `lambda {}`), or a `define_method` block
|
|
21
|
+
# - A `return` inside a nested `def`, a lambda (`-> {}` / `lambda {}`), or a `define_method` block (also the
|
|
22
|
+
# block of `send` / `__send__` / `public_send` naming `define_method` by a literal Symbol or String)
|
|
19
23
|
# within the ensure body is skipped — that `return` exits the inner frame, not the one whose
|
|
20
24
|
# in-flight exception the ensure guards.
|
|
21
25
|
# - A `return` inside a *plain* block (`each do ... return ... end`) within the ensure body DOES
|
|
@@ -37,6 +41,11 @@ module Rigor
|
|
|
37
41
|
# stays in scope for the rule.
|
|
38
42
|
FRAME_BARRIER_CALL_NAMES = %i[lambda define_method].freeze
|
|
39
43
|
|
|
44
|
+
# The reflective spellings that reach `define_method` by a literal name (`send(:define_method, :w) { … }`).
|
|
45
|
+
# `public_send` is included: `define_method` has been public since Ruby 2.5. Their receiver is any, so
|
|
46
|
+
# `self.class.send(:define_method, …)` is a barrier too, as the literal name is what the call makes.
|
|
47
|
+
REFLECTIVE_SEND_CALL_NAMES = %i[send __send__ public_send].freeze
|
|
48
|
+
|
|
40
49
|
def initialize(scope_index)
|
|
41
50
|
@scope_index = scope_index
|
|
42
51
|
@results = []
|
|
@@ -60,6 +69,35 @@ module Rigor
|
|
|
60
69
|
@results.freeze
|
|
61
70
|
end
|
|
62
71
|
|
|
72
|
+
# ADR-116 WD1 — the message builder for this collector's results, moved here from `CheckRules`.
|
|
73
|
+
# {.diagnostics} is called by `CheckRules.diagnose` through its collector table; the rest is private to it.
|
|
74
|
+
|
|
75
|
+
# v0.3.0 — `flow.return-in-ensure`. One diagnostic per explicit
|
|
76
|
+
# `return` lexically inside an `ensure` clause body: it silently
|
|
77
|
+
# discards the method's in-flight return value and swallows any
|
|
78
|
+
# in-flight exception. Purely syntactic; the
|
|
79
|
+
# `Analysis::CheckRules::ReturnInEnsureCollector` describes the
|
|
80
|
+
# frame-aware envelope (nested def / lambda / `define_method`
|
|
81
|
+
# blocks are excluded, plain blocks are not).
|
|
82
|
+
def self.diagnostics(path, results)
|
|
83
|
+
results.map do |result|
|
|
84
|
+
build_return_in_ensure_diagnostic(path, result[:return_node])
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.build_return_in_ensure_diagnostic(path, return_node)
|
|
89
|
+
Diagnostic.from_location(
|
|
90
|
+
return_node.keyword_loc,
|
|
91
|
+
rule: RULE_RETURN_IN_ENSURE,
|
|
92
|
+
path: path,
|
|
93
|
+
message: "`return' inside `ensure' discards the method's in-flight return value " \
|
|
94
|
+
"and swallows any in-flight exception",
|
|
95
|
+
severity: :warning
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private_class_method :build_return_in_ensure_diagnostic
|
|
100
|
+
|
|
63
101
|
private
|
|
64
102
|
|
|
65
103
|
def walk_for_begin_nodes(node)
|
|
@@ -106,9 +144,19 @@ module Rigor
|
|
|
106
144
|
end
|
|
107
145
|
|
|
108
146
|
def frame_barrier_call?(call_node)
|
|
109
|
-
call_node.
|
|
110
|
-
|
|
111
|
-
|
|
147
|
+
return false unless call_node.block.is_a?(Prism::BlockNode)
|
|
148
|
+
|
|
149
|
+
(call_node.receiver.nil? && FRAME_BARRIER_CALL_NAMES.include?(call_node.name)) ||
|
|
150
|
+
reflective_define_method_call?(call_node)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# `send(:define_method, …)` and the other spellings in REFLECTIVE_SEND_CALL_NAMES, when the first argument
|
|
154
|
+
# is a literal Symbol or String naming `define_method`. A computed name is not read and keeps today's answer.
|
|
155
|
+
def reflective_define_method_call?(call_node)
|
|
156
|
+
return false unless REFLECTIVE_SEND_CALL_NAMES.include?(call_node.name)
|
|
157
|
+
|
|
158
|
+
first = call_node.arguments&.arguments&.first
|
|
159
|
+
Source::Literals.symbol_or_string(first) == :define_method
|
|
112
160
|
end
|
|
113
161
|
end
|
|
114
162
|
end
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
require_relative "../../reflection"
|
|
5
|
+
require_relative "../../rbs_extended"
|
|
6
|
+
require_relative "../../inference/scope_indexer"
|
|
7
|
+
require_relative "../diagnostic"
|
|
8
|
+
require_relative "declaration_sourced_guard"
|
|
9
|
+
require_relative "override_support"
|
|
10
|
+
require_relative "replaced_singleton_defs"
|
|
11
|
+
require_relative "rule_ids"
|
|
12
|
+
|
|
13
|
+
module Rigor
|
|
14
|
+
module Analysis
|
|
15
|
+
module CheckRules
|
|
16
|
+
# ADR-116 WD1 — `def.return-type-mismatch` (ADR-8): a `def` whose body's last expression types as
|
|
17
|
+
# something its RBS-declared return cannot accept, with the declines the rule has accumulated (an
|
|
18
|
+
# inherited declaration, a `refine` body, a replaced singleton def, a builtin global read, a `Dynamic`
|
|
19
|
+
# body).
|
|
20
|
+
#
|
|
21
|
+
# The entry point is {.diagnostic}, called by `CheckRules.main_pass_node_diagnostics`. It reads
|
|
22
|
+
# {OverrideSupport} (`declared_return_union`, `dynamic_top?` and `defined_on?`, which the override
|
|
23
|
+
# rules call too) and {DeclarationSourcedGuard}, and calls nothing in `CheckRules`.
|
|
24
|
+
module ReturnType
|
|
25
|
+
module_function
|
|
26
|
+
|
|
27
|
+
# Issue #1120, maintainer ruling a′ — a `def` in a `refine X do … end` body redefines X's method by design, so
|
|
28
|
+
# X's declared return for the name is not its contract and a mismatch against it is not reported. Every other
|
|
29
|
+
# check in the body stands. The refine-body test runs only once a mismatch would report, so a file pays the
|
|
30
|
+
# {LexicalMethodSites} walk only then.
|
|
31
|
+
def diagnostic(path, node, scope_index, lexical_sites)
|
|
32
|
+
replaced = lexical_sites&.replaced_singleton_defs(scope_index)
|
|
33
|
+
diagnostic = return_type_mismatch_diagnostic(path, node, scope_index, replaced)
|
|
34
|
+
return diagnostic if diagnostic.nil? || lexical_sites.nil?
|
|
35
|
+
|
|
36
|
+
lexical_sites.refinements.refinement_def?(node) ? nil : diagnostic
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# ADR-8 § "`def.return-type-mismatch` rule" — flags a `def m(...) ... end` whose body's last
|
|
40
|
+
# expression's type cannot satisfy the RBS-declared return type. Conservative envelope (v0.1.x
|
|
41
|
+
# first cut):
|
|
42
|
+
#
|
|
43
|
+
# - Skips methods without an RBS declaration. The rule has no contract to compare against for
|
|
44
|
+
# source-only methods.
|
|
45
|
+
# - Skips a `def` whose only declaration was resolved through an ANCESTOR. `Reflection`'s lookup
|
|
46
|
+
# reads the fully resolved method table, so a signature written about a base class answers for
|
|
47
|
+
# every subclass that inherits the name; comparing an override's body against it reports the
|
|
48
|
+
# override wrong for disagreeing with a contract that was never written about it (#744, and
|
|
49
|
+
# the four redmine sites in #856). ADR-35 already specifies this rule as comparing a method's
|
|
50
|
+
# OWN declared return, and the sibling override rules gate on `defined_on?` — this one did not.
|
|
51
|
+
# The inherited-declaration signal belongs to the ADR-35 family, which requires both sides
|
|
52
|
+
# authored. Decided in ADR-110 WD3.
|
|
53
|
+
# - Skips methods whose enclosing `self` names no class (top-level methods land outside the rule).
|
|
54
|
+
# - Skips methods whose body's last expression is absent or types as `Dynamic[top]` (the
|
|
55
|
+
# analyzer's fail-soft fallback) — emitting on `Dynamic[top]` would be noise.
|
|
56
|
+
# - Compares the inferred body type against the declared return via `accepts?`:
|
|
57
|
+
# :yes → silent
|
|
58
|
+
# :no → emit at :error (severity_profile may re-stamp; default `balanced` keeps the
|
|
59
|
+
# authored severity).
|
|
60
|
+
# :maybe → silent (see {#compare_return}; ADR-8's `strict` promotion is deferred).
|
|
61
|
+
def return_type_mismatch_diagnostic(path, def_node, scope_index, replaced_defs = nil)
|
|
62
|
+
return nil if def_node.body.nil?
|
|
63
|
+
|
|
64
|
+
last_expr = body_last_expression(def_node.body)
|
|
65
|
+
return nil if last_expr.nil?
|
|
66
|
+
|
|
67
|
+
inner_scope = scope_index[last_expr] || scope_index[def_node.body] || scope_index[def_node]
|
|
68
|
+
return nil if inner_scope.nil?
|
|
69
|
+
|
|
70
|
+
declared = declared_return_type(def_node, scope_index, replaced_defs)
|
|
71
|
+
return nil if declared.nil?
|
|
72
|
+
|
|
73
|
+
# Issue #1362 — a body that ends on a builtin global still on its declared seed, or on a local copied from
|
|
74
|
+
# one, is judged by the file's writes to the global, as for an argument ({#single_argument_mismatch}).
|
|
75
|
+
inferred = DeclarationSourcedGuard.written_type(last_expr, inner_scope) || inner_scope.type_of(last_expr)
|
|
76
|
+
return nil if OverrideSupport.dynamic_top?(inferred)
|
|
77
|
+
|
|
78
|
+
severity = compare_return(declared, inferred)
|
|
79
|
+
return nil if severity.nil?
|
|
80
|
+
return nil if declared_only_return?(last_expr, inferred, declared, inner_scope)
|
|
81
|
+
|
|
82
|
+
build_return_type_mismatch_diagnostic(path, def_node, declared, inferred, severity)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Issue #1362 — a body that ends on a value mixing a builtin global's seed with something else is judged
|
|
86
|
+
# without the declared members the file never writes, as for an argument.
|
|
87
|
+
def declared_only_return?(last_expr, inferred, declared, scope)
|
|
88
|
+
return false unless DeclarationSourcedGuard.global_sources(last_expr, scope).empty?
|
|
89
|
+
|
|
90
|
+
DeclarationSourcedGuard.declared_only_rejection?(inferred, declared, scope) do |stripped|
|
|
91
|
+
compare_return(declared, stripped).nil?
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# The body of a `def` is the last `Prism::StatementsNode` child (or a single expression for
|
|
96
|
+
# one-liner defs). Take the last statement; that's the implicit return.
|
|
97
|
+
def body_last_expression(body)
|
|
98
|
+
case body
|
|
99
|
+
when Prism::StatementsNode then body.body.last
|
|
100
|
+
when Prism::BeginNode then body_last_expression(body.statements)
|
|
101
|
+
else body
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Pulls the declared RBS return type for the def. The enclosing class name comes from the def's
|
|
106
|
+
# scope's `self_type`; the method name is on the def itself. `def self.foo` is a singleton method
|
|
107
|
+
# — dispatched through `Reflection.singleton_method_definition`; plain `def foo` uses
|
|
108
|
+
# `instance_method_definition`. Method overloads contribute their union of declared return types
|
|
109
|
+
# (any one of them satisfying the body silences the rule).
|
|
110
|
+
#
|
|
111
|
+
# v0.1.2 — when the RBS sig carries a `%a{rigor:v1:return: <refinement>}` annotation (recognised by
|
|
112
|
+
# `RbsExtended.read_return_type_override`), the refinement carrier replaces the RBS-declared return
|
|
113
|
+
# for this rule. Annotation-driven refinements — `non-empty-string`, `positive-int`,
|
|
114
|
+
# `non-empty-array[Integer]`, etc. — are stricter than the underlying RBS class, so a body whose
|
|
115
|
+
# inferred type the bare RBS sig would accept may still fail the refinement (e.g. `def name; "";
|
|
116
|
+
# end` returns `Constant[""]`, accepted by `String` but rejected by `non-empty-string`).
|
|
117
|
+
def declared_return_type(def_node, scope_index, replaced_defs = nil)
|
|
118
|
+
scope = scope_index[def_node]
|
|
119
|
+
return nil if scope.nil?
|
|
120
|
+
|
|
121
|
+
self_type = scope.self_type
|
|
122
|
+
return nil unless self_type.respond_to?(:class_name)
|
|
123
|
+
|
|
124
|
+
side = if def_node.receiver.nil?
|
|
125
|
+
receiverless_def_side(scope, self_type.class_name, def_node)
|
|
126
|
+
else
|
|
127
|
+
receiver_def_side(scope, self_type.class_name, def_node)
|
|
128
|
+
end
|
|
129
|
+
return nil if side.nil?
|
|
130
|
+
|
|
131
|
+
method_def =
|
|
132
|
+
if side == :instance
|
|
133
|
+
Reflection.instance_method_definition(self_type.class_name, def_node.name, scope: scope)
|
|
134
|
+
else
|
|
135
|
+
Reflection.singleton_method_definition(self_type.class_name, def_node.name, scope: scope)
|
|
136
|
+
end
|
|
137
|
+
return nil if method_def.nil?
|
|
138
|
+
return nil unless OverrideSupport.defined_on?(method_def, self_type.class_name)
|
|
139
|
+
return nil if replaced_receiver_def?(def_node, replaced_defs)
|
|
140
|
+
|
|
141
|
+
override = Rigor::RbsExtended.read_return_type_override(method_def, environment: scope.environment)
|
|
142
|
+
return override if override
|
|
143
|
+
|
|
144
|
+
OverrideSupport.declared_return_union(method_def, scope.environment)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Which side a receiverless `def` defines, from the indexer's own record of THAT node: the instance table
|
|
148
|
+
# holding it makes it an instance def, the singleton table (`class << self` bodies, and a `def` under
|
|
149
|
+
# `Const.instance_eval` that the indexer attributes to the singleton) a singleton def. A node neither table
|
|
150
|
+
# holds (a `def` in a block whose `self` the engine does not model, such as `E.class_eval do` inside
|
|
151
|
+
# `class << self`, a redefinition a later `def` replaced) or both do is `nil`, and the caller declines: no
|
|
152
|
+
# world is consulted, but the record cannot say which signature the body answers to.
|
|
153
|
+
def receiverless_def_side(scope, class_name, def_node)
|
|
154
|
+
instance = same_def_node?(scope.user_def_for(class_name, def_node.name), def_node)
|
|
155
|
+
singleton = same_def_node?(scope.singleton_def_for(class_name, def_node.name), def_node)
|
|
156
|
+
return :instance if instance && !singleton
|
|
157
|
+
return :singleton if singleton && !instance
|
|
158
|
+
|
|
159
|
+
nil
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Issue #3155 — a singleton def a later certain def replaced ({ReplacedSingletonDefs}). Asked only once the def
|
|
163
|
+
# has a signature to answer to, so the file walk runs only then.
|
|
164
|
+
def replaced_receiver_def?(def_node, replaced_defs)
|
|
165
|
+
!def_node.receiver.nil? && replaced_defs&.replaced?(def_node)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Issue #3155 — `def self.x`, or `def K.x` in `K`'s body, answers to K's singleton signature. A def on another
|
|
169
|
+
# object (`def String.q`, `def obj.q` in a class body) or `def self.x` in a `class << self` body (a method of
|
|
170
|
+
# the singleton class's own singleton) answers to none of K's: `nil`, and the caller declines.
|
|
171
|
+
# {#declared_return_type} also declines, once a signature is found, a singleton def a later certain def of the
|
|
172
|
+
# name in the same body replaced (`def K.w`; `def self.w`; {ReplacedSingletonDefs}). `def (self).x` reads as
|
|
173
|
+
# `def self.x`; `K = self; def K.x` is not read.
|
|
174
|
+
def receiver_def_side(scope, class_name, def_node)
|
|
175
|
+
receiver = ReplacedSingletonDefs.unparenthesized(def_node.receiver)
|
|
176
|
+
lexical_self = if receiver.is_a?(Prism::SelfNode)
|
|
177
|
+
!scope.singleton_class_body?
|
|
178
|
+
else
|
|
179
|
+
Inference::ScopeIndexer.def_receiver_targets_lexical_self?(receiver, class_name.split("::"))
|
|
180
|
+
end
|
|
181
|
+
return nil unless lexical_self
|
|
182
|
+
|
|
183
|
+
:singleton
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# The tables hold the live node or one re-resolved from a `DefHandle`, so identity is the name and span.
|
|
187
|
+
def same_def_node?(recorded, def_node)
|
|
188
|
+
recorded.is_a?(Prism::DefNode) && recorded.name == def_node.name &&
|
|
189
|
+
recorded.location.start_offset == def_node.location.start_offset &&
|
|
190
|
+
recorded.location.end_offset == def_node.location.end_offset
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Returns the severity to emit at, or nil to stay silent. The first-cut implementation only fires
|
|
194
|
+
# on proven (`:no`) mismatches; `:maybe` is treated as silent until the analyzer's narrowing
|
|
195
|
+
# becomes precise enough to avoid noise on common patterns (`{}` → declared `Hash[K, V]`,
|
|
196
|
+
# `Set.new` → declared `Set[Symbol]`, …). ADR-8's promise to emit on `:maybe` under
|
|
197
|
+
# `severity_profile: strict` is deferred to a follow-up that lands together with the narrowing
|
|
198
|
+
# precision improvements.
|
|
199
|
+
def compare_return(declared, inferred)
|
|
200
|
+
result = declared.accepts(inferred)
|
|
201
|
+
return nil unless result.no?
|
|
202
|
+
|
|
203
|
+
:error
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def build_return_type_mismatch_diagnostic(path, def_node, declared, inferred, severity)
|
|
207
|
+
Diagnostic.from_name_loc(
|
|
208
|
+
def_node,
|
|
209
|
+
rule: RULE_RETURN_TYPE,
|
|
210
|
+
path: path,
|
|
211
|
+
message: "return-type mismatch on `#{def_node.name}': " \
|
|
212
|
+
"declared #{declared.describe(:short)}, inferred #{inferred.describe(:short)}",
|
|
213
|
+
severity: severity,
|
|
214
|
+
method_name: def_node.name.to_s
|
|
215
|
+
)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
private_class_method :return_type_mismatch_diagnostic, :declared_only_return?, :body_last_expression,
|
|
219
|
+
:declared_return_type, :receiverless_def_side, :replaced_receiver_def?,
|
|
220
|
+
:receiver_def_side, :same_def_node?, :compare_return,
|
|
221
|
+
:build_return_type_mismatch_diagnostic
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
require_relative "../../source/constant_path"
|
|
5
|
+
require_relative "../diagnostic"
|
|
6
|
+
|
|
7
|
+
module Rigor
|
|
8
|
+
module Analysis
|
|
9
|
+
module CheckRules
|
|
10
|
+
# ADR-116 WD1 — the two `Rigor::Testing` assertion rules: `dump.type` ({.dump_diagnostic},
|
|
11
|
+
# `Rigor::Testing.dump_type(expr)`) and `assert.type-mismatch` ({.assert_diagnostic},
|
|
12
|
+
# `Rigor::Testing.assert_type(expected, expr)`).
|
|
13
|
+
#
|
|
14
|
+
# Both are entry points, called by `CheckRules.call_node_diagnostics`; the module calls nothing else in
|
|
15
|
+
# `CheckRules`.
|
|
16
|
+
module RigorTesting
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
# Slice 7 phase 19 — PHPStan-style `dump_type(value)`. When the engine recognises a call to
|
|
20
|
+
# `dump_type` (with any of the supported receiver shapes — implicit self after `include
|
|
21
|
+
# Rigor::Testing`, `Rigor::Testing.dump_type`, or `Rigor.dump_type`), it emits an `:info` diagnostic
|
|
22
|
+
# showing the inferred type of the argument expression. The diagnostic does NOT count toward
|
|
23
|
+
# `Result#error_count` so a fixture peppered with `dump_type` calls still passes `rigor check`.
|
|
24
|
+
def dump_diagnostic(path, call_node, scope_index)
|
|
25
|
+
return nil unless rigor_testing_call?(call_node, :dump_type)
|
|
26
|
+
return nil if call_node.arguments.nil? || call_node.arguments.arguments.empty?
|
|
27
|
+
|
|
28
|
+
arg = call_node.arguments.arguments.first
|
|
29
|
+
scope = scope_index[arg] || scope_index[call_node]
|
|
30
|
+
return nil if scope.nil?
|
|
31
|
+
return nil if inside_rigor_testing?(scope)
|
|
32
|
+
|
|
33
|
+
type = scope.type_of(arg)
|
|
34
|
+
Diagnostic.from_message_loc(
|
|
35
|
+
call_node,
|
|
36
|
+
path: path,
|
|
37
|
+
message: "dump_type: #{type.describe(:short)}",
|
|
38
|
+
severity: :info,
|
|
39
|
+
rule: RULE_DUMP_TYPE
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Slice 7 phase 19 — PHPStan-style `assert_type("...", value)`. The first argument MUST be a
|
|
44
|
+
# string literal containing the expected `Type#describe(:short)` rendering. When the inferred
|
|
45
|
+
# type's short description does not equal the expected literal, an `:error`-severity diagnostic is
|
|
46
|
+
# emitted; matching calls produce no output. This lets a fixture document its expected types
|
|
47
|
+
# inline: subsequent `rigor check` runs flag any drift.
|
|
48
|
+
def assert_diagnostic(path, call_node, scope_index)
|
|
49
|
+
return nil unless rigor_testing_call?(call_node, :assert_type)
|
|
50
|
+
return nil if call_node.arguments.nil? || call_node.arguments.arguments.size < 2
|
|
51
|
+
|
|
52
|
+
expected_node = call_node.arguments.arguments.first
|
|
53
|
+
return nil unless expected_node.is_a?(Prism::StringNode)
|
|
54
|
+
|
|
55
|
+
value_node = call_node.arguments.arguments[1]
|
|
56
|
+
scope = scope_index[value_node] || scope_index[call_node]
|
|
57
|
+
return nil if scope.nil?
|
|
58
|
+
return nil if inside_rigor_testing?(scope)
|
|
59
|
+
|
|
60
|
+
actual = scope.type_of(value_node).describe(:short)
|
|
61
|
+
expected = expected_node.unescaped.to_s
|
|
62
|
+
return nil if actual == expected
|
|
63
|
+
|
|
64
|
+
build_assert_type_diagnostic(path, call_node, expected, actual)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Recognises any of:
|
|
68
|
+
# `dump_type(x)` (implicit self after `include Rigor::Testing`)
|
|
69
|
+
# `Testing.dump_type(x)`
|
|
70
|
+
# `Rigor.dump_type(x)`
|
|
71
|
+
# `Rigor::Testing.dump_type(x)`
|
|
72
|
+
# The receiver check is purely structural — we do not consult RBS — because the helpers are no-op
|
|
73
|
+
# stubs the user MAY shadow with their own definition; a name clash is the deliberate trade-off for
|
|
74
|
+
# ergonomic invocation.
|
|
75
|
+
RIGOR_TESTING_RECEIVERS = ["Rigor", "Rigor::Testing", "Testing"].freeze
|
|
76
|
+
private_constant :RIGOR_TESTING_RECEIVERS
|
|
77
|
+
|
|
78
|
+
# The dump/assert helpers' own implementation methods call back into `Testing.dump_type` /
|
|
79
|
+
# `assert_type` to share the no-op runtime stub. We do NOT want those internal calls to surface
|
|
80
|
+
# diagnostics — they are reflexive plumbing, not user assertions. This filter skips diagnostics
|
|
81
|
+
# when the call site's `self_type` is the `Rigor` or `Rigor::Testing` module itself.
|
|
82
|
+
SELF_REFERENTIAL_SCOPES = ["Rigor", "Rigor::Testing"].freeze
|
|
83
|
+
private_constant :SELF_REFERENTIAL_SCOPES
|
|
84
|
+
|
|
85
|
+
def inside_rigor_testing?(scope)
|
|
86
|
+
self_type = scope.self_type
|
|
87
|
+
return false if self_type.nil?
|
|
88
|
+
return false unless self_type.respond_to?(:class_name)
|
|
89
|
+
|
|
90
|
+
SELF_REFERENTIAL_SCOPES.include?(self_type.class_name)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def rigor_testing_call?(call_node, method_name)
|
|
94
|
+
return false unless call_node.name == method_name
|
|
95
|
+
|
|
96
|
+
receiver = call_node.receiver
|
|
97
|
+
return true if receiver.nil?
|
|
98
|
+
|
|
99
|
+
name = Source::ConstantPath.qualified_name_or_nil(receiver)
|
|
100
|
+
return false if name.nil?
|
|
101
|
+
|
|
102
|
+
RIGOR_TESTING_RECEIVERS.include?(name)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def build_assert_type_diagnostic(path, call_node, expected, actual)
|
|
106
|
+
Diagnostic.from_message_loc(
|
|
107
|
+
call_node,
|
|
108
|
+
rule: RULE_ASSERT_TYPE,
|
|
109
|
+
path: path,
|
|
110
|
+
message: "assert_type mismatch: expected #{expected.inspect}, got #{actual.inspect}",
|
|
111
|
+
severity: :error
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private_class_method :inside_rigor_testing?, :rigor_testing_call?, :build_assert_type_diagnostic
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -156,13 +156,6 @@ module Rigor
|
|
|
156
156
|
# whose canonical id starts with `<family>.`. Per ADR-8 § "1".
|
|
157
157
|
RULE_FAMILIES = %w[call flow assert dump def global suppression static effect].freeze
|
|
158
158
|
|
|
159
|
-
# Families of diagnostics the engine emits OUTSIDE the CheckRules catalogue (aggregator-level and
|
|
160
|
-
# reporter-level diagnostics such as `rbs_extended.unsatisfied-conformance`,
|
|
161
|
-
# `dynamic.dependency-source.*`, `rbs.coverage.*`, `pre-eval.parse-error`), plus the `plugin.` prefix
|
|
162
|
-
# reserved for plugin-produced identifiers. `suppression.unknown-rule` treats a dotted token whose
|
|
163
|
-
# first segment appears here as KNOWN and stays silent: these ids are legitimate suppression /
|
|
164
|
-
# `severity_overrides:` vocabulary the light rule-id table cannot enumerate (plugins load dynamically;
|
|
165
|
-
# aggregator ids live in the engine-heavy runner), so under-warning is the FP-safe direction.
|
|
166
159
|
# The `pre-eval.*` ids (ADR-17 WD6) the bare family wildcard `pre-eval` expands to. Emitted by the
|
|
167
160
|
# `pre_eval:` pre-pass, outside the CheckRules catalogue, so the family cannot ride `RULE_FAMILIES`
|
|
168
161
|
# (which also drives the catalogue and the config audit over `ALL_RULES`).
|
|
@@ -170,6 +163,13 @@ module Rigor
|
|
|
170
163
|
pre-eval.parse-error pre-eval.file-not-found pre-eval.duplicate-declaration
|
|
171
164
|
].freeze
|
|
172
165
|
|
|
166
|
+
# Families of diagnostics the engine emits OUTSIDE the CheckRules catalogue (aggregator-level and
|
|
167
|
+
# reporter-level diagnostics such as `rbs_extended.unsatisfied-conformance`,
|
|
168
|
+
# `dynamic.dependency-source.*`, `rbs.coverage.*`, `pre-eval.parse-error`), plus the `plugin.` prefix
|
|
169
|
+
# reserved for plugin-produced identifiers. `suppression.unknown-rule` treats a dotted token whose
|
|
170
|
+
# first segment appears here as KNOWN and stays silent: these ids are legitimate suppression /
|
|
171
|
+
# `severity_overrides:` vocabulary the light rule-id table cannot enumerate (plugins load dynamically;
|
|
172
|
+
# aggregator ids live in the engine-heavy runner), so under-warning is the FP-safe direction.
|
|
173
173
|
NON_CHECK_DIAGNOSTIC_FAMILIES = %w[rbs_extended dynamic rbs pre-eval plugin plugin_trust].freeze
|
|
174
174
|
|
|
175
175
|
# Bare (dot-less) diagnostic ids the engine emits outside the catalogue (see the `rule:` literals in
|
|
@@ -12,9 +12,10 @@ module Rigor
|
|
|
12
12
|
# traversed once for all of them instead of once per collector (the ADR-52 WD4 model applied to the
|
|
13
13
|
# built-in rules; {Plugin::NodeRuleWalk} drives the same collectors, ADR-53 B4).
|
|
14
14
|
#
|
|
15
|
-
# The walk is a single visit-before-descend DFS over `
|
|
16
|
-
# context the hosted collectors need — the per-collector
|
|
17
|
-
# it — in one immutable {Context} object, recomputed once per node
|
|
15
|
+
# The walk is a single visit-before-descend DFS over `rigor_each_child` (the allocation-free
|
|
16
|
+
# `compact_child_nodes`). It threads the union of the context the hosted collectors need — the per-collector
|
|
17
|
+
# hand-rolled walks each tracked some subset of it — in one immutable {Context} object, recomputed once per node
|
|
18
|
+
# during the single descent:
|
|
18
19
|
#
|
|
19
20
|
# - `in_loop_or_block` — whether the node is inside a loop / block body (the two flow collectors
|
|
20
21
|
# suppress collection there because mutation tracking through those is incomplete).
|
|
@@ -17,6 +17,8 @@ module Rigor
|
|
|
17
17
|
# - **Classes with a dynamic `attr_*` accessor** — `attr_reader(*NAMES)` / `attr_accessor(:a, SOME_CONST)`
|
|
18
18
|
# synthesizes readers whose names are not statically decidable, so the class's method surface cannot be
|
|
19
19
|
# enumerated from source.
|
|
20
|
+
# - **Classes with a non-constant superclass** — `class X < DelegateClass(Array)` / `< Struct.new(...)`
|
|
21
|
+
# inherits a surface the engine cannot enumerate from a constant name.
|
|
20
22
|
#
|
|
21
23
|
# The enclosing declaration of a self-call is always in the same file as the call (even a reopened class
|
|
22
24
|
# restates `class Foo`), so a per-file AST scan suffices — no cross-file plumbing. Names are built to
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../diagnostic"
|
|
4
|
+
require_relative "receiver_predicates"
|
|
5
|
+
require_relative "self_closedness_scanner"
|
|
6
|
+
|
|
7
|
+
module Rigor
|
|
8
|
+
module Analysis
|
|
9
|
+
module CheckRules
|
|
10
|
+
# ADR-116 WD1 — `call.self-undefined-method` (ADR-24 slice 4): an implicit-self call inside a closed
|
|
11
|
+
# class body that no method of the class, its project subclasses or its mixins can answer.
|
|
12
|
+
#
|
|
13
|
+
# The one entry point is {.diagnostics}, called by `CheckRules.diagnose`. It reads {ReceiverPredicates}
|
|
14
|
+
# and {SelfClosednessScanner} and calls nothing else in `CheckRules`.
|
|
15
|
+
module SelfUndefinedMethod
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
# ADR-24 slice 4 — `call.self-undefined-method`. Consumes the engine's
|
|
19
|
+
# recorded unresolved implicit-self calls
|
|
20
|
+
# ({Analysis::SelfCallResolutionRecorder}) and adds only the
|
|
21
|
+
# closedness POLICY — it NEVER recomputes resolution (the reverted
|
|
22
|
+
# attempt-1 mistake that produced 135 FPs). A miss reaches here only
|
|
23
|
+
# because the engine's real resolution found the method nowhere.
|
|
24
|
+
#
|
|
25
|
+
# The v1 gate is deliberately the most conservative "confidently
|
|
26
|
+
# closed" shape: a STANDALONE project class — no superclass and no
|
|
27
|
+
# `include`/`prepend` (so its in-file method surface is complete) —
|
|
28
|
+
# that is not a module / mixin contract, defines no `method_missing`,
|
|
29
|
+
# has no dynamic `attr_*(*splat)` accessor, and is not an ADR-26 open
|
|
30
|
+
# receiver. Widening to superclass / include chains is a later slice,
|
|
31
|
+
# each behind the external corpus FP gate. Authored `:warning` but
|
|
32
|
+
# mapped to `:off` in every shipped profile until that gate is green
|
|
33
|
+
# (ADR-24 § "Slice 4"); a project opts in via `severity_overrides:`.
|
|
34
|
+
def diagnostics(path, self_call_misses, root, scope_index)
|
|
35
|
+
return [] if self_call_misses.empty?
|
|
36
|
+
|
|
37
|
+
open_names = SelfClosednessScanner.new(root).open_class_names
|
|
38
|
+
self_call_misses.filter_map do |miss|
|
|
39
|
+
next if open_names.include?(miss.class_name)
|
|
40
|
+
|
|
41
|
+
scope = scope_index[miss.node]
|
|
42
|
+
next if scope.nil?
|
|
43
|
+
next unless confidently_closed_self_class?(miss.class_name, scope)
|
|
44
|
+
next if method_defined_on_known_subclass?(miss.class_name, miss.method_name, scope)
|
|
45
|
+
|
|
46
|
+
build_self_undefined_method_diagnostic(path, miss)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# ADR-24 slice 4 — subclass-aware gating (the abstract / template-method
|
|
51
|
+
# base-class false positive the WD4 corpus eval surfaced). A base class
|
|
52
|
+
# legitimately calls a method its subclasses implement
|
|
53
|
+
# (`Mail::CommonField#decoded` calls `do_decode`, which
|
|
54
|
+
# `Mail::UnstructuredField < CommonField` and its siblings define; the
|
|
55
|
+
# same shape covers `Mail::Retriever#find` → POP3 / IMAP). When the
|
|
56
|
+
# missed method is discovered on ANY known subclass of the self-class,
|
|
57
|
+
# the call is a template-method hook, not a typo — suppress. Walks the
|
|
58
|
+
# project subclass closure (the `discovered_superclasses` child→parent
|
|
59
|
+
# map inverted, cycle-guarded). A pure narrowing — it only ever
|
|
60
|
+
# suppresses a firing the closed-class gate would otherwise emit.
|
|
61
|
+
def method_defined_on_known_subclass?(class_name, method_name, scope)
|
|
62
|
+
supers = scope.discovered_superclasses
|
|
63
|
+
seen = {}
|
|
64
|
+
queue = direct_subclasses(class_name, supers)
|
|
65
|
+
until queue.empty?
|
|
66
|
+
subclass = queue.shift
|
|
67
|
+
next if seen[subclass]
|
|
68
|
+
|
|
69
|
+
seen[subclass] = true
|
|
70
|
+
return true if method_known_on_class?(subclass, method_name, scope)
|
|
71
|
+
|
|
72
|
+
queue.concat(direct_subclasses(subclass, supers))
|
|
73
|
+
end
|
|
74
|
+
false
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# The directly-recorded subclasses of `class_name`. `discovered_superclasses`
|
|
78
|
+
# keys the child fully-qualified (`Mail::POP3`) but records the parent
|
|
79
|
+
# *as written* (`Retriever`), so a qualified miss class (`Mail::Retriever`)
|
|
80
|
+
# is matched by resolving the parent name in the child's namespace.
|
|
81
|
+
def direct_subclasses(class_name, discovered_superclasses)
|
|
82
|
+
discovered_superclasses.filter_map { |child, parent| child if parent_matches?(child, parent, class_name) }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Ruby constant lookup: a recorded parent `Retriever` on child
|
|
86
|
+
# `Mail::POP3` resolves to `Mail::Retriever` (walk the child's namespace
|
|
87
|
+
# prefixes, longest first), matched against the miss's fully-qualified
|
|
88
|
+
# class name. Namespace-anchored, so it cannot match a same-named base in
|
|
89
|
+
# an unrelated namespace.
|
|
90
|
+
def parent_matches?(child, parent, class_name)
|
|
91
|
+
parent_name = parent.to_s
|
|
92
|
+
# Issue #722 residue 1 — a rooted parent (`< ::Base`) names the top level, so the namespace walk
|
|
93
|
+
# below must not run for it. This peel is one of the two that predate
|
|
94
|
+
# `Scope#ancestor_name_candidates` and resolve their own pair.
|
|
95
|
+
return parent_name.delete_prefix("::") == class_name if parent_name.start_with?("::")
|
|
96
|
+
return true if parent_name == class_name
|
|
97
|
+
|
|
98
|
+
segments = child.to_s.split("::")[0...-1]
|
|
99
|
+
until segments.empty?
|
|
100
|
+
return true if "#{segments.join('::')}::#{parent_name}" == class_name
|
|
101
|
+
|
|
102
|
+
segments.pop
|
|
103
|
+
end
|
|
104
|
+
false
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Whether `method_name` is defined on `class_name` in the project — a
|
|
108
|
+
# plain `def` (the def-node table) or a dynamic definition
|
|
109
|
+
# (`define_method` / `attr_*` / `alias`). `discovered_method?` alone
|
|
110
|
+
# misses plain defs, which is exactly what the abstract hooks are.
|
|
111
|
+
def method_known_on_class?(class_name, method_name, scope)
|
|
112
|
+
!scope.user_def_for(class_name, method_name).nil? ||
|
|
113
|
+
scope.discovered_method?(class_name, method_name, :instance)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# ADR-24 slice 4 — the universal bases. A recorded self-call miss tagged
|
|
117
|
+
# with one of these means the engine fell back to the root self-type
|
|
118
|
+
# because it could NOT resolve the real class (a class-body macro context
|
|
119
|
+
# where self is the Class object, top-level `main`, `instance_eval`, an
|
|
120
|
+
# FFI / `define_method` metaprogramming surface). Their instance method
|
|
121
|
+
# set is never "project-known and complete" — every object also responds
|
|
122
|
+
# to whatever the unresolved real class adds — so a miss there is a
|
|
123
|
+
# resolution gap, not a typo. This is the dominant false-positive class
|
|
124
|
+
# the WD4 corpus eval surfaced (protobuf 73 / tdiary 199 / pycall 10 /
|
|
125
|
+
# … FFI + class-macro calls, 287 firings across the corpus); excluding
|
|
126
|
+
# it is a pure narrowing.
|
|
127
|
+
SELF_UNDEFINED_UNIVERSAL_BASES = %w[Object BasicObject Kernel].to_set.freeze
|
|
128
|
+
private_constant :SELF_UNDEFINED_UNIVERSAL_BASES
|
|
129
|
+
|
|
130
|
+
def confidently_closed_self_class?(class_name, scope)
|
|
131
|
+
return false if SELF_UNDEFINED_UNIVERSAL_BASES.include?(class_name)
|
|
132
|
+
return false if ReceiverPredicates.unbounded_receiver_surface?(class_name, scope)
|
|
133
|
+
return false if scope.discovered_method?(class_name, :method_missing, :instance)
|
|
134
|
+
# A superclass or mixin extends the surface beyond what this file
|
|
135
|
+
# declares; the engine's ancestor walk may have hit an unresolvable
|
|
136
|
+
# ancestor, so a miss is not provably a typo. Defer to a later slice.
|
|
137
|
+
return false if scope.superclass_of(class_name)
|
|
138
|
+
return false unless scope.includes_of(class_name).empty?
|
|
139
|
+
|
|
140
|
+
true
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def build_self_undefined_method_diagnostic(path, miss)
|
|
144
|
+
Diagnostic.new(
|
|
145
|
+
path: path,
|
|
146
|
+
line: miss.line || 1,
|
|
147
|
+
column: miss.column || 1,
|
|
148
|
+
message: "implicit-self call to `#{miss.method_name}` resolves to no method on " \
|
|
149
|
+
"`#{miss.class_name}` (a standalone class with a complete, project-known " \
|
|
150
|
+
"method surface). Likely a typo or a missing `def`.",
|
|
151
|
+
severity: :warning,
|
|
152
|
+
rule: RULE_SELF_UNDEFINED_METHOD,
|
|
153
|
+
source_family: :builtin,
|
|
154
|
+
receiver_type: miss.class_name,
|
|
155
|
+
method_name: miss.method_name
|
|
156
|
+
)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
private_class_method :method_defined_on_known_subclass?, :direct_subclasses, :parent_matches?,
|
|
160
|
+
:method_known_on_class?, :confidently_closed_self_class?,
|
|
161
|
+
:build_self_undefined_method_diagnostic
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|