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/MethodCallWithArgsParentheses for case expressions #12524

Closed
bkuhlmann opened this issue Dec 9, 2023 · 0 comments · Fixed by #12525
Closed

Fix Style/MethodCallWithArgsParentheses for case expressions #12524

bkuhlmann opened this issue Dec 9, 2023 · 0 comments · Fixed by #12525
Labels

Comments

@bkuhlmann
Copy link

Expected behavior

Hello. 👋 I would expect the following to not be flagged as an issue:

Unit = lambda do |duration, range: RANGE|
  case duration
    when range.fetch(:nanoseconds) then "ns"
    when range.fetch(:microseconds) then "µs"
    when range.fetch(:milliseconds) then "ms"
    when range.fetch(:seconds) then "s"
    else "m"
  end
end

Actual behavior

Given the above, RuboCop flags the use of parenthesis for #fetch but if you remove the parenthesis, you'll end up with a SyntaxError:

syntax error, unexpected symbol literal, expecting `then' or ',' or ';' or '\n'

Steps to reproduce the problem

You'll need this RuboCop configuration to run against the above code snippet:

Style/MethodCallWithArgsParentheses:
  Enabled: true
  EnforcedStyle: omit_parentheses
  AllowParenthesesInChaining: true
  AllowParenthesesInMultilineCall: true
  IgnoreMacros: false

RuboCop version

1.58.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [arm64-darwin22.4.0]
  - rubocop-capybara 2.19.0
  - rubocop-factory_bot 2.24.0
  - rubocop-packaging 0.5.2
  - rubocop-performance 1.19.1
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.25.0
  - rubocop-thread_safety 0.5.1
@bkuhlmann bkuhlmann changed the title Fix Style/MethodCallWithArgsParentheses for case statements Fix Style/MethodCallWithArgsParentheses for case expressions Dec 9, 2023
@koic koic added the bug label Dec 10, 2023
koic added a commit to koic/rubocop that referenced this issue Dec 10, 2023
…sParentheses`

Fixes rubocop#12524.

This PR fixes a false positive for `Style/MethodCallWithArgsParentheses`
when `EnforcedStyle: omit_parentheses` and parens in `when` clause is used to pass an argument.
bbatsov pushed a commit that referenced this issue Dec 11, 2023
…heses`

Fixes #12524.

This PR fixes a false positive for `Style/MethodCallWithArgsParentheses`
when `EnforcedStyle: omit_parentheses` and parens in `when` clause is used to pass an argument.
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