forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
) ## Summary Implement [`no-ignored-enumerate-items`](https://github.com/dosisod/refurb/blob/master/refurb/checks/builtin/no_ignored_enumerate.py) as `unnecessary-enumerate` (`FURB148`). The auto-fix considers if a `start` argument is passed to the `enumerate()` function. If only the index is used, then the suggested fix is to pass the `start` value to the `range()` function. So, ```python for i, _ in enumerate(xs, 1): ... ``` becomes ```python for i in range(1, len(xs)): ... ``` If the index is ignored and only the value is ignored, and if a start value greater than zero is passed to `enumerate()`, the rule doesn't produce a suggestion. I couldn't find a unanimously accepted best way to iterate over a collection whilst skipping the first n elements. The rule still triggers, however. Related to astral-sh#1348. ## Test Plan `cargo test` --------- Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com> Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
- Loading branch information
1 parent
4c4ecee
commit 511cc25
Showing
12 changed files
with
695 additions
and
40 deletions.
There are no files selected for viewing
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,66 @@ | ||
books = ["Dune", "Foundation", "Neuromancer"] | ||
|
||
# Errors | ||
for index, _ in enumerate(books): | ||
print(index) | ||
|
||
for index, _ in enumerate(books, start=0): | ||
print(index) | ||
|
||
for index, _ in enumerate(books, 0): | ||
print(index) | ||
|
||
for index, _ in enumerate(books, start=1): | ||
print(index) | ||
|
||
for index, _ in enumerate(books, 1): | ||
print(index) | ||
|
||
for index, _ in enumerate(books, start=x): | ||
print(book) | ||
|
||
for index, _ in enumerate(books, x): | ||
print(book) | ||
|
||
for _, book in enumerate(books): | ||
print(book) | ||
|
||
for _, book in enumerate(books, start=0): | ||
print(book) | ||
|
||
for _, book in enumerate(books, 0): | ||
print(book) | ||
|
||
for _, book in enumerate(books, start=1): | ||
print(book) | ||
|
||
for _, book in enumerate(books, 1): | ||
print(book) | ||
|
||
for _, book in enumerate(books, start=x): | ||
print(book) | ||
|
||
for _, book in enumerate(books, x): | ||
print(book) | ||
|
||
for index, (_, _) in enumerate(books): | ||
print(index) | ||
|
||
for (_, _), book in enumerate(books): | ||
print(book) | ||
|
||
for(index, _)in enumerate(books): | ||
print(index) | ||
|
||
for(index), _ in enumerate(books): | ||
print(index) | ||
|
||
# OK | ||
for index, book in enumerate(books): | ||
print(index, book) | ||
|
||
for index in range(len(books)): | ||
print(index) | ||
|
||
for book in books: | ||
print(book) |
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
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
Oops, something went wrong.