Skip to content
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

Leverage more node extensions #6954

Merged
merged 23 commits into from
Apr 22, 2019

Conversation

Drenmi
Copy link
Collaborator

@Drenmi Drenmi commented Apr 22, 2019

This change makes our InternalAffairs/NodeDestructuring a bit more picky. Before, it accepted splat destructuring, e.g.:

receiver, method_name, arguments = send_node

but with this change, it enforces the use of node extension methods for all use cases.

I hope to use this to guide me in adding more node extensions.

This change already comes with a slew of fixes where existing node extensions could be used in place of splat destructuring.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@Drenmi Drenmi changed the title Feature/node destructuring cop Leverage more node extensions Apr 22, 2019
@bbatsov bbatsov merged commit ad1d69b into rubocop:master Apr 22, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 22, 2019

Great work! 🙇

@Drenmi Drenmi deleted the feature/node-destructuring-cop branch April 23, 2019 01:03
koic added a commit to rubocop/rubocop-rails that referenced this pull request May 2, 2019
Follow up rubocop/rubocop#6954.

This PR applies `rubocop --auto-gen-config`.
koic added a commit to koic/rubocop-performance that referenced this pull request May 2, 2019
Follow up rubocop/rubocop#6954.

This PR applied `rubocop --auto-gen-config`.
@bbuchalter
Copy link

@Drenmi I'm trying to make some custom cops comply with this new rule, but I'm not familiar with node extensions. I don't see anything about it on the README or the wiki. Same examples:

option_node, value_node = *node
name, args, = *node
_name, superclass, _body = *node

Based on the message I see from Rubocop, I tried changing to this shape:

option_node = node.option_node
value_node = node.value_node

But I get errors like this:

undefined method `option_node' for #<RuboCop::AST::PairNode:0x007f80342d84d8>

Could you please advise?

@Drenmi
Copy link
Collaborator Author

Drenmi commented May 7, 2019

@bbuchalter You can find documentation for the node extension decorators in RubyDoc.

For example, if you have a PairNode, you can do node.key and node.value. (Provided by HashElementNode.)

If you have a SendNode, you can do node.method_name and node.arguments.

Etc.

Note that we don't have node extensions for all node types yet, but I'm working on it.

patrickm53 pushed a commit to patrickm53/performance-develop-rubyonrails that referenced this pull request Sep 23, 2022
Follow up rubocop/rubocop#6954.

This PR applied `rubocop --auto-gen-config`.
richardstewart0213 added a commit to richardstewart0213/performance-build-Performance-optimization-analysis- that referenced this pull request Nov 4, 2022
Follow up rubocop/rubocop#6954.

This PR applied `rubocop --auto-gen-config`.
Cute0110 added a commit to Cute0110/Rubocop-Performance that referenced this pull request Sep 28, 2023
Follow up rubocop/rubocop#6954.

This PR applied `rubocop --auto-gen-config`.
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this pull request Oct 5, 2023
Follow up rubocop/rubocop#6954.

This PR applied `rubocop --auto-gen-config`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants