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 an incorrect auto-correct for Performance/RedundantSplitRegexpArgument #209

Conversation

koic
Copy link
Member

@koic koic commented Jan 25, 2021

Follow #190.

This PR fixes the following incorrect auto-correct for Performance/RedundantSplitRegexpArgument when using consecutive special string chars.

% cat example.rb
"foo\nbar\nbaz\n".split(/\n\n/)

% bundle exec rubocop example.rb --only Performance/RedundantSplitRegexpArgument -a
Inspecting 1 file
C

Offenses:

example.rb:1:25: C: [Corrected]
Performance/RedundantSplitRegexpArgument: Use string as argument instead of regexp.
"foo\nbar\nbaz\n".split(/\n\n/)
                        ^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected

## Before

```console
% cat example.rb
"foo\nbar\nbaz\n".split("nn")

After

% cat example.rb
"foo\nbar\nbaz\n".split("\n\n")

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the fix_incorrect_autocorrect_for_redundant_split_regexp_argument branch 2 times, most recently from 5b2753e to 44289a7 Compare January 26, 2021 00:11
…gument`

Follow rubocop#190.

This PR fixes the following incorrect auto-correct for `Performance/RedundantSplitRegexpArgument`
when using consecutive special string chars.

```console
% cat example.rb
"foo\nbar\nbaz\n".split(/\n\n/)

% bundle exec rubocop example.rb --only Performance/RedundantSplitRegexpArgument -a
Inspecting 1 file
C

Offenses:

example.rb:1:25: C: [Corrected]
Performance/RedundantSplitRegexpArgument: Use string as argument instead of regexp.
"foo\nbar\nbaz\n".split(/\n\n/)
                        ^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected

## Before

```console
% cat example.rb
"foo\nbar\nbaz\n".split("nn")
```

## After

```console
% cat example.rb
"foo\nbar\nbaz\n".split("\n\n")
```
@koic koic force-pushed the fix_incorrect_autocorrect_for_redundant_split_regexp_argument branch from 44289a7 to f0464c9 Compare January 26, 2021 00:25
@koic koic merged commit 9e95dd3 into rubocop:master Jan 26, 2021
@koic koic deleted the fix_incorrect_autocorrect_for_redundant_split_regexp_argument branch January 26, 2021 17:13
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.

1 participant