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

Fix Style/MethodDefParentheses issue with splat forwarding #11361

Closed
bkuhlmann opened this issue Dec 30, 2022 · 0 comments · Fixed by #11362
Closed

Fix Style/MethodDefParentheses issue with splat forwarding #11361

bkuhlmann opened this issue Dec 30, 2022 · 0 comments · Fixed by #11362
Labels

Comments

@bkuhlmann
Copy link

Expected behavior

I would expect Style/MethodDefParentheses to not throw errors when forwarding splats (single and double). This is similar in nature to this issue opened last year when anonymous block support was added to Ruby.

Actual behavior

You'll get the following errors when using splat forwarding:

/Users/bkuhlmann/Engineering/Misc/snippet:16:13: C: [Correctable] Style/MethodDefParentheses: Use def without parentheses. (https://rubystyle.guide#method-parens)
  def single(*)
            ^^^
/Users/bkuhlmann/Engineering/Misc/snippet:20:13: C: [Correctable] Style/MethodDefParentheses: Use def without parentheses. (https://rubystyle.guide#method-parens)
  def double(**)
            ^^^^

Steps to reproduce the problem

Start by configuring Rubocop to use the following configuration:

Style/MethodDefParentheses:
  EnforcedStyle: require_no_parentheses

Next, use the following code as an example:

module Demo
  def single(*)
    super
  end

  def double(**)
    super
  end
end

Save the above and run as rubocop snippet.rb and notice you get the same errors as reported above. If you were to remove the parentheses -- as RuboCop suggests -- then you'd get the following syntax error:

syntax error, unexpected `super', expecting ';' or '\n'
  15  module Demo
> 16    def single *
> 18    end
  23  end
/Users/bkuhlmann/Engineering/Misc/snippet:17: syntax error, unexpected `super', expecting ';' or '\n' (SyntaxError)
    super
    ^~~~~

RuboCop version

1.41.1 (using Parser 3.1.3.0, rubocop-ast 1.24.1, running on ruby 3.2.0) [arm64-darwin22.2.0]
  - rubocop-performance 1.15.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.16.0
  - rubocop-thread_safety 0.4.4
@koic koic added the bug label Dec 31, 2022
koic added a commit to koic/rubocop that referenced this issue Dec 31, 2022
…ous rest and keyword rest args

Fixes rubocop#11361

This PR fixes a false positive for `Style/MethodDefParentheses` when using `EnforcedStyle: require_no_parentheses`
and Ruby 3.2's anonymous rest and keyword rest arguments.
koic added a commit to koic/rubocop that referenced this issue Dec 31, 2022
…ous rest and keyword rest args

Fixes rubocop#11361

This PR fixes a false positive for `Style/MethodDefParentheses` when using `EnforcedStyle: require_no_parentheses`
and Ruby 3.2's anonymous rest and keyword rest arguments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants