sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-unused-return-value`

クローズ

#741 opened on 2020/05/22

 (11 件のコメント) (25 件のリアクション) (0 人の担当者)JavaScript (468 件のフォーク)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 個のスター)
PR merge metrics
 (平均マージ 4h 30m) (30d で 26 merged PRs)

説明

Details here: https://github.com/eslint/eslint/issues/12980

The idea is that many builtin functions return values and if those return values are not used, the code is essentially a noop and can be removed.

The discussion got stale because it seems hard for a plugin to correctly judge the type of a variable which is essential for a rule like this so it may require Typescript to really be useful. Also there was the problem of getters which would trigger false positives but I generally see getters as a obscure feature that should not be used.

Fail

const arr = [{name: 'eslint'}];
arr.map(item => item.name); // error: Unused Array.prototype.map return value
console.log(arr);

Pass

const arr = [{name: 'eslint'}];
console.log(arr);

Fail

let i = 0;
const arr = [1,2,3];
arr.map((item) => {  // error: Unused Array.prototype.map return value
  i += 1;
});

Pass

let i = 0;
const arr = [1,2,3];
arr.forEach((item) => {
  i += 1;
});

コントリビューターガイド