Skip to content

Commit

Permalink
Make Style/TrailingBodyOnClass aware of singleton class
Browse files Browse the repository at this point in the history
This PR makes `Style/TrailingBodyOnClass` aware of singleton class.
So, singleton class can be handled in the same way as class.
  • Loading branch information
koic committed Apr 7, 2023
1 parent f1a7b6a commit 2c1f115
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11775](https://github.com/rubocop/rubocop/pull/11775): Make `Style/TrailingBodyOnClass` aware of singleton class. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/trailing_body_on_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def on_class(node)
)
end
end
alias on_sclass on_class
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/rubocop/cop/style/trailing_body_on_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ def bar; end
RUBY
end

it 'registers an offense when body trails after singleton class definition' do
expect_offense(<<~RUBY)
class << self; body
^^^^ Place the first line of class body on its own line.
end
class << self; def bar; end
^^^^^^^^^^^^ Place the first line of class body on its own line.
end
RUBY

expect_correction(<<~RUBY)
class << self#{trailing_whitespace}
body
end
class << self#{trailing_whitespace}
def bar; end
end
RUBY
end

it 'registers offense with multi-line class' do
expect_offense(<<~RUBY)
class Foo; body
Expand Down

0 comments on commit 2c1f115

Please sign in to comment.