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
A case not handled by no-for-loop
#295
Comments
It is not. |
@IssueHunt has funded $40.00 to this issue.
|
I took a quick look at this and think this should be a separate rule that auto-fixes this shape into a normal for loop. Original: for (let i = 0, j = arr.length; i < j; i += 1) {
const element = arr[i];
console.log(element);
} Fixed: for (let i = 0; i < arr.length; i += 1) {
const element = arr[i];
console.log(element);
} Original: for (let i = 0, j = arr.length; i < j; i += 1) {
const element = arr[i];
console.log(element);
console.log(j);
} Fixed: for (let i = 0; i < arr.length; i += 1) {
const element = arr[i];
console.log(element);
console.log(arr.length);
} |
@MrHen Are we sure we can depend on the fixer output of other rules (the order of fixes)? I don't fully remember how fixers work. How about a rule named Personally, I don't want for-loops at all, so I would prefer just keeping the logic in this rule, as I don't really see the point of simplifying a for-loop if it can just be removed altogether. |
@sindresorhus The main reason I'd want this check in a different rule is because it would make the rule logic and test cases easier to understand and maintain. The end result will be: for (let i = 0, j = arr.length; i < j; i += 1) {
const element = arr[i];
console.log(element);
} Will be auto-fixed to: for (let i = 0; i < arr.length; i += 1) {
const element = arr[i];
console.log(element);
} Which is then auto fixed to: for (const [i, element] of arr) {
console.log(element);
} The end result will be exactly what you want. |
Alright, let's do it as a separate rule then. |
I can take this one! |
Update: #489 didn't fix this |
What about restricting the scope of this proposed new separate rule to only address array length caching ?
|
If anyone wants to work on this, please continue where #492 left off. |
no-for-loop
should report on this but it does not.This slightly unusual pattern is used all over the place in
eslint-plugin-react
.This issue is a subtask of #250.
IssueHunt Summary
Sponsors (Total: $40.00)
Become a sponsor now!
Or submit a pull request to get the deposits!
Tips
The text was updated successfully, but these errors were encountered: