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

[Fix #7759] Fix an error for Layout/LineLength #7760

Merged
merged 1 commit into from Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
* [#7709](https://github.com/rubocop-hq/rubocop/issues/7709): Fix correction of `Style/RedundantCondition` when the else branch contains a range. ([@rrosenblum][])
* [#7682](https://github.com/rubocop-hq/rubocop/issues/7682): Fix `Style/InverseMethods` autofix leaving parenthesis. ([@tejasbubane][])
* [#7745](https://github.com/rubocop-hq/rubocop/issues/7745): Suppress a pending cop warnings when pending cop's department is disabled. ([@koic][])
* [#7759](https://github.com/rubocop-hq/rubocop/issues/7759): Fix an error for `Layout/LineLength` cop when using lambda syntax that argument is not enclosed in parentheses. ([@koic][])

## 0.80.0 (2020-02-18)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/line_length.rb
Expand Up @@ -131,7 +131,7 @@ def check_for_breakable_block(block_node)
end

def breakable_block_range(block_node)
if block_node.arguments?
if block_node.arguments? && !block_node.lambda?
block_node.arguments.loc.end
else
block_node.loc.begin
Expand Down
30 changes: 30 additions & 0 deletions spec/rubocop/cop/layout/line_length_spec.rb
Expand Up @@ -791,6 +791,36 @@ def baz(bar)
RUBY
end
end

context 'lambda syntax' do
context 'when argument is enclosed in parentheses' do
it 'registers an offense and corrects' do
expect_offense(<<~RUBY)
->(x) { fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Line is too long. [70/40]
RUBY

expect_correction(<<~RUBY)
->(x) {
fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo }
RUBY
end
end

context 'when argument is not enclosed in parentheses' do
it 'registers an offense and corrects' do
expect_offense(<<~RUBY)
-> x { foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Line is too long. [70/40]
RUBY

expect_correction(<<~RUBY)
-> x {
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo }
RUBY
end
end
end
end

context 'semicolon' do
Expand Down