eslint-plugin-unicorn
raw JSON → 64.0.0 verified Sat Apr 25 auth: no javascript
An ESLint plugin providing over 100 powerful lint rules focused on best practices, consistency, and code quality. Current stable version is 64.0.0, with regular releases following semantic versioning. Key differentiators: actively maintained by Sindre Sorhus, includes many rules not found in other plugins (e.g., `better-regex`, `prefer-spread`, `no-array-for-each`), ships TypeScript types, and supports ESM-only with ESLint flat config (>=9.20.0). Requires Node ^20.10.0 or >=21.0.0 and ESLint >=9.38.0.
Common errors
error Error: Failed to load plugin 'unicorn' declared in 'plugins': Cannot find module 'eslint-plugin-unicorn' ↓
cause Plugin not installed or not in node_modules
fix
npm install --save-dev eslint-plugin-unicorn
error Error: ConfigError: Config (unnamed): Key "rules": The key 'unicorn/better-regex' is not defined in the plugin unicorn. ↓
cause Plugin not registered in plugins key
fix
Add plugins: { unicorn: eslintPluginUnicorn } to flat config
error Error: Process environment variable 'NODE_OPTIONS': --require is not supported by Node.js ↓
cause CommonJS require() used for plugin
fix
Use ESM import; set type: module in package.json
error Error: Failed to load config 'plugin:unicorn/recommended' to extend from. ↓
cause Flat config does not support extends; use configs.recommended
fix
Use eslintPluginUnicorn.configs.recommended in flat config array
Warnings
breaking ESLint flat config required >=9.20.0; legacy .eslintrc format not supported ↓
fix Migrate to eslint.config.js flat config
breaking Node.js 20.10 or higher required ↓
fix Update Node.js to ^20.10.0 or >=21.0.0
breaking Rename rules breaking change: no-array-push-push renamed to prefer-single-call, no-length-as-slice-end renamed to no-unnecessary-slice-end ↓
fix Update rule names in config
breaking ESM-only; CommonJS require() not supported ↓
fix Use import statements; set type: module in package.json
deprecated Deprecated rules (e.g., no-process-exit, no-hex-escape) removed in recent versions ↓
fix Replace with current rule alternatives or remove from config
gotcha Requires globals.builtin for languageOptions to avoid false positives ↓
fix Install globals package and include globals.builtin in config
Install
npm install eslint-plugin-unicorn yarn add eslint-plugin-unicorn pnpm add eslint-plugin-unicorn Imports
- default wrong
const eslintPluginUnicorn = require('eslint-plugin-unicorn')correctimport eslintPluginUnicorn from 'eslint-plugin-unicorn' - rules wrong
const { rules } = require('eslint-plugin-unicorn')correctimport { rules } from 'eslint-plugin-unicorn' - configs
import { configs } from 'eslint-plugin-unicorn'
Quickstart
// eslint.config.js
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
import globals from 'globals';
export default [
{
languageOptions: {
globals: globals.builtin,
},
plugins: {
unicorn: eslintPluginUnicorn,
},
rules: {
'unicorn/better-regex': 'error',
'unicorn/prefer-spread': 'error',
'unicorn/no-array-for-each': 'error',
},
},
];