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

RedundantSplitRegexpArgument false positive when splitting by one space #222

Closed
dparpyani opened this issue Mar 13, 2021 · 1 comment · Fixed by #223
Closed

RedundantSplitRegexpArgument false positive when splitting by one space #222

dparpyani opened this issue Mar 13, 2021 · 1 comment · Fixed by #223
Labels
bug Something isn't working

Comments

@dparpyani
Copy link

The check triggers on the following line of code

parts = data.split(/ /) # split by exactly one space

and suggests replacing with a string

C: Performance/RedundantSplitRegexpArgument: Use string as argument instead of regexp.
    parts = data.split(/ /) # split by exactly one space

But note that those are not the same:

2.7.2 :001 > 'hello   world'.split(/ /)
 => ["hello", "", "", "world"] 
2.7.2 :002 > 'hello   world'.split(' ')
 => ["hello", "world"] 

Expected behavior

Performance/RedundantSplitRegexpArgument should not have triggered here

Actual behavior

Rubocop triggers Performance/RedundantSplitRegexpArgument

Steps to reproduce the problem

Run rubocop on example code above

RuboCop version

$ be rubocop -V
1.2.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-darwin19)
  - rubocop-performance 1.10.1
  - rubocop-rails 2.8.1
  - rubocop-rspec 2.0.0
@koic koic added the bug Something isn't working label Mar 13, 2021
koic added a commit to koic/rubocop-performance that referenced this issue Mar 13, 2021
…tRegexpArgument`

Fixes rubocop#222.

This PR fixes a false positive for `Performance/RedundantSplitRegexpArgument`
when `split` method argument is exactly one spece regexp `/ /`.
koic added a commit to koic/rubocop-performance that referenced this issue Mar 13, 2021
…tRegexpArgument`

Fixes rubocop#222.

This PR fixes a false positive for `Performance/RedundantSplitRegexpArgument`
when `split` method argument is exactly one spece regexp `/ /`.
koic added a commit to koic/rubocop-performance that referenced this issue Mar 13, 2021
…tRegexpArgument`

Fixes rubocop#222.

This PR fixes a false positive for `Performance/RedundantSplitRegexpArgument`
when `split` method argument is exactly one spece regexp `/ /`.
koic added a commit to koic/rubocop-performance that referenced this issue Mar 20, 2021
…tRegexpArgument`

Fixes rubocop#222.

This PR fixes a false positive for `Performance/RedundantSplitRegexpArgument`
when `split` method argument is exactly one spece regexp `/ /`.
@koic koic closed this as completed in #223 Mar 22, 2021
koic added a commit that referenced this issue Mar 22, 2021
…lit_regexp_argument

[Fix #222] Fix a false positive for `Performance/RedundantSplitRegexpArgument`
@dparpyani
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants