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

Unexpected method indentation when using access modifier #5380

Closed
ellingtonjp opened this issue Jan 2, 2018 · 0 comments · Fixed by #5962
Closed

Unexpected method indentation when using access modifier #5380

ellingtonjp opened this issue Jan 2, 2018 · 0 comments · Fixed by #5962
Labels

Comments

@ellingtonjp
Copy link

Expected behavior

I expect the following

class Foo
  public

    def bar
      puts 42
    end

    def baz
      puts 42
    end

    def nop
      puts 42
    end
end

to be corrected to

class Foo
  public

  def bar
    puts 42
  end

  def baz
    puts 42
  end

  def nop
    puts 42
  end
end

Actual behavior

Nothing is corrected in that case.

Additionally, rubocop will adjust indentation based on the first method. For example,

class Foo
  public

        def bar
          puts 42
        end

  def baz
    puts 42
  end

  def nop
    puts 42
  end
end

is corrected to

class Foo
  public

        def bar
          puts 42
        end

        def baz
          puts 42
        end

        def nop
          puts 42
        end
end

When using no access modifier, methods are always indented to two spaces, as expected.

Steps to reproduce the problem

Run rubocop on the previous examples with default configuration and no arguments.

RuboCop version

$ rubocop -V
0.52.1 (using Parser 2.4.0.2, running on ruby 2.2.4 x86_64-linux-gnu)
$ ruby --version
ruby 2.2.4p230 (2015-12-16) [x86_64-linux-gnu]
@bbatsov bbatsov added the bug label Jan 4, 2018
tatsuyafw added a commit to tatsuyafw/rubocop that referenced this issue Jun 6, 2018
Fix `Layout/IndentationWidth` not detecting invalid indentation of methods
in an access modifier section.
bbatsov pushed a commit that referenced this issue Jun 6, 2018
Fix `Layout/IndentationWidth` not detecting invalid indentation of methods
in an access modifier section.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants