Skip to content

unicorn/prefer-structured-clone Style ​

💡 A suggestion is available for this rule.

What it does ​

Prefer using structuredClone to create a deep clone.

Why is this bad? ​

structuredClone is the modern way to create a deep clone of a value.

Examples ​

Examples of incorrect code for this rule:

js
const clone = JSON.parse(JSON.stringify(foo));

const clone = _.cloneDeep(foo);

Examples of correct code for this rule:

js
const clone = structuredClone(foo);

How to use ​

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny unicorn/prefer-structured-clone
json
{
  "rules": {
    "unicorn/prefer-structured-clone": "error"
  }
}

References ​

Released under the MIT License.