Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

eslint-plugin-unicorn

> 编程语言
Open source

More than 300 powerful ESLint rules

5.2K stars0 likes3 views
WebsiteGitHub

About

More than 300 powerful ESLint rules

eslint-plugin-unicorn

More than 300 powerful ESLint rules

Most rules target JavaScript and TypeScript, but some also lint CSS, HTML, JSON, Markdown, TOML, and YAML when used with the matching ESLint language plugin.

Propose a new rule ➡

We do not accept pull requests because of too much AI slop.

Install

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.

Usage

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

Rules

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-arrow-return-style Enforce a consistent return style for multiline arrow function bodies.
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 o

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScripteslinteslint-configeslint-plugineslint-rules

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言