tapioca
tapioca copied to clipboard
Feature request: DSL compiler for RuboCop's `def_node_matcher`
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.