Shopify / Shopify/tapioca

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

Open
#2,321 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help-wanted
Dominant language
Ruby
Stars
873
Forks
164
Avg merge
4d 27m
Merged PRs (30d)
9

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation file or test is named. Start by locating the def_node_matcher RBI-generation entry point and any existing NodePattern handling, then compare its output with the example; done means generating the shown method signature and untyped variadic block for the sample matcher.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.