
More than 300 powerful ESLint rules
Most rules target JavaScript and TypeScript, but some also lint CSS, HTML, JSON, and Markdown when used with the matching ESLint language plugin.
We do not accept pull requests because of too much AI slop.
npm install --save-dev eslint eslint-plugin-unicorn
Requires ESLint >=10.4, flat config, and ESM.
You might want to check out XO, which includes this plugin.
Use a preset config or configure each rule in eslint.config.js.
If you don't use a preset, set the same languageOptions as shown below.
import unicorn from 'eslint-plugin-unicorn';
import {defineConfig} from 'eslint/config';
import globals from 'globals';
export default defineConfig([
{
files: ['**/*.js'],
languageOptions: {
globals: globals.builtin,
},
plugins: {
unicorn,
},
rules: {
'unicorn/prefer-module': 'error',
'unicorn/…': 'error',
},
},
// …
]);
For TypeScript, scope Unicorn to TypeScript files and configure a TypeScript parser for the same config object:
import typescriptEslintParser from '@typescript-eslint/parser';
import unicorn from 'eslint-plugin-unicorn';
import {defineConfig} from 'eslint/config';
import globals from 'globals';
export default defineConfig([
{
files: ['**/*.ts'],
languageOptions: {
globals: globals.builtin,
parser: typescriptEslintParser,
},
plugins: {
unicorn,
},
rules: {
'unicorn/prefer-module': 'error',
'unicorn/…': 'error',
},
},
// …
]);
💼 Configurations enabled in.\
✅ Set in the recommended configuration.\
☑️ Set in the unopinionated configuration.\
🔧 Automatically fixable by the --fix CLI option.\
💡 Manually fixable by editor suggestions.\
💭 Requires type information.
| Name | Description | 💼 | 🔧 | 💡 | 💭 |
|---|---|---|---|---|---|
| better-dom-traversing | Prefer better DOM traversal APIs. | ✅ ☑️ | 💡 | ||
| catch-error-name | Enforce a specific parameter name in catch clauses. | ✅ | 🔧 | ||
| class-reference-in-static-methods | Enforce consistent class references in static methods. | ✅ | 💡 | ||
| comment-content | Enforce better comment content. | 🔧 | |||
| consistent-assert | Enforce consistent assertion style with node:assert. |
✅ | 🔧 | ||
| consistent-boolean-name | Enforce consistent naming for boolean names. | ✅ | 🔧 | 💡 | |
| consistent-class-member-order | Enforce consistent class member order. | ✅ | 💡 | ||
| consistent-compound-words | Enforce consistent spelling of compound words in identifiers. | ✅ ☑️ | 💡 | ||
| consistent-conditional-object-spread | Enforce consistent conditional object spread style. | ✅ | 🔧 | ||
| consistent-date-clone | Prefer passing Date directly to the constructor when cloning. |
✅ ☑️ | 🔧 | ||
| consistent-destructuring | Use destructured variables over properties. | 💡 | |||
| consistent-empty-array-spread | Prefer consistent types when spreading a ternary in an array literal. | ✅ | 🔧 | ||
| consistent-existence-index-check | Enforce consistent style for element existence checks with indexOf(), lastIndexOf(), findIndex(), and findLastIndex(). |
✅ ☑️ | 🔧 | ||
| consistent-export-decorator-position | Enforce consistent decorator position on exported classes. | ✅ ☑️ | 🔧 | ||
| consistent-function-scoping | Move function definitions to the highest possible scope. | ✅ | |||
| consistent-function-style | Enforce function syntax by role. | 💡 | |||
| consistent-json-file-read | Enforce consistent JSON file reads before JSON.parse(). |
✅ | 🔧 | ||
| consistent-optional-chaining | Enforce consistent optional chaining for same-base member access. | ✅ ☑️ | 💡 | ||
| consistent-template-literal-escape | Enforce consistent style for escaping ${ in template literals. |
✅ | 🔧 | ||
| consistent-tuple-labels | Enforce consistent labels on tuple type elements. | ✅ | |||
| custom-error-definition | Enforce correct Error subclassing. |
🔧 | |||
| default-export-style | Enforce consistent default export declarations. | ✅ | 🔧 | 💡 | |
| dom-node-dataset | Enforce consistent style for DOM element dataset access. | ✅ ☑️ | 🔧 | ||
| empty-brace-spaces | Enforce no spaces between braces. | ✅ | 🔧 | ||
| error-message | Enforce passing a message value when creating a built-in error. |
✅ ☑️ | |||
| escape-case | Require escape sequences to use uppercase or lowercase values. | ✅ ☑️ | 🔧 | ||
| expiring-todo-comments | Add expiration conditions to TODO comments. | ✅ ☑️ | |||
| explicit-length-check | Enforce explicitly comparing the length or size property of a value. |
✅ | 🔧 | 💡 | |
| explicit-timer-delay | Enforce or disallow explicit delay argument for setTimeout() and setInterval(). |
✅ ☑️ | 🔧 | ||
| filename-case | Enforce a case style for filenames and directory names. | ✅ | |||
| id-match | Require identifiers to match a specified regular expression. | ||||
| import-style | Enforce specific import styles per module. | ✅ ☑️ | |||
| isolated-functions | Prevent usage of variables from outside the scope of isolated functions. | ✅ | |||
| logical-assignment-operators | Require or disallow logical assignment operator shorthand | ✅ | 🔧 | 💡 | |
| max-nested-calls | Limit the depth of nested calls. | ✅ | |||
| name-replacements | Enforce replacements for variable, property, and filenames. | ✅ | 🔧 | 💡 | |
| new-for-builtins | Enforce correct use of new for builtin constructors. |
✅ ☑️ | 🔧 | 💡 | |
| no-abusive-eslint-disable | Enforce specifying rules to disable in eslint-disable comments. |
✅ ☑️ | |||
| no-accessor-recursion | Disallow recursive access to this within getters and setters. |
✅ ☑️ | |||
| no-accidental-bitwise-operator | Disall |
$ claude mcp add eslint-plugin-unicorn \
-- python -m otcore.mcp_server <graph>