Skip to content

Commit

Permalink
[Fix rubocop#9523] Fix an error for Style/TrailingMethodEndStatement
Browse files Browse the repository at this point in the history
Fixes rubocop#9523.

This PR fixes an error for `Style/TrailingMethodEndStatement`
when endless method definition signature and body are on different lines.
  • Loading branch information
koic authored and bbatsov committed Feb 17, 2021
1 parent 787f8b8 commit 8bd7679
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
@@ -0,0 +1 @@
* [#9523](https://github.com/rubocop-hq/rubocop/issues/9523): Fix an error for `Style/TrailingMethodEndStatement` when endless method definition signature and body are on different lines. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/trailing_method_end_statement.rb
Expand Up @@ -40,7 +40,7 @@ class TrailingMethodEndStatement < Base
'its own line.'

def on_def(node)
return unless trailing_end?(node)
return if node.endless? || !trailing_end?(node)

add_offense(node.loc.end) do |corrector|
corrector.insert_before(
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/style/trailing_method_end_statement_spec.rb
Expand Up @@ -122,4 +122,20 @@ def another_method
end
RUBY
end

This comment has been minimized.

Copy link
@jsx150

jsx150 Feb 28, 2021

Hi Ruby rudy hear.1


context 'when Ruby 3.0 or higher', :ruby30 do
it 'does not register an offense when using endless method definition' do
expect_no_offenses(<<~RUBY)
def foo = bar
RUBY
end

it 'does not register an offense when endless method definition signature and body are ' \
'on different lines' do
expect_no_offenses(<<~RUBY)
def foo =
bar
RUBY
end
end
end

0 comments on commit 8bd7679

Please sign in to comment.