prevent-abbreviations
Reports abbreviated names like err, idx, and dist, then suggests or applies fuller replacements.
Rule details Suggestion
Section titled “Rule details ”SuggestionBy default, the rule checks variables and filenames. Property names are off unless you turn them on with
checkProperties.
When a name has one safe replacement, the rule can auto-fix it. When there are several possible replacements, it reports the name and lists suggestions instead.
The built-in replacement map includes entries such as err -> error, idx -> index, dist -> distance,
acc -> accumulator, and fn -> func or function.
Examples
Section titled “Examples” Incorrect
const err = new Error();const dist = calculateDistance();const fn = () => {}; Correct
const error = new Error();const distance = calculateDistance();const callback = () => {};Options
Section titled “Options”| Option | Type | Default | Notes |
|---|---|---|---|
allowList | Record<string, boolean> | built-in allow list | Exact names to allow. Merged with the default allow list unless extendDefaultAllowList is false. |
checkDefaultAndNamespaceImports | boolean | "internal" | "internal" | Checks default imports, namespace imports, and require(...) bindings. "internal" only checks relative and absolute imports. |
checkFilenames | boolean | true | Reports abbreviated file basenames. |
checkProperties | boolean | false | Reports property keys and assigned member names like obj.err = value. |
checkShorthandImports | boolean | "internal" | "internal" | Checks shorthand imports like import { err } from "./mod". |
checkShorthandProperties | boolean | false | Checks object shorthand values like { err }. |
checkVariables | boolean | true | Reports variable names, parameters, class names, type aliases, and uppercase JSX component names. |
extendDefaultAllowList | boolean | true | Keeps the built-in allow list and adds your entries on top. |
extendDefaultReplacements | boolean | true | Keeps the built-in replacement map and adds your entries on top. |
ignore | (string | RegExp)[] | [/i18n/u, /l10n/u] | Skips names that match any pattern. String values are treated as regex source. |
replacements | Record<string, Record<string, boolean> | false> | built-in replacement map | Adds or overrides discouraged names and their allowed replacements. Set a key to false to clear that entry. |
import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [ { plugins: { "cease-nonsense": ceaseNonsense, }, rules: { "cease-nonsense/prevent-abbreviations": [ "error", { allowList: { ref: true }, checkProperties: true, ignore: ["^test"], replacements: { ctx: { context: true }, fn: { callback: true }, }, }, ], }, },];Related rules
Section titled “Related rules” no-shorthand-names Targets a smaller, fixed set of shorthand words
naming-convention Checks casing and naming style on top of word choice