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.
Files changed (349) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/docs/handbook/01-getting-started.md +1 -1
  4. data/docs/handbook/04-tuples-and-shapes.md +6 -1
  5. data/docs/handbook/12-lightweight-hkt.md +1 -1
  6. data/docs/handbook/appendix-typescript.md +28 -17
  7. data/docs/manual/02-cli-reference.md +10 -0
  8. data/docs/manual/03-configuration.md +1 -1
  9. data/docs/manual/04-diagnostics.md +1 -1
  10. data/docs/manual/10-mcp-server.md +122 -10
  11. data/docs/manual/plugins/rigor-activerecord.md +7 -0
  12. data/lib/rigor/analysis/check_rules/always_raises.rb +95 -0
  13. data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +32 -2
  14. data/lib/rigor/analysis/check_rules/argument_type.rb +802 -0
  15. data/lib/rigor/analysis/check_rules/call_facts.rb +2 -2
  16. data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +30 -1
  17. data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -5
  18. data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +34 -0
  19. data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +131 -4
  20. data/lib/rigor/analysis/check_rules/nil_receiver.rb +195 -0
  21. data/lib/rigor/analysis/check_rules/override_param_narrowed.rb +111 -0
  22. data/lib/rigor/analysis/check_rules/override_return_widened.rb +88 -0
  23. data/lib/rigor/analysis/check_rules/override_support.rb +246 -0
  24. data/lib/rigor/analysis/check_rules/override_visibility.rb +135 -0
  25. data/lib/rigor/analysis/check_rules/published_constant_guard.rb +75 -31
  26. data/lib/rigor/analysis/check_rules/raise_non_exception.rb +198 -0
  27. data/lib/rigor/analysis/check_rules/receiver_predicates.rb +576 -0
  28. data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +52 -4
  29. data/lib/rigor/analysis/check_rules/return_type.rb +225 -0
  30. data/lib/rigor/analysis/check_rules/rigor_testing.rb +119 -0
  31. data/lib/rigor/analysis/check_rules/rule_ids.rb +7 -7
  32. data/lib/rigor/analysis/check_rules/rule_walk.rb +4 -3
  33. data/lib/rigor/analysis/check_rules/self_closedness_scanner.rb +2 -0
  34. data/lib/rigor/analysis/check_rules/self_undefined_method.rb +165 -0
  35. data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +34 -0
  36. data/lib/rigor/analysis/check_rules/source_arity.rb +2 -2
  37. data/lib/rigor/analysis/check_rules/special_global_write.rb +256 -0
  38. data/lib/rigor/analysis/check_rules/suppression.rb +275 -0
  39. data/lib/rigor/analysis/check_rules/undefined_method.rb +882 -0
  40. data/lib/rigor/analysis/check_rules/unreachable_branch.rb +97 -0
  41. data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +42 -0
  42. data/lib/rigor/analysis/check_rules/unresolved_toplevel.rb +140 -0
  43. data/lib/rigor/analysis/check_rules/visibility_mismatch.rb +252 -0
  44. data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +27 -0
  45. data/lib/rigor/analysis/check_rules/wrong_arity.rb +303 -0
  46. data/lib/rigor/analysis/check_rules.rb +66 -4931
  47. data/lib/rigor/analysis/dependency_recorder.rb +1 -1
  48. data/lib/rigor/analysis/dependency_source_inference/builder.rb +2 -4
  49. data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -2
  50. data/lib/rigor/analysis/dependency_source_inference/walker.rb +15 -15
  51. data/lib/rigor/analysis/incremental_session.rb +4 -4
  52. data/lib/rigor/analysis/path_expansion.rb +1 -1
  53. data/lib/rigor/analysis/plugin_fact_fingerprint.rb +5 -5
  54. data/lib/rigor/analysis/reachability/graph.rb +2 -3
  55. data/lib/rigor/analysis/reachability/plugin_roots.rb +2 -2
  56. data/lib/rigor/analysis/reachability/scan.rb +2 -2
  57. data/lib/rigor/analysis/rule_catalog.rb +2 -1
  58. data/lib/rigor/analysis/run_cache_key.rb +9 -8
  59. data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
  60. data/lib/rigor/analysis/runner/dependency_rows.rb +206 -0
  61. data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +24 -22
  62. data/lib/rigor/analysis/runner/effect_cache_entries.rb +69 -0
  63. data/lib/rigor/analysis/runner/pool_coordinator.rb +6 -8
  64. data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -5
  65. data/lib/rigor/analysis/runner/scope_seed.rb +144 -0
  66. data/lib/rigor/analysis/runner.rb +49 -296
  67. data/lib/rigor/analysis/template_unit_collector.rb +1 -1
  68. data/lib/rigor/analysis/template_units.rb +10 -10
  69. data/lib/rigor/analysis/worker_session.rb +7 -7
  70. data/lib/rigor/bleeding_edge.rb +3 -2
  71. data/lib/rigor/builtins/hkt_builtins.rb +17 -17
  72. data/lib/rigor/builtins/imported_refinements.rb +8 -16
  73. data/lib/rigor/builtins/regex_refinement.rb +3 -3
  74. data/lib/rigor/builtins/static_return_refinements.rb +143 -19
  75. data/lib/rigor/cache/incremental_snapshot.rb +21 -8
  76. data/lib/rigor/cache/rbs_descriptor.rb +18 -1
  77. data/lib/rigor/cli/coverage_renderer.rb +15 -1
  78. data/lib/rigor/cli/coverage_report.rb +19 -1
  79. data/lib/rigor/cli/diagnostic_formats.rb +3 -2
  80. data/lib/rigor/cli/docs_command.rb +5 -5
  81. data/lib/rigor/cli/effects_command.rb +7 -6
  82. data/lib/rigor/cli/fused_protection_report.rb +7 -7
  83. data/lib/rigor/cli/lsp_command.rb +1 -1
  84. data/lib/rigor/cli/mcp_command.rb +5 -2
  85. data/lib/rigor/cli/options.rb +4 -0
  86. data/lib/rigor/cli/plugins_command.rb +1 -1
  87. data/lib/rigor/cli/sig_gen_command.rb +1 -1
  88. data/lib/rigor/cli/skill_command.rb +5 -4
  89. data/lib/rigor/cli/triage_renderer.rb +3 -2
  90. data/lib/rigor/cli/unused_command.rb +4 -4
  91. data/lib/rigor/cli.rb +14 -0
  92. data/lib/rigor/configuration/coercion.rb +418 -0
  93. data/lib/rigor/configuration/defaults.rb +248 -0
  94. data/lib/rigor/configuration/dependencies.rb +1 -1
  95. data/lib/rigor/configuration/loader.rb +354 -0
  96. data/lib/rigor/configuration/severity_profile.rb +4 -4
  97. data/lib/rigor/configuration.rb +51 -860
  98. data/lib/rigor/effects/attribution.rb +1 -1
  99. data/lib/rigor/effects/effect_table.rb +1 -1
  100. data/lib/rigor/effects/identity.rb +3 -3
  101. data/lib/rigor/effects/local_ownership.rb +2 -2
  102. data/lib/rigor/effects/snapshot.rb +1 -1
  103. data/lib/rigor/effects/summary.rb +5 -4
  104. data/lib/rigor/environment/member_consistency.rb +10 -0
  105. data/lib/rigor/environment/rbs_loader.rb +19 -22
  106. data/lib/rigor/environment/reflection.rb +1 -1
  107. data/lib/rigor/environment/unreadable_signature.rb +21 -0
  108. data/lib/rigor/environment.rb +8 -8
  109. data/lib/rigor/flow_contribution/merger.rb +1 -0
  110. data/lib/rigor/hashing/xxh3.rb +1 -1
  111. data/lib/rigor/inference/acceptance.rb +23 -2
  112. data/lib/rigor/inference/alias_mutation_floor/site_collector.rb +5 -0
  113. data/lib/rigor/inference/alias_mutation_floor.rb +0 -5
  114. data/lib/rigor/inference/anonymous_meta_class.rb +2 -2
  115. data/lib/rigor/inference/block_call_timing.rb +6 -0
  116. data/lib/rigor/inference/budget_trace.rb +3 -2
  117. data/lib/rigor/inference/builtins/date_catalog.rb +3 -3
  118. data/lib/rigor/inference/builtins/method_catalog.rb +3 -3
  119. data/lib/rigor/inference/builtins/time_catalog.rb +3 -3
  120. data/lib/rigor/inference/call_ladder/literal_send.rb +98 -0
  121. data/lib/rigor/inference/call_ladder/overriding_def.rb +98 -0
  122. data/lib/rigor/inference/call_ladder/project_singleton.rb +362 -0
  123. data/lib/rigor/inference/call_ladder/refined.rb +212 -0
  124. data/lib/rigor/inference/call_ladder/top_level_def.rb +222 -0
  125. data/lib/rigor/inference/call_ladder/user_method.rb +247 -0
  126. data/lib/rigor/inference/call_ladder.rb +219 -0
  127. data/lib/rigor/inference/callee_write_census.rb +2 -2
  128. data/lib/rigor/inference/captured_locals.rb +2 -2
  129. data/lib/rigor/inference/clause_widening.rb +63 -1
  130. data/lib/rigor/inference/declaration_walk/context.rb +12 -12
  131. data/lib/rigor/inference/declaration_walk/rules.rb +750 -0
  132. data/lib/rigor/inference/declaration_walk/traversal.rb +9 -8
  133. data/lib/rigor/inference/declaration_walk.rb +4 -3
  134. data/lib/rigor/inference/def_node_resolver.rb +2 -2
  135. data/lib/rigor/inference/def_return_typer.rb +14 -6
  136. data/lib/rigor/inference/deferred_mutation.rb +120 -0
  137. data/lib/rigor/inference/define_method_block_self.rb +1 -1
  138. data/lib/rigor/inference/definer_resolution.rb +4 -4
  139. data/lib/rigor/inference/error_info.rb +8 -8
  140. data/lib/rigor/inference/expression_typer/composites.rb +348 -0
  141. data/lib/rigor/inference/expression_typer/per_element_assemblers.rb +233 -0
  142. data/lib/rigor/inference/expression_typer/writes.rb +218 -0
  143. data/lib/rigor/inference/expression_typer.rb +275 -1825
  144. data/lib/rigor/inference/external_ancestor_resolution.rb +2 -2
  145. data/lib/rigor/inference/fallback.rb +1 -0
  146. data/lib/rigor/inference/for_yield_slots.rb +126 -0
  147. data/lib/rigor/inference/genuine_send.rb +92 -0
  148. data/lib/rigor/inference/global_write_census.rb +2 -2
  149. data/lib/rigor/inference/hkt_body.rb +2 -0
  150. data/lib/rigor/inference/in_effect_refinements/walk.rb +2 -2
  151. data/lib/rigor/inference/index_write_widening.rb +4 -4
  152. data/lib/rigor/inference/indexed_narrowing.rb +1 -1
  153. data/lib/rigor/inference/intervening_ivar_reset.rb +46 -9
  154. data/lib/rigor/inference/ivar_writer_census.rb +1 -1
  155. data/lib/rigor/inference/loop_store_sites.rb +239 -0
  156. data/lib/rigor/inference/macro_block_self_type.rb +4 -3
  157. data/lib/rigor/inference/method_dispatcher/block_folding.rb +3 -2
  158. data/lib/rigor/inference/method_dispatcher/call_context.rb +84 -14
  159. data/lib/rigor/inference/method_dispatcher/composite_receiver.rb +144 -0
  160. data/lib/rigor/inference/method_dispatcher/constant_folding.rb +7 -5
  161. data/lib/rigor/inference/method_dispatcher/declared_constructor.rb +1 -1
  162. data/lib/rigor/inference/method_dispatcher/dependency_source.rb +90 -0
  163. data/lib/rigor/inference/method_dispatcher/discovered_method.rb +78 -0
  164. data/lib/rigor/inference/method_dispatcher/file_folding.rb +2 -2
  165. data/lib/rigor/inference/method_dispatcher/hkt_builtin_return.rb +40 -0
  166. data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -6
  167. data/lib/rigor/inference/method_dispatcher/literal_string_folding.rb +4 -2
  168. data/lib/rigor/inference/method_dispatcher/match_data_folding.rb +1 -1
  169. data/lib/rigor/inference/method_dispatcher/meta_introspection.rb +506 -0
  170. data/lib/rigor/inference/method_dispatcher/overload_selector.rb +2 -0
  171. data/lib/rigor/inference/method_dispatcher/plugin_contribution.rb +134 -0
  172. data/lib/rigor/inference/method_dispatcher/project_patched.rb +134 -0
  173. data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +125 -43
  174. data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +3 -4
  175. data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +1 -1
  176. data/lib/rigor/inference/method_dispatcher/set_folding.rb +1 -1
  177. data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +19 -6
  178. data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +3 -3
  179. data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +7 -4
  180. data/lib/rigor/inference/method_dispatcher/static_refinement.rb +106 -0
  181. data/lib/rigor/inference/method_dispatcher/synthesized_stub.rb +41 -0
  182. data/lib/rigor/inference/method_dispatcher/synthetic_method_dispatch.rb +133 -0
  183. data/lib/rigor/inference/method_dispatcher/universal_object_dispatch.rb +2 -1
  184. data/lib/rigor/inference/method_dispatcher/user_class_fallback.rb +216 -0
  185. data/lib/rigor/inference/method_dispatcher.rb +175 -1361
  186. data/lib/rigor/inference/method_parameter_binder.rb +18 -18
  187. data/lib/rigor/inference/module_function_state.rb +5 -4
  188. data/lib/rigor/inference/mutation_widening.rb +20 -7
  189. data/lib/rigor/inference/narrowing/case_literals.rb +58 -0
  190. data/lib/rigor/inference/narrowing/class_dispatch.rb +302 -0
  191. data/lib/rigor/inference/narrowing/complements.rb +322 -0
  192. data/lib/rigor/inference/narrowing/presence_predicates.rb +205 -0
  193. data/lib/rigor/inference/narrowing/regex_match.rb +499 -0
  194. data/lib/rigor/inference/narrowing.rb +86 -1269
  195. data/lib/rigor/inference/object_mixins.rb +2 -2
  196. data/lib/rigor/inference/opaque_mutation.rb +214 -0
  197. data/lib/rigor/inference/optimistic_origin.rb +52 -14
  198. data/lib/rigor/inference/parameter_inference_collector.rb +1 -1
  199. data/lib/rigor/inference/pre_eval_constants.rb +11 -9
  200. data/lib/rigor/inference/precision_scanner.rb +27 -2
  201. data/lib/rigor/inference/project_patched_methods.rb +3 -3
  202. data/lib/rigor/inference/range_constant.rb +3 -3
  203. data/lib/rigor/inference/rbs_type_translator.rb +2 -2
  204. data/lib/rigor/inference/refine_self.rb +8 -7
  205. data/lib/rigor/inference/refined_dispatch.rb +2 -2
  206. data/lib/rigor/inference/return_barrier.rb +24 -9
  207. data/lib/rigor/inference/scope_indexer/alias_def_nodes.rb +311 -0
  208. data/lib/rigor/inference/scope_indexer/census_scope.rb +47 -0
  209. data/lib/rigor/inference/scope_indexer/certainty.rb +2 -2
  210. data/lib/rigor/inference/scope_indexer/class_cvar_census.rb +282 -0
  211. data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +12 -5
  212. data/lib/rigor/inference/scope_indexer/class_declarations.rb +228 -0
  213. data/lib/rigor/inference/scope_indexer/class_ivar_index.rb +2028 -0
  214. data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +4 -3
  215. data/lib/rigor/inference/scope_indexer/constant_tables.rb +844 -0
  216. data/lib/rigor/inference/scope_indexer/cvar_hierarchy.rb +159 -0
  217. data/lib/rigor/inference/scope_indexer/declaration_artifacts.rb +219 -0
  218. data/lib/rigor/inference/scope_indexer/declaration_signature.rb +212 -0
  219. data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +2 -2
  220. data/lib/rigor/inference/scope_indexer/factory_call_resolver.rb +53 -0
  221. data/lib/rigor/inference/scope_indexer/literal_receiver_mutations.rb +266 -0
  222. data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +8 -7
  223. data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +1 -1
  224. data/lib/rigor/inference/scope_indexer/mixin_effects.rb +470 -0
  225. data/lib/rigor/inference/scope_indexer/mixin_tables.rb +388 -0
  226. data/lib/rigor/inference/scope_indexer/mutated_carrier_widening.rb +163 -0
  227. data/lib/rigor/inference/scope_indexer/mutated_element_census.rb +211 -0
  228. data/lib/rigor/inference/scope_indexer/node_propagation.rb +520 -0
  229. data/lib/rigor/inference/scope_indexer/program_globals.rb +154 -0
  230. data/lib/rigor/inference/scope_indexer/published_constant_cvars.rb +146 -0
  231. data/lib/rigor/inference/scope_indexer/published_constant_ivars.rb +181 -0
  232. data/lib/rigor/inference/scope_indexer/shared_walk_tables.rb +823 -0
  233. data/lib/rigor/inference/scope_indexer/singleton_class_sources.rb +85 -0
  234. data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +5 -5
  235. data/lib/rigor/inference/scope_indexer.rb +2657 -9558
  236. data/lib/rigor/inference/self_call_ivar_writes.rb +22 -3
  237. data/lib/rigor/inference/set_mutation.rb +2 -2
  238. data/lib/rigor/inference/singleton_hook_definers.rb +185 -0
  239. data/lib/rigor/inference/statement_evaluator/def_arguments_and_assertions.rb +365 -0
  240. data/lib/rigor/inference/statement_evaluator/pattern_bindings.rb +581 -0
  241. data/lib/rigor/inference/statement_evaluator.rb +201 -1008
  242. data/lib/rigor/inference/synthetic_method_scanner.rb +0 -3
  243. data/lib/rigor/language_server/completion_provider.rb +8 -8
  244. data/lib/rigor/language_server/diagnostic_publisher.rb +6 -7
  245. data/lib/rigor/language_server/document_symbol_provider.rb +4 -6
  246. data/lib/rigor/language_server/folding_range_provider.rb +3 -3
  247. data/lib/rigor/language_server/hover_provider.rb +2 -2
  248. data/lib/rigor/language_server/loop.rb +2 -2
  249. data/lib/rigor/language_server/server.rb +3 -2
  250. data/lib/rigor/language_server/signature_help_provider.rb +7 -9
  251. data/lib/rigor/lens/document.rb +10 -1
  252. data/lib/rigor/lens/file_reader.rb +2 -1
  253. data/lib/rigor/mcp/loop.rb +48 -6
  254. data/lib/rigor/mcp/server.rb +248 -23
  255. data/lib/rigor/mcp/skill_catalog.rb +157 -0
  256. data/lib/rigor/plugin/base.rb +22 -4
  257. data/lib/rigor/plugin/effect_attribution.rb +1 -1
  258. data/lib/rigor/plugin/inflector.rb +2 -2
  259. data/lib/rigor/plugin/io_boundary.rb +1 -1
  260. data/lib/rigor/plugin/loader.rb +4 -4
  261. data/lib/rigor/plugin/macro/heredoc_template.rb +4 -3
  262. data/lib/rigor/plugin/optimistic_return.rb +20 -0
  263. data/lib/rigor/plugin/registry.rb +2 -2
  264. data/lib/rigor/plugin/template_unit.rb +4 -2
  265. data/lib/rigor/plugin/trust_policy.rb +2 -1
  266. data/lib/rigor/plugin.rb +1 -1
  267. data/lib/rigor/protection/mutator.rb +8 -9
  268. data/lib/rigor/rbs_extended/reporter.rb +2 -2
  269. data/lib/rigor/rbs_extended.rb +2 -2
  270. data/lib/rigor/reflection/constant_ancestors.rb +1 -1
  271. data/lib/rigor/reflection/project_method.rb +2 -2
  272. data/lib/rigor/reflection.rb +4 -4
  273. data/lib/rigor/scope/discovery_index.rb +15 -10
  274. data/lib/rigor/scope/resolution_chain.rb +29 -6
  275. data/lib/rigor/scope.rb +89 -32
  276. data/lib/rigor/sig_gen/generator.rb +5 -4
  277. data/lib/rigor/sig_gen/renderer.rb +3 -3
  278. data/lib/rigor/sig_gen/writer.rb +8 -6
  279. data/lib/rigor/source/parameter_envelope.rb +1 -1
  280. data/lib/rigor/triage/catalogue.rb +4 -4
  281. data/lib/rigor/type/combinator.rb +2 -2
  282. data/lib/rigor/type/data_instance.rb +2 -2
  283. data/lib/rigor/type/struct_instance.rb +3 -3
  284. data/lib/rigor/type_node/generic.rb +2 -1
  285. data/lib/rigor/type_of_memo.rb +2 -1
  286. data/lib/rigor/typing_state.rb +3 -2
  287. data/lib/rigor/version.rb +1 -1
  288. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/analyzer.rb +2 -2
  289. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +1 -1
  290. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +4 -4
  291. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +1 -1
  292. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_discoverer.rb +4 -3
  293. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/effects.rb +7 -5
  294. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +4 -2
  295. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/render_locals.rb +1 -1
  296. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +3 -2
  297. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +7 -7
  298. data/plugins/rigor-activejob/lib/rigor/plugin/activejob/job_discoverer.rb +1 -1
  299. data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +2 -2
  300. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +9 -8
  301. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +3 -2
  302. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +15 -7
  303. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +10 -3
  304. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/structure_sql_parser.rb +12 -1
  305. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +20 -5
  306. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +1 -1
  307. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +3 -2
  308. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext/effects.rb +1 -1
  309. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +8 -7
  310. data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema.rb +1 -1
  311. data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +1 -1
  312. data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +6 -7
  313. data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +3 -2
  314. data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +4 -3
  315. data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +4 -2
  316. data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +1 -1
  317. data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +1 -1
  318. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +5 -3
  319. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +1 -1
  320. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +4 -5
  321. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/doorkeeper_routes.rb +2 -2
  322. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +5 -4
  323. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_table.rb +3 -2
  324. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +30 -31
  325. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +13 -15
  326. data/plugins/rigor-rbnacl/lib/rigor/plugin/rbnacl.rb +1 -1
  327. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +4 -3
  328. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +16 -13
  329. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/scope_walker.rb +3 -2
  330. data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -6
  331. data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq/analyzer.rb +3 -3
  332. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +2 -2
  333. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +3 -2
  334. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog_walker.rb +6 -5
  335. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
  336. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +4 -5
  337. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/type_translator.rb +1 -1
  338. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +3 -4
  339. data/sig/rigor/analysis/check_rules/suppression.rbs +9 -0
  340. data/sig/rigor/analysis/dependency_recorder.rbs +9 -0
  341. data/sig/rigor/inference.rbs +275 -11
  342. data/sig/rigor/plugin/base.rbs +14 -5
  343. data/sig/rigor/plugin/optimistic_return.rbs +16 -0
  344. data/sig/rigor/scope.rbs +7 -1
  345. data/sig/rigor/source.rbs +4 -0
  346. data/skills/rigor-mcp-setup/SKILL.md +20 -6
  347. data/skills/rigor-plugin-review/SKILL.md +3 -3
  348. data/skills/rigor-type-oracle/references/01-oracle-commands.md +1 -1
  349. metadata +90 -3
