-
Notifications
You must be signed in to change notification settings - Fork 464
Less strict parsing of visibility method arguments #1803
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
Open
nevans
wants to merge
5
commits into
ruby:master
Choose a base branch
from
nevans:less-strict-visibility-method-argument-parsing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+90
−45
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc11a60
Allow less strict attribute argument parsing
nevans f4607d2
Don't create meta attributes with no name
nevans 7e1a88d
Less strict parsing of visibility method arguments
nevans a7f4df8
Fix Parser::Ruby docs for `*_class_method`
nevans 242a1e9
Refactor Parser::Ruby#call_node_name_arguments
nevans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| # * constants | ||
| # * aliases | ||
| # * private, public, protected | ||
| # * private_class_function, public_class_function | ||
| # * private_class_method, public_class_method | ||
| # * private_constant, public_constant | ||
| # * module_function | ||
| # * attr, attr_reader, attr_writer, attr_accessor | ||
|
|
@@ -389,15 +389,23 @@ def handle_modifier_directive(code_object, line_no) # :nodoc: | |
| end | ||
|
|
||
| def call_node_name_arguments(call_node) # :nodoc: | ||
| return [] unless call_node.arguments | ||
| call_node.arguments.arguments.map do |arg| | ||
| case arg | ||
| when Prism::SymbolNode | ||
| arg.value | ||
| when Prism::StringNode | ||
| arg.unescaped | ||
| end | ||
| end || [] | ||
| return unless arguments_node = call_node.arguments | ||
| names = arguments_node.arguments.filter_map { |arg| argument_name(arg) } | ||
| names unless names.empty? | ||
| end | ||
|
|
||
| def call_node_name_argument(call_node) # :nodoc: | ||
| return unless call_node.arguments | ||
| argument_name(call_node.arguments.arguments.first) | ||
| end | ||
|
|
||
| def argument_name(argument_node) # :nodoc: | ||
| case argument_node | ||
| when Prism::SymbolNode | ||
| argument_node.value | ||
| when Prism::StringNode | ||
| argument_node.unescaped | ||
| end | ||
| end | ||
|
|
||
| # Handles meta method comments | ||
|
|
@@ -439,7 +447,7 @@ def handle_meta_method_comment(comment, directives, node) | |
| mark_container_documentable(@container) | ||
| end | ||
| elsif line_no || node | ||
| method_name ||= call_node_name_arguments(node).first if is_call_node | ||
| method_name ||= call_node_name_argument(node) if is_call_node | ||
| if node | ||
| tokens = syntax_highlighted_tokens(node) | ||
| line_no = node.location.start_line | ||
|
|
@@ -1232,6 +1240,10 @@ def constant_arguments_names(call_node) | |
| names.all? ? names : nil | ||
| end | ||
|
|
||
| def call_node_name_arguments(call_node) | ||
| @scanner.call_node_name_arguments(call_node) | ||
| end | ||
|
|
||
| def symbol_arguments(call_node) | ||
| arguments_node = call_node.arguments | ||
| return unless arguments_node && arguments_node.arguments.all? { |arg| arg.is_a?(Prism::SymbolNode)} | ||
|
|
@@ -1241,10 +1253,9 @@ def symbol_arguments(call_node) | |
| def visibility_method_arguments(call_node, singleton:) | ||
| arguments_node = call_node.arguments | ||
| return unless arguments_node | ||
| symbols = symbol_arguments(call_node) | ||
| if symbols | ||
| if (names = call_node_name_arguments(call_node)) | ||
| # module_function :foo, :bar | ||
| return symbols.map(&:to_s) | ||
| return names | ||
| else | ||
| return unless arguments_node.arguments.size == 1 | ||
| arg = arguments_node.arguments.first | ||
|
|
@@ -1334,20 +1345,20 @@ def _visit_call_extend(call_node) | |
|
|
||
| def _visit_call_public_constant(call_node) | ||
| return if @scanner.in_proc_block || @scanner.singleton | ||
| names = symbol_arguments(call_node) | ||
| @scanner.container.set_constant_visibility_for(names.map(&:to_s), :public) if names | ||
| return unless names = call_node_name_arguments(call_node) | ||
| @scanner.container.set_constant_visibility_for(names, :public) | ||
| end | ||
|
|
||
| def _visit_call_private_constant(call_node) | ||
| return if @scanner.in_proc_block || @scanner.singleton | ||
| names = symbol_arguments(call_node) | ||
| @scanner.container.set_constant_visibility_for(names.map(&:to_s), :private) if names | ||
| return unless names = call_node_name_arguments(call_node) | ||
| @scanner.container.set_constant_visibility_for(names, :private) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| end | ||
|
|
||
| def _visit_call_attr_reader_writer_accessor(call_node, rw) | ||
| return if @scanner.in_proc_block | ||
| names = symbol_arguments(call_node) | ||
| @scanner.add_attributes(names.map(&:to_s), rw, call_node.location.start_line) if names | ||
| return unless names = call_node_name_arguments(call_node) | ||
| @scanner.add_attributes(names, rw, call_node.location.start_line) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| end | ||
|
|
||
| class MethodSignatureVisitor < Prism::Visitor # :nodoc: | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think the original condition shape can be kept and is clearer