sindresorhus/eslint-plugin-unicorn

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

Fermée

#1 266 ouverte le 12 mai 2021

 (1 commentaire) (1 réaction) (0 personne assignée)JavaScript (468 forks)user submission
bughelp wantedtypes

Métriques du dépôt

Stars
 (5 022 étoiles)
Métriques de merge PR
 (Merge moyen 1j 16h) (399 PRs mergées en 30 j)

Description

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.

Guide contributeur