Rule proposal: warn against unused array iterator method return values

Author: PSeitzCreated Sep 7, 2020Updated Sep 17, 2026
Labelspackage: eslint-pluginenhancement: new plugin ruleaccepting prs

There are some function calls where the return value should not be ignored (like some, indexOf, concat, map, etc.) or the function call doesn't make sense. Would be nice to cover this with the no-unused-expressions lint. I did test the snippets below on current master, they both don't fail.

typescript
function foo(arr) {
  if (arr) {
    arr.some(el == 'myval'); // should be: return arr.some(el == 'myval');
  }
  return undefined;
}
typescript
function foo(arr) {
  var merged = arr.reduce(function (a, b) {
    a.concat(b);  // should be: return a.concat(b);
  });
}

Source: typescript-eslint/typescript-eslint