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 error with guarded standalone pattern #12134

Closed
bkuhlmann opened this issue Aug 19, 2023 · 0 comments · Fixed by #12135
Closed

Fix Style/MethodCallWithArgsParentheses error with guarded standalone pattern #12134

bkuhlmann opened this issue Aug 19, 2023 · 0 comments · Fixed by #12135
Labels

Comments

@bkuhlmann
Copy link

Expected behavior

I'd expect the following to not cause an error since the parenthesis are required:

demo = {a: 1, b: 2, c: 3}
puts "Found." if demo.values_at(:a, :c) in Integer, Integer

Actual behavior

The following error will appear:

C: [Correctable] Style/MethodCallWithArgsParentheses: Omit parentheses for method calls with arguments. (https://rubystyle.guide#method-invocation-parens)
puts "Found." if demo.values_at(:a, :c) in Integer, Integer
                               ^^^^^^^^

Letting RuboCop auto-correct the error -- by removing the parenthesis -- will result in the following syntax error:

syntax error, unexpected `in', expecting end-of-input
> 17  puts "Found." if demo.values_at :a, :c in Integer, Integer

syntax error, unexpected `in', expecting end-of-input (SyntaxError)
...d." if demo.values_at :a, :c in Integer, Integer
...                             ^~

Steps to reproduce the problem

Use the following RuboCop configuration:

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

Use the following script:

#! /usr/bin/env ruby
# frozen_string_literal: true

# Save as `demo`, then `chmod 755 demo`, and run as `./demo`.

demo = {a: 1, b: 2, c: 3}
puts "Found." if demo.values_at(:a, :c) in Integer, Integer

RuboCop version

$ [bundle exec] rubocop -V
1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [arm64-darwin22.4.0]
  - rubocop-capybara 2.18.0
  - rubocop-factory_bot 2.23.1
  - rubocop-packaging 0.5.2
  - rubocop-performance 1.19.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.23.2
  - rubocop-thread_safety 0.5.1
@koic koic added the bug label Aug 20, 2023
koic added a commit to koic/rubocop that referenced this issue Aug 20, 2023
…sParentheses`

Fixes rubocop#12134.

This PR fixes a false positive for `Style/MethodCallWithArgsParentheses`
when parentheses are used in one-line `in` pattern matching.
bbatsov pushed a commit that referenced this issue Aug 20, 2023
…heses`

Fixes #12134.

This PR fixes a false positive for `Style/MethodCallWithArgsParentheses`
when parentheses are used in one-line `in` pattern matching.
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