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 false positive for Style/TrailingComma cop #1956

Merged
merged 1 commit into from
Jun 16, 2015
Merged

Fix false positive for Style/TrailingComma cop #1956

merged 1 commit into from
Jun 16, 2015

Conversation

mattjmcnaughton
Copy link
Contributor

Fixes #1955.

Adds an extra check to the multiline? method of the trailing_comma.rb method to ensure expressions like Foo.new({}) are not considered multiline.

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?
Copy link
Contributor Author

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?

@sferik
Copy link
Contributor

sferik commented Jun 9, 2015

👍

@@ -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)

Copy link
Collaborator

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?

@sferik
Copy link
Contributor

sferik commented Jun 10, 2015

@mattjmcnaughton It looks like this PR has picked up some merge conflicts. Can you please rebase from the master branch?

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 14, 2015

@mattjmcnaughton Ping

@mattjmcnaughton
Copy link
Contributor Author

@bbatsov @sferik sorry for the delay! i'll have some time tonight and will rebase, add back the needlessly deleted blank line, and also add a test for another error brought up in the issue thread.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 15, 2015

@mattjmcnaughton Looks good. Just remove the . from the commit message's title to match our commit message style.

#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.
@mattjmcnaughton
Copy link
Contributor Author

Updated 😄

@sferik
Copy link
Contributor

sferik commented Jun 16, 2015

😄

bbatsov added a commit that referenced this pull request Jun 16, 2015
…trailing-comma-cop

Fix false positive for Style/TrailingComma cop
@bbatsov bbatsov merged commit f8fbd50 into rubocop:master Jun 16, 2015
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 16, 2015

👍

sferik added a commit to tweetstream/tweetstream that referenced this pull request Jun 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants