diff --git a/CHANGELOG.md b/CHANGELOG.md index aada835f0..167f33341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ * [#4](https://github.com/rubocop-hq/rubocop-ast/issues/4): Add `interpolation?` for `RegexpNode`. ([@tejasbubane][]) * [#20](https://github.com/rubocop-hq/rubocop-ast/pull/20): Add option predicates for `RegexpNode`. ([@owst][]) * [#11](https://github.com/rubocop-hq/rubocop-ast/issues/11): Add `argument_type?` method to make it easy to recognize argument nodes. ([@tejasbubane][]) -* [#31](https://github.com/rubocop-hq/rubocop-ast/pull/31): Use `param === node` to match params, which allows Regexp, Proc, Set, etc. ([@marcandre][]) +* [#31](https://github.com/rubocop-hq/rubocop-ast/pull/31): NodePattern now uses `param === node` to match params, which allows Regexp, Proc, Set in addition to Nodes and literals. ([@marcandre][]) * [#41](https://github.com/rubocop-hq/rubocop-ast/pull/41): Add `delimiters` and related predicates for `RegexpNode`. ([@owst][]) ## 0.0.3 (2020-05-15) diff --git a/docs/modules/ROOT/pages/node_pattern.adoc b/docs/modules/ROOT/pages/node_pattern.adoc index 2296374d1..8a7e6014c 100644 --- a/docs/modules/ROOT/pages/node_pattern.adoc +++ b/docs/modules/ROOT/pages/node_pattern.adoc @@ -409,6 +409,10 @@ has_user_data?(node, /^pass(word)?$/i) has_user_data?(node, ->(key) { # return true or false depending on key }) ---- +NOTE: `Array#===` will never match a single node element (so don't pass arrays), +but `Set#===` is an alias to `Set#include?` (Ruby 2.5+ only), and so can be +very useful to match within many possible literals / Nodes. + == `nil` or `nil?` Take a special attention to nil behavior: diff --git a/lib/rubocop/ast/node_pattern.rb b/lib/rubocop/ast/node_pattern.rb index d23a10230..28b4808d5 100644 --- a/lib/rubocop/ast/node_pattern.rb +++ b/lib/rubocop/ast/node_pattern.rb @@ -70,8 +70,12 @@ module AST # '(send %1 _)' # % stands for a parameter which must be supplied to # # #match at matching time # # it will be compared to the corresponding value in - # # the AST using #=== so you can pass Procs, Regexp - # # in addition to Nodes or literals. + # # the AST using #=== so you can pass Procs, Regexp, + # # etc. in addition to Nodes or literals. + # # `Array#===` will never match a node element, but + # # `Set#===` is an alias to `Set#include?` (Ruby 2.5+ + # # only), and so can be very useful to match within + # # many possible literals / Nodes. # # a bare '%' is the same as '%1' # # the number of extra parameters passed to #match # # must equal the highest % value in the pattern