sindresorhus/eslint-plugin-unicorn

Rule proposal: No computed object property existence check

クローズ

#1,096 opened on 2021/02/05

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

Repository metrics

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

説明

If property name is a variable, this may leads to unexpected result.

Fail

if (foo[bar]) {}
if (bar in foo) {}

In these cases if bar is 'toString', 'constructor' etc, it will be true.

Pass

if (foo[bar] === true) {}
if (Object.prototype.hasOwnProperty.call(foo, bar)) {}

Problem: foo maybe an array, static check can't know.

Idea from https://github.com/prettier/prettier/pull/10256

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