-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes #43] Basic support for non-legacy emitters
- Loading branch information
Showing
13 changed files
with
205 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module AST | ||
# Used for modern support only! | ||
# Not as thoroughly tested as legacy equivalent | ||
# | ||
# $ ruby-parse -e "foo[:bar]" | ||
# (index | ||
# (send nil :foo) | ||
# (sym :bar)) | ||
# $ ruby-parse --legacy -e "foo[:bar]" | ||
# (send | ||
# (send nil :foo) :[] | ||
# (sym :bar)) | ||
# | ||
# The main RuboCop runs in legacy mode; this node is only used | ||
# if user `AST::Builder.modernize` or `AST::Builder.emit_index=true` | ||
class IndexNode < Node | ||
include ParameterizedNode | ||
include MethodDispatchNode | ||
|
||
# For similarity with legacy mode | ||
def attribute_accessor? | ||
false | ||
end | ||
|
||
# For similarity with legacy mode | ||
def assignment_method? | ||
false | ||
end | ||
|
||
# For similarity with legacy mode | ||
def method_name | ||
:[] | ||
end | ||
|
||
# An array containing the arguments of the dispatched method. | ||
# | ||
# @return [Array<Node>] the arguments of the dispatched method | ||
def arguments | ||
node_parts[1..-1] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module AST | ||
# Used for modern support only! | ||
# Not as thoroughly tested as legacy equivalent | ||
# | ||
# $ ruby-parse -e "foo[:bar] = :baz" | ||
# (indexasgn | ||
# (send nil :foo) | ||
# (sym :bar) | ||
# (sym :baz)) | ||
# $ ruby-parse --legacy -e "foo[:bar] = :baz" | ||
# (send | ||
# (send nil :foo) :[]= | ||
# (sym :bar) | ||
# (sym :baz)) | ||
# | ||
# The main RuboCop runs in legacy mode; this node is only used | ||
# if user `AST::Builder.modernize` or `AST::Builder.emit_index=true` | ||
class IndexasgnNode < Node | ||
include ParameterizedNode | ||
include MethodDispatchNode | ||
|
||
# For similarity with legacy mode | ||
def attribute_accessor? | ||
false | ||
end | ||
|
||
# For similarity with legacy mode | ||
def assignment_method? | ||
true | ||
end | ||
|
||
# For similarity with legacy mode | ||
def method_name | ||
:[]= | ||
end | ||
|
||
# An array containing the arguments of the dispatched method. | ||
# | ||
# @return [Array<Node>] the arguments of the dispatched method | ||
def arguments | ||
node_parts[1..-1] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module AST | ||
# Used for modern support only: | ||
# Not as thoroughly tested as legacy equivalent | ||
# | ||
# $ ruby-parse -e "->(foo) { bar }" | ||
# (block | ||
# (lambda) | ||
# (args | ||
# (arg :foo)) | ||
# (send nil :bar)) | ||
# $ ruby-parse --legacy -e "->(foo) { bar }" | ||
# (block | ||
# (send nil :lambda) | ||
# (args | ||
# (arg :foo)) | ||
# (send nil :bar)) | ||
# | ||
# The main RuboCop runs in legacy mode; this node is only used | ||
# if user `AST::Builder.modernize` or `AST::Builder.emit_lambda=true` | ||
class LambdaNode < Node | ||
include ParameterizedNode | ||
include MethodDispatchNode | ||
|
||
# For similarity with legacy mode | ||
def lambda? | ||
true | ||
end | ||
|
||
# For similarity with legacy mode | ||
def lambda_literal? | ||
true | ||
end | ||
|
||
# For similarity with legacy mode | ||
def attribute_accessor? | ||
false | ||
end | ||
|
||
# For similarity with legacy mode | ||
def assignment_method? | ||
false | ||
end | ||
|
||
# For similarity with legacy mode | ||
def method_name | ||
:lambda | ||
end | ||
|
||
# For similarity with legacy mode | ||
def arguments | ||
[] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters