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.

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).
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.
npm install eslint-unicorn
yarn add eslint-unicorn
pnpm add eslint-unicorn

Shows how to set up eslint-plugin-unicorn with flat config (ESLint >=8.56.0) using the recommended preset and additional rules.

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',
    },
  },
];