Rubocop: Replace single dig to [] access

Created on 10 May 2020  路  5Comments  路  Source: rubocop-hq/rubocop

Is your feature request related to a problem? Please describe.

When you refactor you code from:

{ key: { subkey: 'value' } }.dig(:key, :subkey)

to:

{ key: 'value' }.dig(:key)

You can forget to use just [] to access the value.

Describe the solution you'd like

Replace single dig methods to [] access.

From:

{ key: 'value' }.dig(:key)

to:

{ key: 'value' }[:key]
feature request good first issue

Most helpful comment

Thank you, @volfgox !

All 5 comments

I'd like to try to implement this feature.

@volfgox I have seen you did some work on this. Mind opening a PR?

@fatkodima I finalized the development and sent a PR and waited long long time to merge. But, It's never been merged. You can review the PR here.

P.S. @bbatsov Would you please consider the PR?

Thank you, @volfgox !

@wbotelhos Thank you too. I hope I can contribute more.

Was this page helpful?
0 / 5 - 0 ratings