sindresorhus/eslint-plugin-unicorn

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

已關閉

#996 建立於 2021年1月5日

 (2 則留言) (3 個反應) (0 位負責人)JavaScript (468 個分叉)user submission
enhancementhelp wanted

倉庫指標

星標
 (5,022 顆星)
PR 合併指標
 (平均合併 4小時 30分鐘) (30 天內合併 26 個 PR)

描述

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.

貢獻者指南