close

prefer-structured-clone

Added in v0.9.4

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-structured-clone': 'error',
    },
  },
]);

Prefer structuredClone when creating deep clones.

The rule recognizes:

  • JSON.parse(JSON.stringify(value))
  • _.cloneDeep(value)
  • lodash.cloneDeep(value)
  • additional configured function paths

The rule reports suggestions only; it does not autofix automatically.

// Incorrect
const clone = JSON.parse(JSON.stringify(value));
const other = _.cloneDeep(value);

// Correct
const clone = structuredClone(value);

Custom functions can be configured through the functions option.

This port follows eslint-plugin-unicorn v75.0.0 and preserves authored parentheses, comments, and trailing commas in suggestions.