Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt
Use this file to discover all available pages before exploring further.
eslint-plugin-unicorn supports two approaches: drop in a preset config to enable a curated set of rules with one line, or configure rules manually for full control over which rules are active and at what severity.
Preset configs
Manual configuration
Preset configs
Preset configs include the plugin, all required languageOptions, and a pre-selected set of rules. You do not need to register the plugin or set languageOptions separately when using a preset.Choose the preset that matches how much enforcement you want:| Preset | Description |
|---|
recommended | Enables rules that enforce well-established best practices. The right starting point for most projects. |
unopinionated | A subset of recommended containing only rules that are broadly agreed upon. Avoids rules where reasonable people disagree. |
all | Enables every rule (except deprecated ones) at error severity. |
Recommended config
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
export default [
// …
eslintPluginUnicorn.configs.recommended,
];
All config
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
export default [
// …
eslintPluginUnicorn.configs.all,
];
Unopinionated config
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
export default [
// …
eslintPluginUnicorn.configs.unopinionated,
];
Override a rule’s severity in a preset
Spread the preset into your config array, then add a second config object with your overrides. ESLint merges configs in order, so the override takes effect:import eslintPluginUnicorn from 'eslint-plugin-unicorn';
export default [
// …
eslintPluginUnicorn.configs.recommended,
{
rules: {
'unicorn/better-regex': 'warn',
},
},
];
Disable a rule
Set a rule to 'off' in an override config:import eslintPluginUnicorn from 'eslint-plugin-unicorn';
export default [
// …
eslintPluginUnicorn.configs.recommended,
{
rules: {
'unicorn/no-array-reduce': 'off',
},
},
];
Manual configuration
If you want full control over which rules are active, register the plugin and list each rule explicitly. When using this approach, you must also set languageOptions to include globals.builtin — some rules depend on knowing which built-in globals are available.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/…': 'error',
},
},
// …
];
The globals package is a dependency of eslint-plugin-unicorn, so it is already available after installation. You can import it directly without installing it separately.
Override or disable a specific rule
Set any rule to 'warn', 'error', or 'off' in the rules object:rules: {
'unicorn/better-regex': 'warn', // downgrade to warning
'unicorn/no-null': 'off', // disable entirely
},
Why globals.builtin is required
Several unicorn rules — such as no-instanceof-builtins and prefer-global-this — need to know which identifiers are built-in globals in the target environment. Without globals.builtin, these rules may produce false positives or miss violations.Preset configs set this automatically. You only need to add it manually when configuring rules without a preset.