I'm trying to develop a new cop (based on these guidelines) and am banging my head trying to get the correct node pattern.
I want the cop to register an offense when X.some_method
is called without providing a block.
i.e X.some_method
is an offense, but X.some_method { blah }
is not.
I got the correct pattern for identifying X.some_method
, which is '(send (const nil? :X) :some_method ...'
.
But not sure how to create a pattern for "is not given a block"?
Apparently, in the parsed AST, when a node is given a block, that node is then represented as the first child of that block.
i.e
And we can check that using the
Rubocop::AST
instances.Here is the full implementation (includes an option for multiple method names):