Skip to content

Utility libraries rules

Reports a default import of lodash, lodash-es, rxjs, rambda, or validator when the version range in package.json allows named or per-method imports.

On in the all config.

A default import pulls the whole library into the bundle, even when the code uses one function.

Import the functions you use by name, or import each lodash or validator method from its own path.

import _ from "lodash"; reports method. Write import map from "lodash/map";.

Reports a write or a mutating call, such as push, on a nested property two or more members deep of a variable whose value comes from the shallow clone of lodash, lodash-es, or underscore.

On in the recommended and all configs.

A shallow clone shares its nested objects with the original, so a change to a nested property changes the original value too.

Copy with structuredClone() or _.cloneDeep() when the copy needs its own nested values, or replace the parent object before the write.

const copy = _.clone(settings); copy.theme.color = "red"; reports shared.

Reports the deprecated Axios helpers axios.all() and axios.spread(), each use of axios.CancelToken, and a cancelToken option in the config argument of an Axios request.

On in the recommended and all configs.

Axios deprecated these helpers and CancelToken. The language and the platform give the same behavior without them.

Use Promise.all() for axios.all(), array destructuring for axios.spread(), and an AbortController signal for cancellation.

axios.all([first, second]) reports helper. Write Promise.all([first, second]).

Reports isArray, parseJSON, now, trim, and inArray called on jQuery: the $ or jQuery global, or a binding imported or required from jquery.

On in the recommended and all configs.

The language now has each of these functions, so the jQuery copies only keep the dependency alive, and jQuery has deprecated four of them.

Call the native function: Array.isArray(), JSON.parse(), Date.now(), String.prototype.trim(), or Array.prototype.indexOf().

$.isArray(rows) reports deprecated. Write Array.isArray(rows).

Reports a call of a lodash, lodash-es, or Underscore.js method that the configured ECMAScript version provides, such as isArray or uniq, and of map or filter on a value that the source or its types show is an array.

On in the all config.

A native method needs no dependency, and every reader knows it.

Call the native method. Check nullish values first, because the library accepts them.

_.isArray(value) reports direct. Write Array.isArray(value).

Reports a memoize call of lodash, lodash-es, or underscore without a key function, when the memoized function takes two or more parameters or a rest parameter.

On in the recommended and all configs.

Without a key function, memoize caches by the first argument alone, so calls that differ only in a later argument return the first cached result.

Pass a second argument that builds the cache key from every argument that changes the result.

memoize((price, rate) => price * rate) reports keyFunction. Write memoize((price, rate) => price * rate, (price, rate) => `${price}:${rate}`).