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

Allow chained Hash#[] when BlockDelimiters braces_for_chaining is true #6847

Merged

Conversation

att14
Copy link

@att14 att14 commented Mar 19, 2019

Sometimes the return of a block is a Hash and Ruby allows you to call [] without a dot. This means only checking dot? in return_value_chaining? does not allow chaining Hash element reference. I wasn't sure if checking the explicit method name was the best choice or if there is something that I missed in the documentation.

I did not add an entry to the Changelog in order to get feedback first. If this is an acceptable change I will do so.


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.

@att14
Copy link
Author

att14 commented Mar 19, 2019

This doesn't work for the case,

        Hash[
          {foo: :bar}.map do |k, v|
            [k, v]
          end
        ]

Maybe someone with more knowledge of the AST could point me in the right direction for fixing this.

@att14 att14 force-pushed the block_delimiters_chain_hash_element_reference branch from 7b8a698 to 2b566bc Compare March 19, 2019 17:48
@att14
Copy link
Author

att14 commented Mar 19, 2019

chained? appears to work and the tests are passing. Is there any reason not to use chained? instead of return_value_chaining??

@att14
Copy link
Author

att14 commented Apr 29, 2019

Is anyone able to look at this? I'm pretty sure this is a bug. My company has been using this for some time with no issues.

Copy link
Collaborator

@Drenmi Drenmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me. 🙇

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 30, 2019

@att14 Sorry about the slow response - huge backlog of other tasks... :-( Rebase and add a changelog entry and we're good to go.

h.key?(:foo)
}[:foo]
RUBY
expect_no_offenses(<<-RUBY.strip_indent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example doesn't match the it description. In general I'd have one it per example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@att14 att14 force-pushed the block_delimiters_chain_hash_element_reference branch 2 times, most recently from fa5cb7f to c6e28d2 Compare April 30, 2019 15:27
@att14 att14 force-pushed the block_delimiters_chain_hash_element_reference branch from c6e28d2 to 2466225 Compare April 30, 2019 15:29
@att14
Copy link
Author

att14 commented Apr 30, 2019

Any ideas on why the 2.2 build is failing?

@bbatsov bbatsov merged commit fe316c2 into rubocop:master Apr 30, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 30, 2019

Seems that the newest version of byebug dropped support for Ruby 2.2.

@att14 att14 deleted the block_delimiters_chain_hash_element_reference branch May 1, 2019 01:34
@att14
Copy link
Author

att14 commented May 1, 2019

👍 thank you!

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.

None yet

3 participants