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 #6699] Fix a false negative for Layout/IndentationWidth #6792

Merged
merged 1 commit into from
Feb 26, 2019

Commits on Feb 26, 2019

  1. [Fix rubocop#6699] Fix a false negative for Layout/IndentationWidth

    Fixes rubocop#6699.
    
    This PR fixes infinite loop for `Layout/IndentationWidth` and
    `Layout/IndentationConsistency` when bad modifier indentation
    before good method definition.
    
    ```ruby
    # exmaple.rb
    class Foo
          private
    
      def foo
      end
    end
    ```
    
    First, auto-corrected by `Layout/IndentationConsistency`.
    
    ```console
    % rubocop -v
    0.65.0
    % rubocop -a --only Layout/IndentationConsistency example.rb
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:4:3: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
      def foo ...
      ^^^^^^^
    
    1 file inspected, 1 offense detected, 1 offense corrected
    ```
    
    ```diff
    % g diff
    diff --git a/example.rb b/example.rb
    index 23d3556..974f101 100644
    --- a/example.rb
    +++ b/example.rb
    @@ -1,6 +1,6 @@
     class Foo
           private
    
    -  def foo
    -  end
    +      def foo
    +      end
     end
    ```
    
    Next, auto-corrected by `Layout/IndentationWidth`.
    
    ```console
    % rubocop -a --only Layout/IndentationWidth example.rb
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:4:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 6)
    spaces for indentation.
          def foo
    ^^^^^^
    
    1 file inspected, 1 offense detected, 1 offense corrected
    ```
    
    This will return to the original code.
    
    ```diff
    % g diff
    diff --git a/example.rb b/example.rb
    index 974f101..23d3556 100644
    --- a/example.rb
    +++ b/example.rb
    @@ -1,6 +1,6 @@
     class Foo
           private
    
    -      def foo
    -      end
    +  def foo
    +  end
     end
    ```
    
    That caused the infinite loop in `Layout/IndentationConsistency`
    and `Layout/IndentationWidth`.
    
    With this PR, `Layout/indentationWidth` cop makes aware of
    the bad modifier indentation before good method definition.
    
    ```console
    % rubocop -a --only Layout/IndentationWidth example.rb
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:2:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 6)
    spaces for indentation.
          private
    ^^^^^^
    
    1 file inspected, 1 offense detected, 1 offense corrected
    ```
    
    ```diff
    diff --git a/example.rb b/example.rb
    index 23d3556..07525ec 100644
    --- a/example.rb
    +++ b/example.rb
    @@ -1,5 +1,5 @@
     class Foo
    -      private
    +  private
    
       def foo
       end
    ```
    
    This PR fixes the above false negative. That would be an auto-correct expected.
    koic committed Feb 26, 2019
    Configuration menu
    Copy the full SHA
    f5b6244 View commit details
    Browse the repository at this point in the history