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

Add new Lint/RequireRangeParentheses cop #10792

Merged

Commits on Jul 7, 2022

  1. Add new Lint/RequireRangeParentheses cop

    ## Context
    
    It emulates the following Ruby warning.
    
    ```console
    % cat example.rb
    1...
    2
    ```
    
    ```consle
    % ruby example.rb
    example.rb:1: warning: ... at EOL, should be parenthesized?
    ```
    
    So, this cop will detect case like rubocop#10789.
    
    ## Summary
    
    It checks that a range literal is enclosed in parentheses when the end of the range is
    at a line break.
    
    ### example
    
    ```ruby
    # bad - Represents `(1..42)`, not endless range.
    1..
    42
    
    # good - It's incompatible, but your intentions when using endless range may be:
    (1..)
    42
    
    # good
    1..42
    
    # good
    (1..42)
    
    # good
    (1..
    42)
    ```
    
    NOTE: The following is maybe intended for `(42..)`. But, compatible is `42..do_something`.
    So, this cop does not provide autocorrection because it is left to user.
    
    ```ruby
    case condition
    when 42..
      do_something
    end
    ```
    koic committed Jul 7, 2022
    Copy the full SHA
    3c96b2a View commit details
    Browse the repository at this point in the history