You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ rubocop -a hoge.rb
Inspecting 1 file
E
Offenses:
hoge.rb:2:14: C: [Corrected] Style/StructInheritance: Don't extend an instance initialized by Struct.new. Use a block to customize the struct.
class Hoge < Struct.new(:foo, :bar)
^^^^^^^^^^^^^^^^^^^^^^
hoge.rb:5:1: E: Lint/Syntax: unexpected token kEND
(Using Ruby 2.4 parser; configure using TargetRubyVersion parameter, under AllCops)
end
^^^
1 file inspected, 2 offenses detected, 1 offense corrected
This PR fixes the following incorrect auto-correct for `Style/StructInheritance`
incorrect auto-correct for `Style/StructInheritance` when there is a comment
before class declaration.
```console
% cat example.rb
# comment
class Foo < Struct.new(:foo)
end
% bundle exec rubocop --only Style/StructInheritance -a
(snip)
Offenses:
example.rb:2:13: C: [Corrected] Style/StructInheritance: Don't extend an
instance initialized by Struct.new. Use a block to customize the struct.
class Foo < Struct.new(:foo)
^^^^^^^^^^^^^^^^
1 file inspected, 1 offense detected, 1 offense corrected
% cat example.rb
# commentFoo = Struct.new(:foo) do
end
```
This issue has been reported on rubocop-jp. (Japanese)
rubocop/rubocop-jp#61
環境
入力
実行
結果
補足
Hoge = Struct.new(:foo, :bar) do
の前に改行が必要ですが、改行コードがないのでHoge = Struct.new(:foo, :bar) do
がコメントの一部になってしまいます。The text was updated successfully, but these errors were encountered: