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

SingleArgumentDig false positive (*) #12284

Closed
johnnyshields opened this issue Oct 15, 2023 · 3 comments · Fixed by #12285
Closed

SingleArgumentDig false positive (*) #12284

johnnyshields opened this issue Oct 15, 2023 · 3 comments · Fixed by #12285
Labels

Comments

@johnnyshields
Copy link

johnnyshields commented Oct 15, 2023

Using Rubocop 1.57.1 with Ruby 3.2 -- latest release of both at time of writing.

    # incorrectly triggers SingleArgumentDig
    def foo(*)
      bar.dig(*)
    end

This was incorrectly autocorrected to:

    def foo(*)
      bar[*]
    end

Possibly PR #10576 fixed ... case but not * case, I'm not sure.

@koic
Copy link
Member

koic commented Oct 15, 2023

... accepts all arguments for delegation, whereas * is an anonymized *args. Thus, it seems like it should be treated the same as the good case { key1: { key2: 'value' } }.dig(*keys):
https://docs.rubocop.org/rubocop/1.57/cops_style.html#stylesingleargumentdig

What issues were encountered?

@johnnyshields
Copy link
Author

@koic when I used autocorrect it corrected it to:

     bar[*]

which is non-sense. I've updated the ticket description above. Thank you for your fast response as always 🙇‍♂️

@koic
Copy link
Member

koic commented Oct 15, 2023

Ah, I understand. This is clearly a bug. Thank you!

@koic koic added the bug label Oct 15, 2023
koic added a commit to koic/rubocop that referenced this issue Oct 16, 2023
Fixes rubocop#12284.

This PR fixes false positives for `Style/SingleArgumentDig`
when using some anonymous argument syntax.
koic added a commit that referenced this issue Oct 22, 2023
…gle_argument_dig

[Fix #12284] Fix false positives for `Style/SingleArgumentDig`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants