Cop for deterministic regexp on String#split#190
Conversation
|
I came up with a cop name |
|
Hello @koic! I applied all the required changes! I also don't have a better name than that 😅 but I like yours better. |
|
Testing this out against my codebase it looks like it's matching on this code: filter_parts = filter.split(/\./)This is being autocorrected to: filter_parts = filter.split('\.')This should be autocorrected to: filter_parts = filter.split('.') |
|
@tas50 I couldn't reproduce your issue. Your case is not considered an offense and it will not be auto-corrected. I also added a test case for it: https://github.com/rubocop-hq/rubocop-performance/pull/190/files#diff-bbc2461ef6fae3f431f7a7dbc2b3852a9bcf830680f583806a7429e2e414a830R14-R17 |
c208adf to
122f40d
Compare
|
Can you add the changelog entry to CHANGELOG.md and squash your commits into one? |
|
@koic hello! sorry for taking long to respond to you! I've applied the necessary changes. Please review |
a57f30f to
1ae6d24
Compare
|
Sorry, @koic! I've missed this: It is done now! |
Apply reviews Remove wrong configuration Fix auto-correction with escaping chars Ignore string special chars Guarantee string will behave the same when using special chars Apply review Add changelog Update docs/modules/ROOT/pages/cops_performance.adoc Co-authored-by: Tim Smith <tsmith84@gmail.com>
618d856 to
5f3d528
Compare
|
@mfbmina I'm happy with it. |
|
It looks good overall. I will tweak the changelog after merging. Thank you for implementing the useful cop! |
|
Thank you guys 😄 |
…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") ```
…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") ```
…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") ```
…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") ```
* Update rubocop from 1.12.1 to [1.13.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.13.0) * Update rubocop-performance from 1.9.2 to [1.11.1](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.11.1) * Enabled the following rules: * [`Performance/RedundantSplitRegexpArgument`](rubocop/rubocop-performance#190) * [`Style/IfWithBooleanLiteralBranches`](rubocop/rubocop#9396) * [`Lint/TripleQuotes`](rubocop/rubocop#9402) * [`Lint/SymbolConversion`](rubocop/rubocop#9362) * [`Lint/OrAssignmentToConstant`](rubocop/rubocop#9363) * [`Lint/NumberedParameterAssignment`](rubocop/rubocop#9326) * [`Style/HashConversion`](rubocop/rubocop#9478) * [`Gemspec/DateAssignment`](rubocop/rubocop#9496) * [`Style/StringChars`](rubocop/rubocop#9615)
This feature was requested here: https://github.com/rubocop-hq/rubocop/issues/8979
Sometimes, a regexp is used when a simple string could solve the problem, this PR looks for that when calling
.split.Before submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.