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 an incorrect auto-correct for Lint/AmbiguousOperator #9671

Merged

Commits on Apr 3, 2021

  1. Fix an incorrect auto-correct for Lint/AmbiguousOperator

    This PR fixes the following incorrect auto-correct for
    `Style/MethodCallWithArgsParentheses` with `Lint/AmbiguousOperator`.
    
    ```console
    % cat example.rb
    def foo(&block)
      do_something &block
    end
    
    % rubocop --only Style/MethodCallWithArgsParentheses,Lint/AmbiguousOperator -a
    Inspecting 4 files
    ..WC
    
    Offenses:
    
    example.rb:2:3: C: [Corrected] Style/MethodCallWithArgsParentheses: Use
    parentheses for method calls with arguments.
      do_something &block
      ^^^^^^^^^^^^^^^^^^^
    example.rb:2:16: W: [Corrected] Lint/AmbiguousOperator: Ambiguous block
    operator. Parenthesize the method arguments if it's surely a block
    operator, or add a whitespace to the right of the & if it should be a
    binary AND.
      do_something &block
                   ^
    ripper/example.rb:6:5: C: [Corrected]
    Style/MethodCallWithArgsParentheses: Use parentheses for method calls
    with arguments.
        raise message
        ^^^^^^^^^^^^^
    
    4 files inspected, 3 offenses detected, 3 offenses corrected
    ```
    
    ## Before
    
    Syntax error with redundant closing parentheses.
    
    ```console
    % cat example.rb
    def foo(&block)
      do_something(&block))
    end
    
    % ruby -c example.rb
    example.rb:2: syntax error, unexpected ')', expecting end
      do_something(&block))
    ```
    
    ## After
    
    Valid syntax.
    
    ```console
    % cat example.rb
    def foo(&block)
      do_something(&block)
    end
    ```
    koic committed Apr 3, 2021
    Copy the full SHA
    e0342b2 View commit details
    Browse the repository at this point in the history