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
Add autocorrect support to Style/AccessModifierDeclarations
#10966
Conversation
93c9181
to
2a5e50b
Compare
node.parent.children.find do |child| | ||
child&.send_type? && child&.method?(node.method_name) && child&.arguments&.empty? | ||
end |
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.
node.parent.children.find do |child| | |
child&.send_type? && child&.method?(node.method_name) && child&.arguments&.empty? | |
end | |
node.parent.children.compact.find do |child| | |
child.send_type? && child.method?(node.method_name) && child.arguments.empty? | |
end |
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.
I thought that it would be wasteful to iterate twice on #children
for this purpose.
By the way, if we want to remove this safe navigation operators, I think it is better to use #each_child_node
than to use #compact
, what do you think?
node.parent.children.find do |child| | |
child&.send_type? && child&.method?(node.method_name) && child&.arguments&.empty? | |
end | |
node.parent.each_child_node.find do |child| | |
child.send_type? && child.method?(node.method_name) && child.arguments.empty? | |
end |
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.
I think it's a good choice.
node.parent.children.find do |child| | ||
child&.def_type? && child&.method?(method_name) | ||
end |
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.
node.parent.children.find do |child| | |
child&.def_type? && child&.method?(method_name) | |
end | |
node.parent.children.compact.find do |child| | |
child.def_type? && child.method?(method_name) | |
end |
Could you add |
b96160b
to
f64b7e1
Compare
I added these 2 changes:
Whether or not to explicitly write |
node.parent.each_child_node.find do |child| | ||
child.def_type? && child.method?(method_name) |
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.
each_child_node
can filter node types.
node.parent.each_child_node.find do |child| | |
child.def_type? && child.method?(method_name) | |
node.parent.each_child_node(:def).find do |child| | |
child.method?(method_name) |
node.parent.each_child_node.find do |child| | ||
child.send_type? && child.method?(node.method_name) && child.arguments.empty? |
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.
node.parent.each_child_node.find do |child| | |
child.send_type? && child.method?(node.method_name) && child.arguments.empty? | |
node.parent.each_child_node(:send).find do |child| | |
child.method?(node.method_name) && child.arguments.empty? |
501af86
to
a2fe5ab
Compare
Thanks! |
I would like to change
Style/AccessModifierDeclarations
to be able to autocorrect.I made a little effort about indentation and empty lines with
RuboCop::Cop::RangeHelp#range_by_whole_lines
and some other treatments, but it does not handle them perfectly. They should be autocorrected by other Layout cops.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.