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/SingleLineMethods #9740

Merged

Commits on Apr 26, 2021

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

    This PR fixes the following incorrect auto-correct for `Style/SingleLineMethods`
    when defining setter method.
    
    ```console
    % cat example.rb
    def foo=(other) @foo == foo end
    
    % bundle exec rubocop --only Style/SingleLineMethods -a
    (snip)
    
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:1:1: C: [Corrected] Style/SingleLineMethods: Avoid
    single-line method definitions.
    def foo=(other) @foo == foo end
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    1 file inspected, 1 offense detected, 1 offense corrected
    ```
    
    ### Before
    
    Auto-corrected to invalid syntax because setter method cannot be defined in
    an endless method definition.
    
    ```ruby
    % cat example.rb
    def foo=(other) = @foo == foo
    
    % ruby -c example.rb
    example.rb:1: setter method cannot be defined in an endless method definition
    def foo=(other) = @foo == foo
    ```
    
    ### After
    
    ```ruby
    % cat example.rb
    def foo=(other)
      @foo == foo
    end
    ```
    koic committed Apr 26, 2021
    Copy the full SHA
    16c0321 View commit details
    Browse the repository at this point in the history