Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 643 Bytes

prefer-find.md

File metadata and controls

44 lines (32 loc) · 643 Bytes

Prefer find

When using _.filter and accessing the first or last result, you should probably use _.find or _.findLast, respectively.

Rule Details

This rule takes no arguments.

The following patterns are considered warnings:

const x = _.filter(a, f)[0];
const x = _.head(_.filter(a, f));
const x = _(a)
            .filter(f)
            .head()
const x = _.last(_.filter(a, f));
const x = _.head(_.reject(a, f));

The following patterns are not considered warnings:

const x = _.filter(a, f);
const x = _.filter(a, f)[3];
const x = _.find(a, f);