Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

eslint-plugin-unicorn is an ESLint plugin with over 100 opinionated rules. It enforces modern JavaScript patterns, prevents common mistakes, and promotes consistent code — with auto-fix support for most rules. You might also want to check out XO, a JavaScript linter that includes eslint-plugin-unicorn out of the box.

Key features

100+ rules

Broad coverage of JavaScript best practices, from naming conventions to modern API enforcement.

Auto-fixable

Most rules support --fix for automatic correction and editor suggestions for the rest.

Flat config support

Built for ESLint’s modern flat config system (eslint.config.js). Legacy .eslintrc is not supported.

ESM-first

Written as an ES module. You import it — not require() it.

Preset configs

Three ready-made configs: recommended, all, and unopinionated. Use one or configure rules individually.

Editor suggestions

Rules that can’t be auto-fixed provide inline editor suggestions for guided manual fixes.

Requirements

eslint-plugin-unicorn requires ESLint >=9.38.0, ESLint’s flat config format, and Node.js ^20.10.0 || >=21.0.0. Legacy .eslintrc configuration files are not supported.

How it differs from other ESLint plugins

Most ESLint plugins target a single domain — React, imports, accessibility, and so on. eslint-plugin-unicorn covers a wide range of general JavaScript best practices in one package:
  • Modern APIs — rules prefer Array#at(), structuredClone(), node: protocol imports, and other contemporary built-ins over legacy equivalents.
  • Consistency — rules enforce uniform style for things like filename casing, error naming, template literals, and numeric separators.
  • Bug prevention — rules catch subtle mistakes like passing a function reference directly to an iterator method, using await in non-async contexts, or misusing Promise methods.
  • Code clarity — rules flag patterns that are hard to read, such as nested ternaries, unreadable array destructuring, or implicit undefined returns.

Rule categories

eslint-plugin-unicorn rules fall broadly into these themes:
CategoryExamples
Prefer modern APIsprefer-at, prefer-node-protocol, prefer-structured-clone
Code style & consistencyfilename-case, numeric-separators-style, number-literal-case
Best practicesno-array-reduce, no-await-expression-member, throw-new-error
Bug preventionno-invalid-fetch-options, no-accessor-recursion, no-thenable
ESM & modulesprefer-module, prefer-export-from, prefer-import-meta-properties

Next steps

Installation

Install the plugin and set up your project.

Configuration

Use a preset config or configure individual rules.

Build docs developers (and LLMs) love