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 numblock regressions in omit_parentheses Style/MethodCallWithArgsParentheses` #12648

Merged
merged 1 commit into from
Jan 25, 2024

Commits on Jan 24, 2024

  1. Fix numblock regressions in omit_parentheses Style/MethodCallWithAr…

    …gsParentheses
    
    My last change was trying to fix an edge case where RuboCop wanted us to
    remove parentheses in the following example, but removing the parens was
    resulting in a `SyntaxError`:
    
    ```ruby
    AnyCable.middleware.use(
      Class.new(AnyCable::Middleware) do
               ^^^^^^^^^^^^^^^^^^^^^^ Omit parentheses for method calls with arguments.
        pass
      end
    )
    ```
    
    As it often happens, though, I broke a few other cases where we now want
    to remove parens, while the removal can result in ambiguous code:
    
    **Case 1**
    
    ```ruby
    Foo::Bar.find(pending.things.map { _1['code'] })
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Omit parentheses for method calls with arguments.
    ```
    
    While we can remove the parentheses in *Case 1*, the author has to be
    well aware of the difference between the do/end and braced blocks method
    bounding semantics. Allowing the author to put the parens can remove
    this ambiguity and we used to allow it.
    
    **Case 2**
    
    ```ruby
    [a, b].map { _1.call 'something' }.uniq.join(' - ')
                                                ^^^^^^^ Omit parentheses for method calls with arguments.
    ```
    
    If we set `AllowParenthesesInChaining: true`, we should allow
    parentheses in chained calls. However, this is broken in current
    RuboCop.
    
    Both of the issues were caused by a 'refactoring' that forgot to check
    argument calls or chaining with `numblocks` specifically.
    gsamokovarov committed Jan 24, 2024
    Configuration menu
    Copy the full SHA
    5d818a9 View commit details
    Browse the repository at this point in the history