-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Performance/ArraySemiInfiniteRangeSlice breaks code on Strings #197
Comments
tejasbubane
added a commit
to tejasbubane/rubocop-performance
that referenced
this issue
Nov 23, 2020
…as unsafe This cop is unsafe for string slices because string does not have `#take` and `#drop` methods Closes rubocop#197
8 tasks
Although we could change the cop to skip literal strings, it still remains unsafe for variables which we cannot determine statically if they are arrays or strings. I have raised a PR to mark this cop as unsafe. |
tejasbubane
added a commit
to tejasbubane/rubocop-performance
that referenced
this issue
Nov 23, 2020
This cop was created due to a mistake in microbenchmark Refer rubocop#175 (comment) Closes rubocop#197, rubocop#198
tejasbubane
added a commit
to tejasbubane/rubocop-performance
that referenced
this issue
Nov 23, 2020
This cop was created due to a mistake in microbenchmark Refer rubocop#175 (comment) Closes rubocop#197, rubocop#198
tejasbubane
added a commit
to tejasbubane/rubocop-performance
that referenced
this issue
Nov 23, 2020
This cop was created due to a mistake in microbenchmark Refer rubocop#175 (comment) Closes rubocop#197, rubocop#198
tejasbubane
added a commit
to tejasbubane/rubocop-performance
that referenced
this issue
Nov 24, 2020
This cop was created due to a mistake in microbenchmark Refer rubocop#175 (comment) Closes rubocop#197, rubocop#198
tejasbubane
added a commit
to tejasbubane/rubocop-performance
that referenced
this issue
Nov 24, 2020
This cop was created due to a mistake in microbenchmark Refer rubocop#175 (comment) Closes rubocop#197, rubocop#198
tejasbubane
added a commit
to tejasbubane/rubocop-performance
that referenced
this issue
Nov 24, 2020
This cop was created due to a mistake in microbenchmark Refer rubocop#175 (comment) Closes rubocop#197, rubocop#198
koic
added a commit
that referenced
this issue
Nov 25, 2020
[Fix #197] Disable `Performance/ArraySemiInfiniteRangeSlice` cop
Thank you for looking into this!
…On Wed, Nov 25, 2020 at 12:43 PM Koichi ITO ***@***.***> wrote:
Closed #197 <#197>
via #199 <#199>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#197 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADC7UJYXTDV7BWGBOAGD3SRROLTANCNFSM4T63I4NA>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When running rubocop-performance over our code we noticed some autocorrections broke code.
The
ArraySemiInfiniteRangeSlice
rule was being applied toString
s but there is noString#drop
method, leading to broken code.See the minimal
.rubocop.yml
andsample.rb
below for details.Note: this also applies to non-obvious strings (returned from a method) and not just string literals.
The only workaround was to disable the rule.
Expected behavior
$ rubocop -a sample.rb Inspecting 1 file . 1 file inspected, no offenses detected
And running sample.rb produces:
Actual behavior
$ rubocop -a sample.rb Inspecting 1 file C Offenses: sample.rb:3:6: C: [Corrected] Performance/ArraySemiInfiniteRangeSlice: Use drop instead of [] with semi-infinite range. puts 'an obvious string'[7..] ^^^^^^^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected
And running sample.rb produces:
$ ruby sample.rb Traceback (most recent call last): sample.rb:3:in `<main>': undefined method `drop' for "an obvious string":String (NoMethodError)
Steps to reproduce the problem
Given the
.rubocop.yml
file:And the
sample.rb
file:Run
rubocop -a
ruby sample.rb
String#drop
method.RuboCop version
The text was updated successfully, but these errors were encountered: