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

False negatives in Layout/ClassStructure with inline access modifiers #9415

Closed
dduugg opened this issue Jan 26, 2021 · 3 comments · Fixed by #9419
Closed

False negatives in Layout/ClassStructure with inline access modifiers #9415

dduugg opened this issue Jan 26, 2021 · 3 comments · Fixed by #9419
Labels

Comments

@dduugg
Copy link
Contributor

dduugg commented Jan 26, 2021

The Layout/ClassStructure cop fails to surface private/public method ordering violations when inline access modifiers are used. Given the file ab.rb with:

class A
  private def foo
  end

  public def bar
  end
end

class B
  private
  def foo
  end

  public
  def bar
  end
end

Expected behavior

Layout/ClassStructure should be agnostic to visibility modifier and flag both definitions of bar (A#bar and B#bar).

Actual behavior

Only B#bar is flagged:

rubocop ab.rb --only Layout/ClassStructure
Inspecting 1 file
C

Offenses:

ab.rb:15:3: C: [Correctable] Layout/ClassStructure: public_methods is supposed to appear before private_methods.
  def bar ...
  ^^^^^^^

1 file inspected, 1 offense detected, 1 offense auto-correctable

Steps to reproduce the problem

☝️

RuboCop version

1.8.1 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 3.0.0 x86_64-darwin20)
  - rubocop-performance 1.9.2
  - rubocop-rake 0.5.1
  - rubocop-rspec 2.1.0
  - rubocop-sorbet 0.5.1
@AndreiEres
Copy link

@dduugg, @koic
Could you have a look to that fix #9419?

@dduugg
Copy link
Contributor Author

dduugg commented Jan 26, 2021

Wow, fast work @AndreiEres! I left one comment, regarding implicit public methods.

AndreiEres pushed a commit to AndreiEres/rubocop that referenced this issue Jan 27, 2021
@AndreiEres
Copy link

@dduugg I suppose I fixed it

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.

3 participants