rubocop / rubocop-ast

RuboCop's AST extensions and NodePattern functionality
https://docs.rubocop.org/rubocop-ast
MIT License
112 stars 53 forks source link

Add `Node#type?` to reduce complexity of checking against multiple node types #329

Closed dvandersluis closed 4 weeks ago

dvandersluis commented 4 weeks ago

There are a lot of places in rubocop in which we check if a node is one of multiple node types. This allows those checks to be refactored to be less complex.

node.call_type? || node.const_type? || node.lvar_type?

# can become
node.type?(:call, :const, :lvar)

This covers both the standard node type predicates, as well as the meta predicates for multiple node types (ie. call_type? for send and csend).

If Node#string_type? in #328 is accepted, I'll add that in here as well.

marcandre commented 4 weeks ago

Great stuff, thanks!

marcandre commented 4 weeks ago

Let's see if we get other feedback on string_type? and I'll make a release shortly after