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 #3032] Autocorrect predicates without space before args - e.g. is_a?Integer #3033

Merged
merged 1 commit into from
Apr 13, 2016
Merged

Conversation

graemeboy
Copy link
Contributor

@graemeboy graemeboy commented Apr 12, 2016

Summary of problem:

Using rubocop autocorrect on the following lines of code:

false or 'a'.is_a?String
=> false || 'a'.is_a?(tring)

'1'.is_a?Integer or 1.is_a?Integer
=> '1'.is_a?(nteger) || 1.is_a?(nteger)

PR adds six example cases to the test specs, and some code that makes all pass.

@@ -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]/
Copy link
Contributor

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]/.

@rrosenblum
Copy link
Contributor

This is an interesting issue. I guess this could happen for any method that ends in ? and then does not use a space. I think the regex may need to be tweaked to look for any non white space character.

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.

@graemeboy
Copy link
Contributor Author

♻️

@@ -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]/
Copy link
Collaborator

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.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 13, 2016

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][])
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

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.

@graemeboy
Copy link
Contributor Author

@bbatsov ♻️

@bbatsov bbatsov merged commit 96728e4 into rubocop:master Apr 13, 2016
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 13, 2016

👍

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.

None yet

3 participants