Skip to content

Commit

Permalink
Improve doc for NodePattern parameters [doc] [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Jun 22, 2020
1 parent 41306ed commit c6db124
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/ROOT/pages/node_pattern.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions lib/rubocop/ast/node_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c6db124

Please sign in to comment.