Skip to main content

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.

Code is written once but read many times. Abbreviations like e, cb, err, req, and res save a few keystrokes but force every future reader to decode the shorthand. This rule flags discouraged abbreviations and suggests full-word replacements, with an auto-fix when there is exactly one possible replacement.
Recommendedrecommended
Fixable🔧 Auto-fix (single replacement only)
Suggestions

Examples

const e = new Error();
const e = document.createEvent('Event');
class Btn {}

Configuration

eslint.config.js
export default [
  {
    rules: {
      'unicorn/prevent-abbreviations': ['error', {
        replacements: {},
        extendDefaultReplacements: true,
        allowList: {},
        extendDefaultAllowList: true,
        checkDefaultAndNamespaceImports: 'internal',
        checkShorthandImports: 'internal',
        checkShorthandProperties: false,
        checkProperties: false,
        checkVariables: true,
        checkFilenames: true,
        ignore: [],
      }],
    },
  },
];

replacements

Type: object Extend or override the default replacements. Each key is an abbreviation; the value is an object mapping replacement names to true (enabled) or false (disabled).
'unicorn/prevent-abbreviations': ['error', {
  replacements: {
    e: { event: false },       // disable e → event, keep e → error
    res: false,                 // disable all replacements for `res`
    cmd: { command: true },     // add custom cmd → command
    errCb: { handleError: true }, // add custom errCb → handleError
  },
}]

extendDefaultReplacements

Type: boolean — Default: true When false, the replacements option completely replaces the built-in list instead of extending it.

allowList

Type: object Map of exact identifier names (case-sensitive) to true to exempt them from reporting.
// Allow `getInitialProps` even though `props` is normally discouraged
{ allowList: { getInitialProps: true } }

extendDefaultAllowList

Type: boolean — Default: true When false, the allowList option completely replaces the built-in allow list.

checkDefaultAndNamespaceImports

Type: 'internal' | boolean — Default: 'internal'
  • 'internal' — check default and namespace import names only for internal modules (relative or absolute paths, not node_modules).
  • true — check all default and namespace import names.
  • false — skip default and namespace import names entirely.

checkShorthandImports

Type: 'internal' | boolean — Default: 'internal' Same as checkDefaultAndNamespaceImports but for shorthand ({named}) imports.

checkShorthandProperties

Type: boolean — Default: false When true, destructured shorthand property names are also checked.
// Reported when checkShorthandProperties: true
const { err } = foo;
function f({ err }) {}

checkProperties

Type: boolean — Default: false When true, object property keys and class member names are checked.

checkVariables

Type: boolean — Default: true Set to false to skip variable name checks entirely.

checkFilenames

Type: boolean — Default: true Set to false to skip filename checks. When enabled, only the basename is tested (not the full path).

ignore

Type: Array<string | RegExp> — Default: [] Patterns to ignore. Strings are interpreted as regular expressions.
{ ignore: ['\\.e2e$', /^ignore/i] }
The auto-fix only applies when there is exactly one possible replacement. When multiple replacements exist, the rule reports all suggestions but leaves the rename to you.

Build docs developers (and LLMs) love