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

Style/StructInheritance auto-correct can result in an empty block lint violation if the class is empty. #9627

Closed
snood1205 opened this issue Mar 22, 2021 · 0 comments
Labels

Comments

@snood1205
Copy link

@snood1205 snood1205 commented Mar 22, 2021

The Style/StructInheritance auto-correct treats all class _ < Struct.new inheritance to Struct.new do; end instead of just Struct.new


Expected behavior

If there a struct defined in the following format with an empty class body, as portrayed below:

class Foo < Struct.new(:bar, :baz)
end

It should be corrected to

Foo = Struct.new(:bar, :baz)

Actual behavior

The class mentioned above is corrected to

Foo = Struct.new(:bar, :baz) do
end

This will cause another rubocop violation for an empty block upon running rubocop again.

Steps to reproduce the problem

Any Struct declared in class syntax with an empty body will cause this problem

RuboCop version

$ bundle exec rubocop -V
1.11.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.1 x86_64-darwin19)
  - rubocop-rspec 2.2.0
@koic koic added the bug label Mar 22, 2021
koic added a commit to koic/rubocop that referenced this issue Mar 22, 2021
…eritance`

Fixes rubocop#9627.

This PR fixes an incorrect auto-correct for `Style/StructInheritance` when
extending instance of Struct without `do` ... `end` and class body is empty.
bbatsov added a commit that referenced this issue Mar 22, 2021
Fixes #9627.

This PR fixes an incorrect auto-correct for `Style/StructInheritance` when
extending instance of Struct without `do` ... `end` and class body is empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants