-
Notifications
You must be signed in to change notification settings - Fork 450
Ignore visibility method, attr definition, module_function within block #1595
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
tompng
wants to merge
2
commits into
ruby:master
Choose a base branch
from
tompng:ignore_within_block
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.
+127
−20
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 @@ class RDoc::Parser::PrismRuby < RDoc::Parser | |
| parse_files_matching(/\.rbw?$/) if ENV['RDOC_USE_PRISM_PARSER'] | ||
|
|
||
| attr_accessor :visibility | ||
| attr_reader :container, :singleton | ||
| attr_reader :container, :singleton, :in_proc_block | ||
|
|
||
| def initialize(top_level, content, options, stats) | ||
| super | ||
|
|
@@ -43,9 +43,10 @@ def initialize(top_level, content, options, stats) | |
| # example: `Module.new { include M }` `M.module_eval { include N }` | ||
|
|
||
| def with_in_proc_block | ||
| in_proc_block = @in_proc_block | ||
| @in_proc_block = true | ||
| yield | ||
| @in_proc_block = false | ||
| @in_proc_block = in_proc_block | ||
| end | ||
|
|
||
| # Dive into another container | ||
|
|
@@ -480,7 +481,6 @@ def add_attributes(names, rw, line_no) | |
| # Adds includes/extends. Module name is resolved to full before adding. | ||
|
|
||
| def add_includes_extends(names, rdoc_class, line_no) # :nodoc: | ||
| return if @in_proc_block | ||
| comment, directives = consecutive_comment(line_no) | ||
| handle_code_object_directives(@container, directives) if directives | ||
| names.each do |name| | ||
|
|
@@ -508,8 +508,6 @@ def add_extends(names, line_no) # :nodoc: | |
| # Adds a method defined by `def` syntax | ||
|
|
||
| def add_method(method_name, receiver_name:, receiver_fallback_type:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, start_line:, args_end_line:, end_line:) | ||
| return if @in_proc_block | ||
|
|
||
| receiver = receiver_name ? find_or_create_module_path(receiver_name, receiver_fallback_type) : @container | ||
| comment, directives = consecutive_comment(start_line) | ||
| handle_code_object_directives(@container, directives) if directives | ||
|
|
@@ -745,11 +743,14 @@ def visit_call_node(node) | |
| when :extend | ||
| _visit_call_extend(node) | ||
| when :public | ||
| _visit_call_public_private_protected(node, :public) { super } | ||
| super | ||
| _visit_call_public_private_protected(node, :public) | ||
| when :private | ||
| _visit_call_public_private_protected(node, :private) { super } | ||
| super | ||
| _visit_call_public_private_protected(node, :private) | ||
| when :protected | ||
| _visit_call_public_private_protected(node, :protected) { super } | ||
| super | ||
| _visit_call_public_private_protected(node, :protected) | ||
| when :private_constant | ||
| _visit_call_private_constant(node) | ||
| when :public_constant | ||
|
|
@@ -759,11 +760,14 @@ def visit_call_node(node) | |
| when :alias_method | ||
| _visit_call_alias_method(node) | ||
| when :module_function | ||
| _visit_call_module_function(node) { super } | ||
| super | ||
| _visit_call_module_function(node) | ||
| when :public_class_method | ||
| _visit_call_public_private_class_method(node, :public) { super } | ||
| super | ||
| _visit_call_public_private_class_method(node, :public) | ||
| when :private_class_method | ||
| _visit_call_public_private_class_method(node, :private) { super } | ||
| super | ||
| _visit_call_public_private_class_method(node, :private) | ||
| else | ||
| super | ||
| end | ||
|
|
@@ -774,12 +778,14 @@ def visit_call_node(node) | |
|
|
||
| def visit_block_node(node) | ||
| @scanner.with_in_proc_block do | ||
| # include, extend and method definition inside block are not documentable | ||
| # include, extend and method definition inside block are not documentable. | ||
| # visibility methods and attribute definition methods should be ignored inside block. | ||
| super | ||
| end | ||
| end | ||
|
|
||
| def visit_alias_method_node(node) | ||
| return if @scanner.in_proc_block | ||
| @scanner.process_comments_until(node.location.start_line - 1) | ||
| return unless node.old_name.is_a?(Prism::SymbolNode) && node.new_name.is_a?(Prism::SymbolNode) | ||
| @scanner.add_alias_method(node.old_name.value.to_s, node.new_name.value.to_s, node.location.start_line) | ||
|
|
@@ -858,6 +864,8 @@ def visit_def_node(node) | |
| end_line = node.location.end_line | ||
| @scanner.process_comments_until(start_line - 1) | ||
|
|
||
| return if @scanner.in_proc_block | ||
|
|
||
| case node.receiver | ||
| when Prism::NilNode, Prism::TrueNode, Prism::FalseNode | ||
| visibility = :public | ||
|
|
@@ -995,37 +1003,39 @@ def _visit_call_require(call_node) | |
| end | ||
|
|
||
| def _visit_call_module_function(call_node) | ||
| yield | ||
| return if @scanner.singleton | ||
| return if @scanner.in_proc_block || @scanner.singleton | ||
| names = visibility_method_arguments(call_node, singleton: false)&.map(&:to_s) | ||
| @scanner.change_method_to_module_function(names) if names | ||
| end | ||
|
|
||
| def _visit_call_public_private_class_method(call_node, visibility) | ||
| yield | ||
| return if @scanner.singleton | ||
| return if @scanner.in_proc_block || @scanner.singleton | ||
| names = visibility_method_arguments(call_node, singleton: true) | ||
| @scanner.change_method_visibility(names, visibility, singleton: true) if names | ||
| end | ||
|
|
||
| def _visit_call_public_private_protected(call_node, visibility) | ||
| return if @scanner.in_proc_block | ||
| arguments_node = call_node.arguments | ||
| if arguments_node.nil? # `public` `private` | ||
| @scanner.visibility = visibility | ||
| else # `public :foo, :bar`, `private def foo; end` | ||
| yield | ||
| names = visibility_method_arguments(call_node, singleton: false) | ||
| @scanner.change_method_visibility(names, visibility) if names | ||
| end | ||
| end | ||
|
|
||
| def _visit_call_alias_method(call_node) | ||
| return if @scanner.in_proc_block | ||
|
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. Should the same check be added to
Member
Author
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. Nice catch! Fixed |
||
|
|
||
| new_name, old_name, *rest = symbol_arguments(call_node) | ||
| return unless old_name && new_name && rest.empty? | ||
| @scanner.add_alias_method(old_name.to_s, new_name.to_s, call_node.location.start_line) | ||
| end | ||
|
|
||
| def _visit_call_include(call_node) | ||
| return if @scanner.in_proc_block | ||
|
|
||
| names = constant_arguments_names(call_node) | ||
| line_no = call_node.location.start_line | ||
| return unless names | ||
|
|
@@ -1038,26 +1048,30 @@ def _visit_call_include(call_node) | |
| end | ||
|
|
||
| def _visit_call_extend(call_node) | ||
| return if @scanner.in_proc_block | ||
|
|
||
| names = constant_arguments_names(call_node) | ||
| @scanner.add_extends(names, call_node.location.start_line) if names && !@scanner.singleton | ||
| end | ||
|
|
||
| def _visit_call_public_constant(call_node) | ||
| return if @scanner.singleton | ||
| 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 | ||
| end | ||
|
|
||
| def _visit_call_private_constant(call_node) | ||
| return if @scanner.singleton | ||
| 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 | ||
| 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 | ||
| end | ||
|
|
||
| class MethodSignatureVisitor < Prism::Visitor # :nodoc: | ||
| class << self | ||
| def scan_signature(def_node) | ||
|
|
||
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.