forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…range Fixes rubocop#12233. This PR makes `Style/SlicingWithRange` aware of redundant and beginless range. Ruby 2.7 introduced beginless ranges. But, unlike the somewhat obscure `-1` in `ary[1..-1]`, the `0` in `ary[0..42]` is clear as a starting point. In fact, changing it to `ary[..42]` could potentially make it less readable. Therefore, `ary[0..42]` should respect the original programmer's intent. On the other hand, `ary[nil..42]` could be replaced with `ary[..42]`. Similarly, `ary[1..nil]` could be replaced with `ary[1..]`. Moreover, `[0..-1]` in `ary[0..-1]` is redundant and simply synonymous with `ary`. This PR has also made adjustments to detect this case. While this is a byproduct of supporting beginless and endless ranges, I think including this change in `Style/SlicingWithRange` cop may be suitable and not feel out of place.
- Loading branch information
Showing
4 changed files
with
154 additions
and
15 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog/change_make_style_slicing_with_range_aware_of_beginless_range.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#12233](https://github.com/rubocop/rubocop/issues/12233): Make `Style/SlicingWithRange` aware of redundant and beginless range. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters