-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #3032] Autocorrect predicates without space before args - e.g. is_a?Integer #3033
Conversation
@@ -119,7 +119,9 @@ def correctable_send?(node) | |||
def whitespace_before_arg(node) | |||
sb = node.source_range.source_buffer | |||
begin_paren = node.loc.selector.end_pos | |||
Parser::Source::Range.new(sb, begin_paren, begin_paren + 1) | |||
end_paren = begin_paren | |||
end_paren += 1 unless node.source_range.source.to_s =~ /\?[A-Za-z]/ |
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.
This can be simplified to end_paren += 1 unless node.source =~ /\?[A-Za-z]/
.
This is an interesting issue. I guess this could happen for any method that ends in I think that this would fall into your same error condition, but I don't think that it would be caught by the current regex. @foo = Integer
bar.is_a?@foo There are a few test failures for line lengths in the tests being too long. Aside from a few small tweaks, it looks pretty good to me. |
♻️ |
@@ -119,7 +119,9 @@ def correctable_send?(node) | |||
def whitespace_before_arg(node) | |||
sb = node.source_range.source_buffer | |||
begin_paren = node.loc.selector.end_pos | |||
Parser::Source::Range.new(sb, begin_paren, begin_paren + 1) | |||
end_paren = begin_paren | |||
end_paren += 1 unless node.source =~ /\?[!\S]/ |
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.
I'd add some comment here as it's not obvious what you're checking for.
You should also add a changelog entry mentioning this fix. |
@@ -10,7 +10,7 @@ | |||
* [#2993](https://github.com/bbatsov/rubocop/pull/2993): `Style/SpaceAfterColon` now checks optional keyword arguments. ([@owst][]) | |||
|
|||
### Bug fixes | |||
|
|||
* [#3033](https://github.com/bbatsov/rubocop/pull/3033): Fix autocorrecting parentheses for predicate methods without space before args. ([@graemeboy][]) |
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.
The PR says this fixes #3032.
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.
The PR itself is #3033, ha. Thanks :)
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.
I know. But we typically refer here to the bug reports.
@bbatsov ♻️ |
👍 |
Summary of problem:
Using rubocop autocorrect on the following lines of code:
PR adds six example cases to the test specs, and some code that makes all pass.