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 Style/HashConversion #9712

Commits on Apr 19, 2021

  1. Fix an incorrect auto-correct for Style/HashConversion

    This PR fixes the following incorrect auto-correct for `Style/HashConversion`
    when `Hash[]` as a method argument without parentheses.
    
    ```console
    % cat example.rb
    do_something Hash[a: b, c: d], 42
    
    % bundle exec rubocop --only Style/HashConversion -a
    (snip)
    
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:1:14: C: [Corrected] Style/HashConversion: Prefer literal
    hash to Hash[key: value, ...].
    do_something Hash[a: b, c: d], 42
                 ^^^^^^^^^^^^^^^^
    
    1 file inspected, 1 offense detected, 1 offense corrected
    ```
    
    ## Before
    
    Auto-corrected to invalid syntax.
    
    ```ruby
    % cat example.rb
    do_something {a: b, c: d}, 42
    
    % ruby -c example.rb
    example.rb:1: syntax error, unexpected ':', expecting '}'
    do_something {a: b, c: d}, 42
    ```
    
    ## After
    
    Auto-corrected to valid syntax.
    
    ```ruby
    % cat example.rb
    do_something({a: b, c: d}, 42)
    ```
    koic committed Apr 19, 2021
    Copy the full SHA
    e3b2ebf View commit details
    Browse the repository at this point in the history