@@ -12,13 +12,13 @@ module Rigor
12
12
  module SigGen
13
13
  # Output formatter for `rigor sig-gen`.
14
14
  #
15
- # Supports three modes:
15
+ # Three outputs: two text `mode:`s and the JSON `format:`.
16
16
  # - `:print` (default) — RBS skeletons grouped by source file and class declaration, ready for the user to
17
17
  # paste into `sig/<path>.rbs`.
18
18
  # - `:diff` — a unified-style diff comparing the existing RBS spelling (if any) against the inferred
19
19
  # spelling, as a minimal "- declared / + inferred" block.
20
- # - `:json` — machine-readable payload with the same classification table as `:print`, plus every `skipped`
21
- # row with its `skip_reason` (#778).
20
+ # - `format: "json"` (`mode:` is ignored) — machine-readable payload with the same classification table as
21
+ # `:print`, plus every `skipped` row with its `skip_reason` (#778).
22
22
  class Renderer
23
23
  def initialize(out:)
24
24
  @out = out
@@ -15,9 +15,11 @@ module Rigor
15
15
  # signature tree.
16
16
  #
17
17
  # ADR-14 slice 2: the writer parses the target with `RBS::Parser` to find the matching class declaration and
18
- # inserts new method declarations just before the class's closing `end` keyword. Existing declarations are
19
- # NEVER touched unless `--overwrite` is set and the candidate is eligible for replacement (see
20
- # {#eligible_for_replacement?}).
18
+ # inserts new method declarations just before the class's closing `end` keyword. An existing member is
19
+ # NEVER replaced unless `--overwrite` is set and the candidate is eligible for replacement (see
20
+ # {#eligible_for_replacement?}). Two structural edits do not need it: a bare generic class header gets its type
21
+ # parameters ({#repair_generic_headers}), and a declaration this run touched moves under its parent's
22
+ # ({#collapse_nested_declarations}).
21
23
  #
22
24
  # The slice does NOT re-render the whole file through `RBS::Writer`. That would lose comments / blank-line
23
25
  # formatting per upstream design; the byte-range insertion approach taken here preserves untouched
@@ -855,9 +857,9 @@ module Rigor
855
857
  end
856
858
  end
857
859
 
858
- # Inserts each new method line one column before the class declaration's `end` keyword. The insertion
859
- # text carries its own leading indent + trailing newline so the surrounding source's whitespace stays
860
- # intact.
860
+ # Inserts each new method line just before the class declaration's closing `end`, one indent level
861
+ # deeper than the declaration's keyword. The insertion text carries its own leading indent + trailing
862
+ # newline so the surrounding source's whitespace stays intact.
861
863
  def insert_into_class(source, decl, new_methods)
862
864
  return source if new_methods.empty?
863
865
 
@@ -16,7 +16,7 @@ module Rigor
16
16
  # bundle through `Marshal`: `max` is nil when a rest or `...` parameter leaves it unbounded, and
17
17
  # `required_keywords` is true when the def takes a required keyword — a call that passes positionals
18
18
  # only then fails on the missing keyword whatever its count, which is a different diagnostic than the
19
- # one this envelope backs, so the rule declines on it the way `compute_arity_envelope` declines an RBS
19
+ # one this envelope backs, so the rule declines on it the way `WrongArity.compute_arity_envelope` declines an RBS
20
20
  # function with required keywords.
