Skip to main content

prefer-no-lodash-clone-deep

Detects all usages of cloneDeep from Lodash.

Rationale

Lodash's cloneDeep is a very costly operation and should be used only when it is really needed.

Examples

❌ Examples of incorrect code for this rule
import { cloneDeep } from 'lodash-es';

const clone = cloneDeep(orig);

✅ Examples of correct code for this rule
// see: https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
const clone = structuredClone(original);
type T = {
prop: string;
arr: { x: number; y: number }[];
};

const shallowClone: T = { ...orig };
const deepClone: T = { ...orig, arr: orig.arr.map((item) => ({ ...item })) };
import { cloneDeep } from './utils';

const clone = cloneDeep(orig);