sindresorhus/eslint-plugin-unicorn

`prefer-array-some`: Trigger through variable assignment

クローズ

#996 opened on 2021/01/05

 (2 件のコメント) (3 件のリアクション) (0 人の担当者)JavaScript (468 件のフォーク)user submission
enhancementhelp wanted

Repository metrics

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

説明

The prefer-array-some rule is not triggered when the .find() result is assigned to a variable:

const arr = [];
const hasFoo = arr.find(val => val === 'foo');
if (hasFoo) console.log('foo');

Obviously it shouldn't be triggered if hasFoo were to be used elsewhere for anything other than element existence checks, but if that's all it's used for, I'd expect it to trigger the rule.

Variable assignment of these element existence checks is useful when the predicate function is long, but also to generally make code read more prose-like.

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