21
21
  #
22
22
  # {OPAQUE} is the value every other contribution to a name records — `define_method`, `attr_*`, an alias,
@@ -4,11 +4,11 @@ require_relative "hint"
4
4
 
5
5
  module Rigor
6
6
  module Triage
7
- # ADR-23 § "Heuristic catalogue" — the six v1 recognisers.
7
+ # ADR-23 § "Heuristic catalogue" — the recognisers: H1–H7, plus H2K (the engine-proven variant of H2).
8
8
  #
9
- # {.recognise} runs them in order over the diagnostic stream. Each recogniser sees only the diagnostics not yet
10
- # claimed by an earlier one, so a `5.minutes` diagnostic counted by H1 (ActiveSupport) is not re-counted by H2
11
- # (monkey-patch).
9
+ # {.recognise} runs them in {.recognisers} order over the diagnostic stream. Each recogniser sees only the
10
+ # diagnostics not yet claimed by an earlier one, so a `5.minutes` diagnostic counted by H1 (ActiveSupport) is not
11
+ # re-counted by H2 (monkey-patch).
12
12
  #
13
13
  # WD3 / slice 4: recognisers key on the structured `qualified_rule` first; where they additionally need the receiver
14
14
  # type or method name they read the structured `Diagnostic#receiver_type` / `#method_name` fields, falling back to
@@ -284,7 +284,7 @@ module Rigor
284
284
  # Recognises the carriers that participate in literal-string flow tracking: any `Constant<String>`
285
285
  # (constants are literal by construction), the `literal-string` Refined carrier, an `Intersection`
286
286
  # containing `literal-string`, or a `Union` whose every member qualifies. Used by
287
- # `ExpressionTyper#type_of_interpolated_string` and the `LiteralStringFolding` dispatcher tier so
287
+ # `ExpressionTyper::Composites.type_of_interpolated_string` and the `LiteralStringFolding` dispatcher tier so
288
288
  # propagation through interpolation and `+`/`*` composition stays consistent.
289
289
  def literal_string_compatible?(type)
290
290
  case type
@@ -850,7 +850,7 @@ module Rigor
850
850
  # that holds a type ({TYPE_CHILDREN}). Members equal after {erase_facets} merge into the erased form, at the
851
851
  # first one's position; a member no other matches keeps its facet, and {absorb_contained_members} compares
852
852
  # the erased forms too. The facet scan runs on every join and allocates nothing (no enumerator, no array),
853
- # so the merge costs only where a facet is present, which is nowhere until ADR-130 slice 1b.
853
+ # so the merge costs only where a facet is present.
854
854
  def merge_erased_members(members)
855
855
  return members if members.size < 2
856
856
  return members unless members.any? { |member| facet_bearing?(member) }
@@ -13,8 +13,8 @@ module Rigor
13
13
  # its class nominal rather than an RBS record.
14
14
  #
15
15
  # `Data` instances are frozen, so the member map is sound for the instance's whole lifetime — the
16
- # reason `Data` is the first target (a `Struct` instance can be mutated through a setter or `[]=`,
17
- # which would invalidate the map; that follow-up is deferred — see ADR-48).
16
+ # reason `Data` was the first target (a `Struct` instance can be mutated through a setter or `[]=`,
17
+ # which would invalidate the map; {StructInstance} is the mutable sibling — see ADR-48).
18
18
  #
19
19
  # Member reads fold to the member's type (`Point.new(1, 2).x` -> `Constant[1]`); `[]`, `to_h`,
20
20
  # `deconstruct`, `deconstruct_keys`, `members`, and `with` project precisely. Methods this carrier
@@ -14,9 +14,9 @@ module Rigor
14
14
  # Unlike {DataInstance}, a `Struct` instance is **mutable** — `s.x = v`, `s[:x] = v`, and escape can
15
15
  # invalidate the member map. The folding tier therefore only projects member reads off a **fresh**
16
16
  # instance (the transient receiver of a `.new(...).x` / `.with(...).x` chain, which provably cannot
17
- # have been mutated between materialisation and the read); a read off a *stored* binding degrades to
18
- # `Dynamic[top]` rather than fold a possibly-stale member value. Promoting the fold to mutation-free
19
- # bound locals is the deferred slice 3 (see ADR).
17
+ # have been mutated between materialisation and the read) or a mutation-free bound local
18
+ # (`Inference::StructFoldSafety`, ADR-48 slice 3); a read off any other stored binding degrades to
19
+ # `Dynamic[top]` rather than fold a possibly-stale member value.
20
20
  #
21
21
  # That mutability-gating lives in the dispatch tier (`StructFolding`), not the carrier: the carrier
22
22
  # itself just records the member map. Like {DataInstance}, non-folded methods project to the
@@ -44,7 +44,8 @@ module Rigor
44
44
  # ADR-13 slice 3 expanded the accepted set to include {IntegerLiteral} so the parser can emit a
45
45
  # uniform AST for `int<5, 10>` (angle bounds) and `int_mask[1, 2, 4]` (square-bracketed bitflag
46
46
  # union). The follow-up further admits {SymbolLiteral} / {StringLiteral} / {IndexedAccess} /
47
- # {Union} so `Pick[T, :a | "b"]` carries through to the resolver as a uniform AST. Every addition
47
+ # {Union} so `Pick[T, :a | "b"]` carries through to the resolver as a uniform AST, and {RangeLiteral}
48
+ # for `Integer[1..10]` (ADR-109). Every addition
48
49
  # stays additive — every earlier-shape Generic remains valid.
49
50
  def valid_arg?(arg)
50
51
  arg.is_a?(Identifier) || arg.is_a?(Generic) || arg.is_a?(IntegerLiteral) ||
@@ -10,7 +10,8 @@ require_relative "type_of_memo/serving"
10
10
  module Rigor
11
11
  # ADR-129 stage 3 — the `ExpressionTyper#type_of` result memo in **shadow** form (WD5's G1, stage-3 form). It keys a
12
12
  # computation on `(scope identity, node identity, state id)` (WD2), opens a journal capture around it, and stores
13
- # what an unrefused computation read and wrote (WD3). It never serves anything: on a would-be hit, an entry whose read
13
+ # what an unrefused computation read and wrote (WD3). It never serves anything (bar {enable!}'s `serve:` form for
14
+ # specs and audit tools, see {Serving}): on a would-be hit, an entry whose read
14
15
  # slice still holds, production computes as usual inside a priors window, and G1 checks afterwards that
15
16
  # - the type equals the entry's;
16
17
  # - the live tables equal their pre-computation state with the entry's write slice replayed;
@@ -33,8 +33,9 @@ module Rigor
33
33
  # evaluator, so a slot read is an ivar and an array index. Each slot constant is the slot's integer index, which
34
34
  # keeps the declaration Ractor-shareable and the read an `Array#[]`.
35
35
  #
36
- # Stage 1 (ADR-129 WD6) adds no caching: no capture is opened outside the specs, so the journal stays empty and
37
- # every touch is a size check.
36
+ # Nothing is served from a capture (ADR-129 WD6): the only captures outside the specs are the opt-in shadow
37
+ # memo's ({TypeOfMemo}, `RIGOR_TYPE_OF_SHADOW`), so with it off the journal stays empty and every touch is a size
38
+ # check.
38
39
  module TypingState
39
40
  KINDS = %i[frame table resource memo].freeze
40
41
  READ_EXEMPTIONS = %i[id_determined delta_internal].freeze
data/lib/rigor/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rigor
4
- VERSION = "0.4.8"
4
+ VERSION = "0.4.9"
5
5
  end
@@ -14,8 +14,8 @@ module Rigor
14
14
  # - `<ChannelClass>.broadcast_to(record, data)` — class-targeted broadcast. The class must exist
15
15
  # in the index.
16
16
  # - `ActionCable.server.broadcast(stream_name, data)` — string-targeted broadcast. When
17
- # `stream_name` is a literal string and the index has at least one channel with no dynamic
18
- # stream registrations, we check that the name appears in `index.all_stream_names`. Otherwise
17
+ # `stream_name` is a literal string and no discovered channel has a dynamic
18
+ # stream registration, we check that the name appears in `index.all_stream_names`. Otherwise
19
19
  # the `unknown-stream` warning is suppressed (we can't prove absence).
20
20
  module Analyzer
21
21
  # `ActionCable.server.broadcast(...)` — the receiver path we recognise as a server-targeted
@@ -15,7 +15,7 @@ module Rigor
15
15
  #
16
16
  # For each discovered channel, the discoverer:
17
17
  #
18
- # - Records every public instance-side `def` whose name isn't an ActionCable framework hook
18
+ # - Records every instance-side `def` directly in the class body whose name isn't an ActionCable framework hook
19
19
  # (`subscribed`, `unsubscribed`, `_`-prefixed). These are the action methods clients can invoke
20
20
  # via `subscription.perform("action_name", data)`.
21
21
  # - Records every literal-string `stream_from "name"` call as a registered stream name.
@@ -23,13 +23,13 @@ module Rigor
23
23
  # IoBoundary's cache descriptor (so the cache invalidates when the template changes); missing
24
24
  # templates are recorded so the plugin can surface a diagnostic on the action's `def`.
25
25
  #
26
- # Limitations (intentional for v0.1.0):
26
+ # Limitations (intentional):
27
27
  #
28
28
  # - Direct-superclass match only. `class CustomerMailer < BaseMailer` where `BaseMailer <
29
29
  # ApplicationMailer` is NOT discovered. Add `BaseMailer` to `mailer_base_classes` if needed.
30
30
  # - Action methods are read from the syntactic instance-side `def` list. Methods built via
31
- # `define_method`, `private`, or non-action helpers (e.g. methods starting with `_`) are out of
32
- # scope. The discoverer filters obvious non-actions (`initialize`, names prefixed with `_`).
31
+ # `define_method` are out of scope. The discoverer filters non-actions (`initialize`, names
32
+ # prefixed with `_`, and methods that are not public — see {#collect_action_defs}).
33
33
  class MailerDiscoverer
34
34
  DEFAULT_VIEWS_ROOT = "app/views"
35
35
  VIEW_FORMATS = %w[html text].freeze
@@ -212,7 +212,7 @@ module Rigor
212
212
  # - methods starting with `_` (Ruby convention for private/internal)
213
213
  # - `def self.<name>` (singleton-side)
214
214
  # - methods that are not public at the end of the class body, read in source order: after a bare
215
- # `private` / `protected` (until a `public` switches back), named by `private :foo` /
215
+ # `private` / `protected` / `module_function` (until a `public` switches back), named by `private :foo` /
216
216
  # `protected :foo`, or defined inline (`private def foo`) — Rails builds `action_methods` from the
217
217
  # public instance methods. `public :foo` after a `protected` section makes `foo` an action again.
218
218
  # Methods named by a callback or `helper_method` macro (see {#collect_callback_names}) stay actions:
@@ -33,7 +33,7 @@ module Rigor
33
33
  # `app/views/<mailer_underscore>/<action>.{html,text}.{erb,haml,slim}` must exist. Missing
34
34
  # actions get a `missing-view` diagnostic anchored on the action's `def`.
35
35
  #
36
- # ## Limitations (v0.1.0)
36
+ # ## Limitations
37
37
  #
38
38
  # - Direct-superclass match only.
39
39
  # - Action methods are read from the syntactic instance-side `def` list. `define_method` actions are
@@ -9,9 +9,10 @@ require_relative "controller_index"
9
9
  module Rigor
10
10
  module Plugin
11
11
  class Actionpack < Rigor::Plugin::Base
12
- # Walks `controller_search_paths` building a {ControllerIndex} of `(class_name, methods,
13
- # parent_class_name)` triples. Used by Phase 2 (filter chains) to validate that `before_action
14
- # :name` references a method defined on the controller or its ancestor chain.
12
+ # Walks `controller_search_paths` building a {ControllerIndex} of entries (class name, defined
13
+ # methods, parent class name, included modules, enclosing namespace). Used by Phase 2 (filter
14
+ # chains) to validate that `before_action :name` references a method defined on the controller or
15
+ # its ancestor chain.
15
16
  #
16
17
  # Two declaration shapes are recognised and qualified the same way:
17
18
  #
@@ -18,9 +18,10 @@ module Rigor
18
18
  # `mutate.self` plus the framework meaning — and an envelope forbidding `io` in a service object is
19
19
  # not violated by a helper that happens to call `render_to_string`.
20
20
  #
21
- # `render` additionally keeps a **taint**: the template is not an effect unit yet (ADR-103 WD11 /
22
- # issue #392), so what the view does is genuinely unknown and the summary says so rather than
23
- # pretending the action stops at the `render` line.
21
+ # `render` additionally keeps a **taint**: a template is an effect unit (ADR-103 WD11 / issue #392)
22
+ # reached through the `rails_render` callee edge, but a render whose target the rule cannot resolve
23
+ # leaves what the view does genuinely unknown, and the summary says so rather than pretending the
24
+ # action stops at the `render` line.
24
25
  #
25
26
  # ## The self-path rows
26
27
  #
@@ -46,8 +47,9 @@ module Rigor
46
47
  RESPONSE_WRITERS = %w[redirect_to redirect_back redirect_back_or_to head].freeze
47
48
 
48
49
  # The render family. Same labels, plus the `template-not-analysed` taint: what the controller does
49
- # is fully stated, and what the TEMPLATE does is unknown until views are effect units (ADR-103
50
- # WD11 / issue #392). A summary that stopped at the `render` line and read exhaustive would be
50
+ # is fully stated, and what the TEMPLATE does arrives through the callee edge only when the rule
51
+ # resolves the target (ADR-103 WD11 / issue #392); otherwise it is unknown. A summary that stopped
52
+ # at the `render` line and read exhaustive would be
51
53
  # the one genuinely misleading row in the whole Rails layer.
52
54
  RENDERERS = %w[render render_to_string render_to_body].freeze
53
55
 
@@ -162,8 +162,10 @@ module Rigor
162
162
  end
163
163
  end
164
164
 
165
- # Rewrites every block-opening output tag into a statement tag; see {BLOCK_EXPR}. Line- and
166
- # width-preserving by construction: only the tag's `=` characters are replaced, by spaces.
165
+ # The template pre-pass: blanks the trim markers ({TRIM_OPEN}), rewrites the `yield` keyword
166
+ # ({YIELD_METHOD}) and turns every block-opening output tag into a statement tag ({BLOCK_EXPR}).
167
+ # Line-preserving by construction; the trim and block rewrites are also width-preserving (only
168
+ # `-` / `=` characters are replaced, by spaces), the `yield` rewrite is not.
167
169
  def normalize(text)
168
170
  normalize_block_expressions(normalize_yields(text.gsub(TRIM_OPEN, "<% ").gsub(TRIM_CLOSE, " %>")))
169
171
  end
@@ -262,7 +262,7 @@ module Rigor
262
262
  # The view-side reading of a render target, which differs from the controller's in exactly one
263
263
  # place: a bare positional name is a PARTIAL here. `template:` is the escape hatch an author uses
264
264
  # when they mean otherwise, and `layout:` in a view names a partial too — the same reading
265
- # {Effects::CalleeRule.rails_render_partial} takes, for the same reason.
265
+ # {Rigor::Effects::CalleeRule.rails_render_partial} takes, for the same reason.
266
266
  def template_target(call, directory)
267
267
  explicit = string_option(call, "template")
268
268
  return qualify(explicit, directory) if explicit
@@ -149,8 +149,9 @@ module Rigor
149
149
  end
150
150
  end
151
151
 
152
- # `before_action :set_user, only: %i[show edit]` → `[[:set_user, [:show, :edit], nil]]`.
153
- # `except:` rides the third slot. `prepend_before_action` is the same chain; `after_action` and
152
+ # `before_action :set_user, only: %i[show edit]` → `[[:set_user, [:show, :edit], nil, false]]`.
153
+ # `except:` rides the third slot and the presence of `if:` / `unless:` the fourth.
154
+ # `prepend_before_action` is the same chain; `after_action` and
154
155
  # `around_action` are not — an assign made after the render cannot be a seed.
155
156
  def filter_chain(node)
156
157
  body = node.body
@@ -22,7 +22,8 @@ module Rigor
22
22
  #
23
23
  # Tier 2 of the [Rails plugins roadmap](../../../../../docs/design/20260508-rails-plugins-roadmap.md).
24
24
  # Phase 1 (strong-parameters → AR column validation), Phase 2 (filter chains), and Phase 3 (render
25
- # targets) ship as separate slices; each phase composes additively under the same plugin id.
25
+ # targets) are separate rules over the same walk; each phase composes additively under the same plugin
26
+ # id.
26
27
  #
27
28
  # ## Configuration
28
29
  #
@@ -47,9 +48,8 @@ module Rigor
47
48
  # - Implicit-self calls only. `Rails.application.routes.url_helpers.users_path` and other
48
49
  # explicit-receiver shapes are passed through; they're rare in controller code and the helper
49
50
  # table doesn't include any extra context to validate them.
50
- # - Files outside `controller_search_paths` are skipped. The plugin doesn't try to detect "is this
51
- # a controller?" by class hierarchy — Phase 1's strong-parameters work needs that, so it lives
52
- # there. Phase 4's job is the single-purpose helper check.
51
+ # - Files outside `controller_search_paths` are skipped by every phase's rule. The plugin doesn't try
52
+ # to detect "is this a controller?" by class hierarchy.
53
53
  # - When `rigor-rails-routes` is not installed (or its helper table is empty), Phase 4 silently
54
54
  # degrades to a no-op. No load-error diagnostic is emitted; the user gets the "no checks
55
55
  # happened" failure mode rather than a wall of "is this configured right?" warnings.
@@ -268,11 +268,11 @@ module Rigor
268
268
  ]
269
269
  end
270
270
 
271
- # The compile the {RenderLocals} cache could not answer — an editor's in-flight bytes, or a template
272
- # the index never globbed. Same four values the cache carries.
273
271
  # The one handler this plugin compiles; every other claimed template is declined for its name.
274
272
  ERB_SUFFIX = ".erb"
275
273
 
274
+ # The compile the {RenderLocals} cache could not answer — an editor's in-flight bytes, or a template
275
+ # the index never globbed. Same four values the cache carries.
276
276
  def compile_now(text)
277
277
  compiled, line_map, transform = ErbCompiler.compile(text)
278
278
  [compiled, line_map, transform, Prism.parse(compiled).errors.empty?]
@@ -540,7 +540,7 @@ module Rigor
540
540
  # and still carries the chain — `params[:user][:name]` types `Parameters?` and
541
541
  # `params[:user].permit(:name)` types `Parameters`, because the dispatcher strips the nil arm
542
542
  # for the receiver gate. Idiomatic *chained* reads stay silent too: `call.possible-nil-receiver`
543
- # restricts itself to `Prism::LocalVariableReadNode` receivers (`CheckRules#nil_receiver_diagnostic`), so
543
+ # restricts itself to `Prism::LocalVariableReadNode` receivers (`CheckRules::NilReceiver.diagnostic`), so
544
544
  # `params[:q].strip` cannot fire. What it does fire on is the assigned form — `q = params[:q];
545
545
  # q.strip` — at **error** severity, once per unguarded use. Guarded forms (`return if q.nil?`,
546
546
  # `if q`, `q&.strip`, `|| ""`) all narrow correctly and stay silent, so this is not a broken
@@ -14,7 +14,7 @@ module Rigor
14
14
  # For each discovered class, the discoverer also reads the `#perform` method's parameter list and
15
15
  # computes the arity envelope.
16
16
  #
17
- # Limitations (intentional for v0.1.0):
17
+ # Limitations (intentional):
18
18
  #
19
19
  # - Only direct-superclass matches. `class WelcomeJob < BaseJob` where `BaseJob < ApplicationJob`
20
20
  # is NOT discovered. List `BaseJob` in `job_base_classes` if needed.
@@ -26,14 +26,14 @@ module Rigor
26
26
  # job_base_classes: ["ApplicationJob", "ActiveJob::Base"] # default; optional
27
27
  # recurring_paths: ["config/recurring.yml"] # default; optional
28
28
  #
29
- # ## Limitations (v0.1.0)
29
+ # ## Limitations
30
30
  #
31
31
  # - Direct-superclass match only. `class WelcomeJob < BaseJob` where `BaseJob < ApplicationJob` is
32
32
  # NOT discovered. Add `BaseJob` to `job_base_classes` if needed.
33
33
  # - The `#perform` arity is read from the syntactic parameter list. Methods built via
34
34
  # `define_method` are out of scope.
35
35
  # - Required keyword arguments are recognised but not validated at the call site (positional arity
36
- # only for v0.1.0).
36
+ # only).
37
37
  class Activejob < Rigor::Plugin::Base
