Skip to content

Add DSL compiler for RuboCop def_node_matcher/def_node_search#2661

Draft
Vein05 wants to merge 1 commit into
Shopify:mainfrom
Vein05:feature/rubocop-node-pattern-compiler
Draft

Add DSL compiler for RuboCop def_node_matcher/def_node_search#2661
Vein05 wants to merge 1 commit into
Shopify:mainfrom
Vein05:feature/rubocop-node-pattern-compiler

Conversation

@Vein05

@Vein05 Vein05 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new RubocopNodePattern DSL compiler that generates RBI files for RuboCop cops using def_node_matcher and def_node_search macros.

Detection Strategy

  • Uses the param0 heuristic to identify macro-generated methods (no false positives across 594+ cops)
  • [:opt, :param0]def_node_matcher, [:req, :param0]def_node_search
  • Reads source_location to extract the pattern string and count captures

Return Type Logic

  • def_node_matcher: 0 captures → T::Boolean, 1+ captures → T.untyped
  • def_node_search: predicate (?) → T::Boolean, otherwise → T::Enumerator[::RuboCop::AST::Node]
  • Handles extra pattern arguments (%1, %2) as additional T.untyped parameters

Status

🚧 Work in progress — initial skeleton with core functionality. Still TODO:

  • Edge case handling (multi-line patterns, inline string patterns)
  • Error handling for unreadable source locations
  • More comprehensive test coverage
  • Performance testing against large cop codebases

Resolves #2321

Test plan

  • All 8 initial specs passing
  • Test against real-world rubocop extensions (rubocop-rails, rubocop-rspec)
  • Verify generated RBIs match actual method signatures
  • Run full test suite to check for regressions

Initial skeleton for the RubocopNodePattern compiler that generates
RBI files for RuboCop cops using def_node_matcher and def_node_search
macros. Uses the param0 heuristic to detect macro-generated methods
and source_location to extract patterns for capture counting.

Resolves Shopify#2321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: DSL compiler for RuboCop's def_node_matcher

1 participant