sindresorhus/eslint-plugin-unicorn

`explicit-length-check`: ignore variables with non-array properties?

已关闭

#1,266 创建于 2021年5月12日

 (1 条评论) (1 个反应) (0 位负责人)JavaScript (468 个派生)user submission
bughelp wantedtypes

仓库指标

星标
 (5,022 个星标)
PR 合并指标
 (平均合并 1天 16小时) (30 天内合并 399 个 PR)

描述

if (
  dimensions.width &&
  dimensions.height &&
  dimensions.length // violation reported by unicorn/explicit-length-check
) { }

In this example, packagingData.dimensions is an object, and length could be a string.

As a heuristic to avoid false positives with detecting length or size on variables that are not actually arrays, could we ignore variables that have non-array properties? For example, an array does not have a width property, so if we see that used, we would assume dimensions is not an array, and ignore it.

贡献者指南