38
38
  manifest(
39
39
  id: "activejob",
@@ -33,7 +33,7 @@ module Rigor
33
33
  # anchors with the plain constant rendering (#583: the rooted `"::User"` key used to make all three
34
34
  # Hash consumers miss such models silently).
35
35
  #
36
- # Limitations (intentional for v0.1.0 of the plugin):
36
+ # Limitations (intentional):
37
37
  #
38
38
  # - `self.table_name = "..."` recognised only when the RHS is a String literal. Computed names
39
39
  # (`self.table_name = "#{tenant}_users"`) are skipped.
@@ -77,13 +77,13 @@ module Rigor
77
77
  # `ApplicationRecord`) setting `self.table_name_prefix` for every model under it — both already
78
78
  # guess wrong identically on unpatched code.
79
79
  class ModelDiscoverer
80
- # @param search_paths — absolute or project-relative paths.
81
- # @param base_classes — superclass names that identify a class as an AR model.
82
80
  # Declaration macros whose column's runtime value is a rich object, not the SQL scalar. Their column
83
81
  # must NOT be narrowed to the schema type (see {ModelIndex.build}'s type-override remap).
84
82
  TYPE_OVERRIDE_METHODS = %i[serialize mount_uploader mount_uploaders].freeze
85
83
  OUTSIDE_SEARCH_DIRECTORIES = %w[lib config engines].freeze
86
84
 
85
+ # @param search_paths — absolute or project-relative paths.
86
+ # @param base_classes — superclass names that identify a class as an AR model.
87
87
  def initialize(io_boundary:, search_paths:, base_classes:, project_root: ".")
88
88
  @io_boundary = io_boundary
89
89
  @search_paths = search_paths
@@ -687,7 +687,8 @@ module Rigor
687
687
  # - The final bare-name fall-back attributes BY SPELLING. A nearer constant declared outside
688
688
  # `model_search_paths` — `Account::Suspensions` in `lib/`, say, while the concern roots hold a
689
689
  # top-level `Suspensions` — is invisible to this walker, so the wrong one can win. Reading
690
- # further than the model roots needs its own cache descriptor (see {#discover}'s `watch:` note),
690
+ # further than the model roots needs its own cache descriptor (see the `producer :model_index`
691
+ # `watch:` block),
691
692
  # so the spelling is trusted instead.
692
693
  def resolve_concern_name(raw, from_name)
693
694
  name = strip_root(raw)
@@ -1529,8 +1530,8 @@ module Rigor
1529
1530
  end
1530
1531
 
1531
1532
  # `validates :name, presence: true, length: { maximum: 100 }`. Records the attribute name (the
1532
- # validator option set is ignored — the value here is the diagnostic `validates :unknown_attr`
1533
- # surfacing when the attribute isn't a column on the table).
1533
+ # validator option set is ignored). The names ride on the published `:model_index` fact as
1534
+ # `validations:`; this plugin's own {Analyzer} does not read them.
1534
1535
  def lookup_validations(body)
1535
1536
  return [] if body.nil?
1536
1537
 
@@ -1546,8 +1547,8 @@ module Rigor
1546
1547
  end
1547
1548
 
1548
1549
  # `before_save :foo`, `after_create :bar`, etc. Records the referenced method name (a Symbol
1549
- # literal). The diagnostic value is "did you forget to `def` this?". Block callbacks
1550
- # (`before_save { ... }`) decline.
1550
+ # literal), published as `callbacks:` on the `:model_index` fact for consumers that check the named
1551
+ # method exists. Block callbacks (`before_save { ... }`) decline.
1551
1552
  CALLBACK_METHODS = %i[
1552
1553
  before_validation after_validation
1553
1554
  before_save after_save around_save
@@ -29,7 +29,8 @@ module Rigor
29
29
  # {Entry} resolves its table from the root model and inherits the chain's declared associations /
30
30
  # enums / aliases / scopes / validations / callbacks / macro methods.
31
31
  class ModelIndex
32
- # `associations` is a frozen list of rows `{ name:, kind:, target:, nullable: }`:
32
+ # `associations` is a frozen list of rows `{ name:, kind:, target:, nullable:, ... }` (the further
33
+ # keys — `polymorphic`, `macro`, `class_name_option`, `through`, ... — feed {AssociationRoots}):
33
34
  #
34
35
  # - `name` — the association method name as the user invokes it (`"posts"`).
35
36
  # - `kind` — `:singular` (`belongs_to` / `has_one`) or `:collection` (`has_many`).
@@ -181,7 +182,7 @@ module Rigor
181
182
  next column unless overrides.include?(column.name)
182
183
 
183
184
  SchemaTable::Column.new(
184
- name: column.name, type: column.type, ruby_type: "Object", array: column.array
185
+ name: column.name, type: column.type, ruby_type: "Object", array: column.array, not_null: column.not_null
185
186
  )
186
187
  end
187
188
  end
@@ -107,7 +107,7 @@ module Rigor
107
107
  # it cannot read leaves `id` untyped as well.
108
108
  def implicit_id_column(call_node)
109
109
  unless single_primary_key?(call_node)
110
- return SchemaTable::Column.new(name: "id", type: UNKNOWN_PRIMARY_KEY_TYPE, ruby_type: "Object")
110
+ return SchemaTable::Column.new(name: "id", type: UNKNOWN_PRIMARY_KEY_TYPE, ruby_type: "Object", not_null: true)
111
111
  end
112
112
 
113
113
  SchemaTable::Column.new(name: "id", **primary_key_shape(call_node))
@@ -145,11 +145,11 @@ module Rigor
145
145
  options = id.is_a?(Prism::HashNode) ? id.elements : []
146
146
  array = keyword_in(options, :array).is_a?(Prism::TrueNode)
147
147
  unless primary_key_type_stated?(call_node, options)
148
- return { type: UNKNOWN_PRIMARY_KEY_TYPE, ruby_type: "Object", array: array }
148
+ return { type: UNKNOWN_PRIMARY_KEY_TYPE, ruby_type: "Object", array: array, not_null: true }
149
149
  end
150
150
 
151
151
  type = primary_key_type(id, options)
152
- { type: type, ruby_type: primary_key_ruby_type(type), array: array }
152
+ { type: type, ruby_type: primary_key_ruby_type(type), array: array, not_null: true }
153
153
  end
154
154
 
155
155
  # `id: :string` or `id: { type: :string, ... }`. `id: true` asks for the default key, as does an
@@ -266,7 +266,8 @@ module Rigor
266
266
  name: name,
267
267
  type: type,
268
268
  ruby_type: column_ruby_type(type, call_node),
269
- array: keyword_true?(call_node, :array)
269
+ array: keyword_true?(call_node, :array),
270
+ not_null: null_false?(call_node)
270
271
  )
271
272
  end
272
273
 
@@ -278,10 +279,11 @@ module Rigor
278
279
  return nil if name.nil?
279
280
 
280
281
  columns = [
281
- SchemaTable::Column.new(name: "#{name}_id", type: :integer, ruby_type: "Integer")
282
+ SchemaTable::Column.new(name: "#{name}_id", type: :integer, ruby_type: "Integer", not_null: null_false?(call_node))
282
283
  ]
283
284
  if references_polymorphic?(call_node)
284
- columns << SchemaTable::Column.new(name: "#{name}_type", type: :string, ruby_type: "String")
285
+ columns << SchemaTable::Column.new(name: "#{name}_type", type: :string, ruby_type: "String",
286
+ not_null: null_false?(call_node))
285
287
  end
286
288
  columns
287
289
  end
@@ -297,6 +299,11 @@ module Rigor
297
299
  keyword_value(call_node, name).is_a?(Prism::TrueNode)
298
300
  end
299
301
 
302
+ # `null: false` — the one spelling that proves a column non-nullable (#3322).
303
+ def null_false?(call_node)
304
+ keyword_value(call_node, :null).is_a?(Prism::FalseNode)
305
+ end
306
+
300
307
  # `t.column "name", "type"` / `t.column "name", :type` — the explicit generic column form. The
301
308
  # type lives in the second argument; an absent type degrades to `:string`.
302
309
  def parse_generic_column(call_node)
@@ -309,7 +316,8 @@ module Rigor
309
316
  name: name,
310
317
  type: type_sym,
311
318
  ruby_type: column_ruby_type(type_sym, call_node),
312
- array: keyword_true?(call_node, :array)
319
+ array: keyword_true?(call_node, :array),
320
+ not_null: null_false?(call_node)
313
321
  )
314
322
  end
315
323
 
@@ -14,12 +14,19 @@ module Rigor
14
14
  # reads `Object` here. Exotic types (json, jsonb, ltree, hstore, custom) fall back to `Object` so the
15
15
  # plugin stays silent rather than guessing.
16
16
  class SchemaTable
17
- Column = Struct.new(:name, :type, :ruby_type, :array, keyword_init: true) do
18
- def to_h = { name: name, type: type, ruby_type: ruby_type, array: array }
17
+ # `not_null` is true only where the schema proves the column cannot hold `NULL` — `null: false`, a primary
18
+ # key, or `NOT NULL` / `PRIMARY KEY` in `structure.sql`. Anything else, unknown included, is nullable, and
19
+ # its reader is answered optimistically nil-free (#3322).
20
+ Column = Struct.new(:name, :type, :ruby_type, :array, :not_null, keyword_init: true) do
21
+ def to_h = { name: name, type: type, ruby_type: ruby_type, array: array, not_null: not_null }
19
22
 
20
23
  def array?
21
24
  array == true
22
25
  end
26
+
27
+ def not_null?
28
+ not_null == true
29
+ end
23
30
  end
24
31
 
25
32
  RUBY_TYPE_MAPPING = {
@@ -52,7 +59,7 @@ module Rigor
52
59
  # assumes these exist; users who run `create_table id: false` or `id: nil` get no implicit `id` column from
53
60
  # the parser, but most apps never disable it.
54
61
  IMPLICIT_COLUMNS = [
55
- Column.new(name: "id", type: :integer, ruby_type: "Integer").freeze
62
+ Column.new(name: "id", type: :integer, ruby_type: "Integer", not_null: true).freeze
56
63
  ].freeze
57
64
 
58
65
  attr_reader :tables
@@ -147,10 +147,21 @@ module Rigor
147
147
  name: name,
148
148
  type: rails_type,
149
149
  ruby_type: ruby_type,
150
- array: array
150
+ array: array,
151
+ not_null: not_null_constraint?(rest)
151
152
  )
152
153
  end
153
154
 
155
+ # #3322 — `NOT NULL` / `PRIMARY KEY` among the column's own constraints. String literals and
156
+ # parenthesised expressions are removed first (`DEFAULT 'NOT NULL'::text`,
157
+ # `GENERATED ALWAYS AS (… IS NOT NULL …)`, `CHECK (…)`), since a `NOT NULL` inside one says nothing about
158
+ # the column; pg_dump's `DEFAULT 'x'::text NOT NULL` keeps its trailing constraint.
159
+ def not_null_constraint?(rest)
160
+ constraints = rest.gsub(/'(?:[^']|'')*'/, "''")
161
+ nil while constraints.gsub!(/\([^()]*\)/, "")
162
+ constraints.match?(/\b(?:NOT\s+NULL|PRIMARY\s+KEY)\b/i)
163
+ end
164
+
154
165
  # The type is every token before the first uppercase-initial token (a column modifier such as
155
166
  # `NOT`, `NULL`, `DEFAULT`, `GENERATED`, `COLLATE`). A trailing `[]` marks a Postgres array column;
156
167
  # a `(length[,scale])` specifier is dropped. Returns `[normalized_type, array?, scale]`, where `scale` is