After the SonarQube instance I use was updated recently, I got a lot of flags for the new rule S1515. All the code looked like this:
const tasks = [];
while(collection.length > 0) {
const batch = collection.splice(0, batchSize);
tasks.push(new Task(() => doSomethingWith(batch)));
}
Smart static analysis could tell us that the function defined inside the Task
constructor does not access any state outside the loop, and is therefore safe. Is this possible with the current JS/TS engine?