-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ArgNode for
arg
, kwarg
, optarg
, restarg
, kwoptarg
, `kwr…
…estarg`, `blockarg`, `forward_arg` and `shadowarg` types. - Add `ArgsNode#argument_list` to return all descendant argument type nodes. - Added Procarg0Node for modernized compatibility with ArgNode. - Expose `ArgsNode#argument_list` on `BlockNode`.
- Loading branch information
1 parent
6dad540
commit d658902
Showing
14 changed files
with
507 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#154](https://github.com/rubocop-hq/rubocop-ast/pull/154): Add `BlockNode#argument_list` and `BlockNode#argument_names`. ([@dvandersluis][]) |
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,2 @@ | ||
* [#154](https://github.com/rubocop-hq/rubocop-ast/pull/154): Add `ArgNode` and `Procarg0Node` ("modern" mode), and add `ArgsNode#argument_list` to get only argument type nodes. ([@dvandersluis][]) | ||
|
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module AST | ||
# A node extension for `arg`, `optarg`, `restarg`, `kwarg`, `kwoptarg`, | ||
# `kwrestarg`, `blockarg`, `shadowarg` and `forward_arg` nodes. | ||
# This will be used in place of a plain node when the builder constructs | ||
# the AST, making its methods available to all `arg` nodes within RuboCop. | ||
class ArgNode < Node | ||
# Returns the name of an argument. | ||
# | ||
# @return [Symbol, nil] the name of the argument | ||
def name | ||
node_parts[0] | ||
end | ||
|
||
# Returns the default value of the argument, if any. | ||
# | ||
# @return [Node, nil] the default value of the argument | ||
def default_value | ||
return unless default? | ||
|
||
node_parts[1] | ||
end | ||
|
||
# Checks whether the argument has a default value | ||
# | ||
# @return [Boolean] whether the argument has a default value | ||
def default? | ||
optarg_type? || kwoptarg_type? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module AST | ||
# A node extension for `procarg0` nodes. | ||
# This will be used in place of a plain node when the builder constructs | ||
# the AST, making its methods available to all `arg` nodes within RuboCop. | ||
class Procarg0Node < ArgNode | ||
# Returns the name of an argument. | ||
# | ||
# @return [Symbol, nil] the name of the argument | ||
def name | ||
node_parts[0].name | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.