How about forcing the looped expression to be one of:
- a variable (
x
)- a property access (
x.a.b
)- a single function call with no arguments (
x()
,x.a.b()
)- one of built-in function calls commonly used for iteration (
Object.keys(x)
/Object.values(x)
/Object.entries(x)
)Otherwise force the user to define a variable before the loop (may be possible to auto-fix, the iteratee variable name could be the pluralized name of the element variable).
Originally from #846 (comment)
for (const x of xs.filter(x => shouldKeep(x))) {
console.log(x)
}
const filteredXs = xs.filter(x => shouldKeep(x))
for (const x of filteredXs) {
console.log(x)
}
for (const x of Object.values(xs)) {
console.log(x)
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too