Navigation Menu

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

Style/MethodCallWithArgsParentheses doesn't respect endless class method parethensis #9707

Closed
bkuhlmann opened this issue Apr 18, 2021 · 0 comments · Fixed by #9708
Closed
Assignees

Comments

@bkuhlmann
Copy link

bkuhlmann commented Apr 18, 2021

Expected behavior

When using the following Rubocop configuration (note the enforced style):

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

I would not expect to have a violation for the following contrived code sample (note the use of the endless class method for .call):

# frozen_string_literal: true

require "http"

class Example
  def self.call = new(client: HTTP)

  def initialize client: HTTP
    @client = client
  end

  private

  attr_reader :client
end

In the above scenario, the parenthesis can't be removed because the endless method would no longer be syntactically correct for Ruby 3.0.0.

Actual behavior

When using the above configuration, you'll end up with this error:

Inspecting 1 file
C

Offenses:

/Users/bkuhlmann/Engineering/Misc/snippet.rb:6:22: C: [Correctable] Style/MethodCallWithArgsParentheses: Omit parentheses for method calls with arguments. (https://rubystyle.guide#method-invocation-parens)
  def self.call = new(client: HTTP)
                     ^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense auto-correctable

Steps to reproduce the problem

To reproduce this issue, use the above Rubocop configuration and Ruby code snippet saved as snippet.rb. You can then then run Rubocop as follows to reproduce the error:

rubocop snippet.rb

RuboCop version

rubocop -V
1.12.1 (using Parser 3.0.1.0, rubocop-ast 1.4.1, running on ruby 3.0.1 arm64-darwin20)
  - rubocop-performance 1.10.2
  - rubocop-rake 0.5.1
  - rubocop-rspec 2.2.0
@dvandersluis dvandersluis self-assigned this Apr 18, 2021
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Apr 18, 2021
…rentheses` with `omit_parentheses` style on an endless `defs` node.
koic added a commit that referenced this issue Apr 18, 2021
[Fix #9707] Fix false positive for `Style/MethodCallWithArgsParentheses` with `omit_parentheses` style on an endless `defs` node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants