Skip to content

Feature request: DSL compiler for RuboCop's def_node_matcher #2321

Description

@amomchilov

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help-wantedWe support this change, and welcome community contributions for it.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions