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
Mark Style/SlicingWithRange
as safe
#8890
Mark Style/SlicingWithRange
as safe
#8890
Conversation
9e669d8
to
69909ec
Compare
Let's also add a note in the cop description explaning why the auto-correct is unsafe, so it's clearer to the end users. |
Style/SlicingWithRange
as unsafe auto-correctionStyle/SlicingWithRange
as safe
69909ec
to
bd5a38a
Compare
Ah, I misunderstood it as @zverok Please let me know if there is any reason why this cop is unsafe. |
bd5a38a
to
389c14b
Compare
@@ -4116,8 +4116,7 @@ Style/SingleLineMethods: | |||
Style/SlicingWithRange: | |||
Description: 'Checks array slicing is done with endless ranges when suitable.' | |||
Enabled: pending | |||
VersionAdded: '0.83' | |||
Safe: false | |||
VersionAdded: '0.94' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be VersionChanged
.
Follow rubocop#7921. This PR marks `Style/SlicingWithRange` as safe.
389c14b
to
89cd0e3
Compare
I don't believe this cop can be safe. Equivalence of h = {-3..-1 => 'foo', 0..5 => 'bar'}
h[-3..-1] # => "foo"
h[-3..] # => nil
sum = proc { |ary| ary.sum }
sum[-3..-1] # => -6
sum[-3..] # Hangs forever While both examples are artificial, they demonstrate the principle: in general, |
Ah, I was missing on that point of view. I think it's possible to add an unsafe reason to the documentation. I'll close this PR for now. @zverok Thank you for your explanation! |
Follow #7921.
This PR marks
Style/SlicingWithRange
as safe.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.