tapioca icon indicating copy to clipboard operation
tapioca copied to clipboard

Feature request: DSL compiler for RuboCop's `def_node_matcher`

Open amomchilov opened this issue 5 months ago • 0 comments
trafficstars

This code:

class MyCop < ::RuboCop::Cop::Base
  def_node_matcher :my_pattern?, <<~PATTERN
    (send _ :some_method ...)
  PATTERN
end

Should produce this RBI:

class MyCop < ::RuboCop::Cop::Base
  sig do
    params(
      node: RuboCop::AST::Node,
      block: T.proc.params(*captures: T.untyped).void,
    ).returns(T::Boolean)
  end
  def my_pattern?; end
end

Typing the block would be pretty challenging... we'd need to statically analyze the NodePattern, to figure out how many matches where will be. I just left it as an untyped varargs.

amomchilov avatar Jun 13 '25 18:06 amomchilov