Skip to content

Latest commit

 

History

History
40 lines (22 loc) · 893 Bytes

prefer-is-empty.md

File metadata and controls

40 lines (22 loc) · 893 Bytes

Prefer _.isEmpty

When checking if a collection is empty or no, it is more concise to use _.isEmpty instead.

Rule Details

This rule takes no arguments.

The following patterns are considered warnings:

const myLengthEqualZero = myVar.length === 0;

const myLengthEqualZero = myVar.length > 0;

const myLengthEqualZero = myVar.length > 0 ? "first" : "second";

const myLengthEqualZero = myVar.myProp.mySecondProp.length === 0;

const myLengthEqualZero = myVar.myProp.mySecondProp.length > 0;

The following patterns are not considered warnings:

const myLengthEqualZero = !isEmpty(myVar);

const myLengthEqualZero = isEmpty(myVar);

const myLengthEqualZero = myVar.length == 0;

const myLengthEqualZero = myVar.length;

const myLengthEqualZero = myVar;

When Not To Use It

If you do not want to enforce using _.isEmpty, and prefer using native checks instead.