eslint-plugin-unicorn
raw JSON → 55.0.0 verified Sat Apr 25 auth: no javascript
ESLint plugin providing more than 100 powerful rules for enforcing consistent, error-free code style and catching common mistakes. Current stable version is 55.0.0, with frequent releases (often multiple per month). Key differentiators include a broad focus beyond stylistic concerns (e.g., security, performance, best practices), automatic fixing for many rules, and strong integration with XO. It requires ESLint >=8.56.0 and Node >=18.18, and ships TypeScript definitions.
Common errors
error Oops! Something went wrong! :( ESLint: 8.x.x. eslint-plugin-unicorn: 55.x.x. No configuration matching. ↓
cause Using older ESLint version or missing flat config migration
fix
Update ESLint to >=8.56.0 and use eslint.config.js.
error Error: Cannot find module 'eslint-plugin-unicorn' ↓
cause Package not installed or missing in node_modules
fix
Run 'npm install --save-dev eslint eslint-plugin-unicorn'.
error TypeError: eslintPluginUnicorn is not a function ↓
cause Incorrectly importing default export in CommonJS
fix
Use 'const eslintPluginUnicorn = require('eslint-plugin-unicorn');' (no .default).
Warnings
breaking Minimum Node.js version is 18.18 starting from v60.0.0 ↓
fix Update Node.js to >=18.18 or pin eslint-plugin-unicorn to <60.0.0.
deprecated Rule 'no-array-push-push' renamed to 'prefer-single-call' in v59.0.0 ↓
fix Replace 'unicorn/no-array-push-push' with 'unicorn/prefer-single-call'.
deprecated Rule 'no-length-as-slice-end' renamed to 'no-unnecessary-slice-end' in v59.0.0 ↓
fix Replace 'unicorn/no-length-as-slice-end' with 'unicorn/no-unnecessary-slice-end'.
breaking ESLint <8.56.0 is no longer supported (flat config required starting v55?) ↓
fix Upgrade ESLint to >=8.56.0 and migrate to flat config (eslint.config.js).
gotcha Flat config (eslint.config.js) requires explicit import of plugin; global plugins no longer work ↓
fix Import the plugin in eslint.config.js as shown in the quickstart.
Install
npm install eslint-unicorn yarn add eslint-unicorn pnpm add eslint-unicorn Imports
- eslintPluginUnicorn wrong
const eslintPluginUnicorn = require('eslint-plugin-unicorn').default;correctimport eslintPluginUnicorn from 'eslint-plugin-unicorn'; - configs.recommended wrong
const { configs } = require('eslint-plugin-unicorn');correctimport eslintPluginUnicorn from 'eslint-plugin-unicorn'; eslintPluginUnicorn.configs.recommended - rules wrong
const rules = require('eslint-plugin-unicorn/rules');correctimport eslintPluginUnicorn from 'eslint-plugin-unicorn'; eslintPluginUnicorn.rules['unicorn/better-regex']
Quickstart
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
import globals from 'globals';
export default [
eslintPluginUnicorn.configs.recommended,
{
languageOptions: {
globals: globals.builtin,
},
plugins: {
unicorn: eslintPluginUnicorn,
},
rules: {
'unicorn/better-regex': 'error',
'unicorn/catch-error-name': 'error',
},
},
];