Utility libraries rules
no-default-utility-imports
Section titled “no-default-utility-imports”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.
What to do
Section titled “What to do”Import the functions you use by name, or import each lodash or validator method from its own path.
Example
Section titled “Example”import _ from "lodash"; reports method. Write import map from "lodash/map";.
no-shallow-clone-mutation
Section titled “no-shallow-clone-mutation”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.
What to do
Section titled “What to do”Copy with structuredClone() or _.cloneDeep() when the copy needs its own nested values, or replace the parent object before the write.
Example
Section titled “Example”const copy = _.clone(settings); copy.theme.color = "red"; reports shared.
prefer-native-axios
Section titled “prefer-native-axios”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.
What to do
Section titled “What to do”Use Promise.all() for axios.all(), array destructuring for axios.spread(), and an AbortController signal for cancellation.
Example
Section titled “Example”axios.all([first, second]) reports helper. Write Promise.all([first, second]).
prefer-native-jquery
Section titled “prefer-native-jquery”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.
What to do
Section titled “What to do”Call the native function: Array.isArray(), JSON.parse(), Date.now(), String.prototype.trim(), or Array.prototype.indexOf().
Example
Section titled “Example”$.isArray(rows) reports deprecated. Write Array.isArray(rows).
prefer-native-lodash
Section titled “prefer-native-lodash”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.
What to do
Section titled “What to do”Call the native method. Check nullish values first, because the library accepts them.
Example
Section titled “Example”_.isArray(value) reports direct. Write Array.isArray(value).
require-memoize-key
Section titled “require-memoize-key”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.
What to do
Section titled “What to do”Pass a second argument that builds the cache key from every argument that changes the result.
Example
Section titled “Example”memoize((price, rate) => price * rate) reports keyFunction. Write memoize((price, rate) => price * rate, (price, rate) => `${price}:${rate}`).