-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 false positive for Style/TrailingComma cop #1956
Fix false positive for Style/TrailingComma cop #1956
Conversation
after_last_item = Parser::Source::Range.new(sb, begin_pos, end_pos) | ||
|
||
return if heredoc?(after_last_item.source) | ||
|
||
# Stop Execution if data structure constructed with brackets is empty | ||
return if items.first.children.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern is that, based on this implementation, Foo.new({}, \n ... 5)
would pass this cop, and perhaps it should not?
👍 |
@@ -46,7 +46,6 @@ def on_send(node) | |||
# It's impossible for a method call without parentheses to have | |||
# a trailing comma. | |||
return unless brackets?(node) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this blank line?
@mattjmcnaughton It looks like this PR has picked up some merge conflicts. Can you please rebase from the |
@mattjmcnaughton Ping |
@mattjmcnaughton Looks good. Just remove the |
#1955 The Style/TrailingComma cop reported false positives. Specifically, code such as `Foo.new({})` and `Foo.new([])` caused false positives when EnforcedStyleForMultiline was set to 'comma'. The `multiline?` method, in trailing_comma.rb interpreting the previous methods as multiline caused the bug. Setting the EnforcedStyleForMultiline options for the Style/TrailingComma cop to 'comma' or 'consistent_comma' means multiline method invocations are expected to have trailing commas after their final argument. Because `Foo.new({})` is a method invocation, and mistakenly considered to be multiline, the Style/TrailingComma cop believed it should be written as `Foo.new({},)`. This is not the intended behavior of the cop. * Add checks to the `multiline?` behavior so methods will not incorrectly be considered multiline. * Add tests related to the original bugs reported.
Updated 😄 |
😄 |
…trailing-comma-cop Fix false positive for Style/TrailingComma cop
👍 |
Fixes #1955.
Adds an extra check to the
multiline?
method of thetrailing_comma.rb
method to ensure expressions likeFoo.new({})
are not considered multiline.