Skip to content

TypeScript · maintainability

prefer-native-random-uuid

eslint:prefer-native-random-uuid

Prefer `globalThis.crypto.randomUUID()` over resolved zero-argument UUID v4 bindings from the `uuid` package.

Default
error
Fix
suggestion
Languages
typescript

Why

The platform implementation avoids an unnecessary dependency for standard random UUID generation.

Fix

Call `globalThis.crypto.randomUUID()` and remove the unused `uuid` v4 import when possible.

Before / after

Executed by this rule’s unit tests.

Before

Do not call uuid v4 without options

src/id.ts · focus
import { v4 } from 'uuid'; const id = v4();

After

Use the platform UUID generator

src/id.ts · focus
const id = globalThis.crypto.randomUUID();

Limits

  • Only resolved zero-argument UUID v4 calls are reported; customized and other UUID versions are excluded.

Message IDs

preferNativereplaceWithNative