Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn on 'emit_match_pattern' #162

Merged
merged 2 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ See the [docs site](https://docs.rubocop.org/rubocop-ast) for more details.

### Parser compatibility switches

This gem, by default, uses most [legacy AST output from parser](https://github.com/whitequark/parser/#usage), except for `emit_forward_arg` which is set to `true`.
This gem, by default, uses most [legacy AST output from parser](https://github.com/whitequark/parser/#usage), except for the following which are set to `true`:
* `emit_forward_arg`
* `emit_match_pattern`

The main `RuboCop` gem uses these defaults (and is currently only compatible with these), but this gem can be used separately from `RuboCop` and is meant to be compatible with all settings. For example, to have `-> { ... }` emitted
as `LambdaNode` instead of `SendNode`:
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/ast/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module AST
# root_node = parser.parse(buffer)
class Builder < Parser::Builders::Default
self.emit_forward_arg = true
self.emit_match_pattern = true if respond_to?(:emit_match_pattern=)

# @api private
NODE_MAP = {
Expand Down Expand Up @@ -52,6 +53,7 @@ class Builder < Parser::Builders::Default
indexasgn: IndexasgnNode,
irange: RangeNode,
erange: RangeNode,
kwargs: HashNode,
kwsplat: KeywordSplatNode,
lambda: LambdaNode,
module: ModuleNode,
Expand Down
5 changes: 3 additions & 2 deletions lib/rubocop/ast/traversal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ def arity_check(range)
in_match match_alt break next
match_as array_pattern array_pattern_with_tail
hash_pattern const_pattern find_pattern
index indexasgn procarg0]
index indexasgn procarg0 kwargs]
many_opt_node_children = %i[case rescue resbody ensure for when
case_match in_pattern irange erange]
case_match in_pattern irange erange
match_pattern match_pattern_p]

### Callbacks for above
def_callback no_children
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
if ENV['MODERNIZE']
RuboCop::AST::Builder.modernize
RuboCop::AST::Builder.emit_forward_arg = false # inverse of default
if RuboCop::AST::Builder.respond_to?(:emit_match_pattern=)
RuboCop::AST::Builder.emit_match_pattern = false # inverse of default
end
end

RSpec.shared_context 'ruby 2.3', :ruby23 do
Expand Down