Skip to content

Commit

Permalink
Add Node#global_const?
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Jul 13, 2020
1 parent 805c7c0 commit 4038a79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [#50](https://github.com/rubocop-hq/rubocop-ast/pull/50): Support find pattern matching for Ruby 2.8 (3.0) parser. ([@koic][])
* [#55](https://github.com/rubocop-hq/rubocop-ast/pull/55): Add `ProcessedSource#line_with_comment?`. ([@marcandre][])
* [#63](https://github.com/rubocop-hq/rubocop-ast/pull/63): NodePattern now supports patterns as arguments to predicate and functions. ([@marcandre][])
* [#64](https://github.com/rubocop-hq/rubocop-ast/pull/64): Add `Node#global_const?`. ([@marcandre][])

### Bug fixes

Expand Down
14 changes: 8 additions & 6 deletions lib/rubocop/ast/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ def const_name
def_node_matcher :defined_module0, <<~PATTERN
{(class (const $_ $_) ...)
(module (const $_ $_) ...)
(casgn $_ $_ (send (const nil? {:Class :Module}) :new ...))
(casgn $_ $_ (block (send (const nil? {:Class :Module}) :new ...) ...))}
(casgn $_ $_ (send #global_const?({:Class :Module}) :new ...))
(casgn $_ $_ (block (send #global_const?({:Class :Module}) :new ...) ...))}
PATTERN

private :defined_module0
Expand Down Expand Up @@ -496,16 +496,18 @@ def guard_clause?

def_node_matcher :proc?, <<~PATTERN
{(block (send nil? :proc) ...)
(block (send (const nil? :Proc) :new) ...)
(send (const nil? :Proc) :new)}
(block (send #global_const?(:Proc) :new) ...)
(send #global_const?(:Proc) :new)}
PATTERN

def_node_matcher :lambda?, '({block numblock} (send nil? :lambda) ...)'
def_node_matcher :lambda_or_proc?, '{lambda? proc?}'

def_node_matcher :global_const?, '(const {nil? cbase} %1)'

def_node_matcher :class_constructor?, <<~PATTERN
{ (send (const nil? {:Class :Module}) :new ...)
(block (send (const nil? {:Class :Module}) :new ...) ...)}
{ (send #global_const?({:Class :Module}) :new ...)
(block (send #global_const?({:Class :Module}) :new ...) ...)}
PATTERN

# Some expressions are evaluated for their value, some for their side
Expand Down

0 comments on commit 4038a79

Please sign in to comment.