Skip to content

prevent-abbreviations

Reports abbreviated names like err, idx, and dist, then suggests or applies fuller replacements.

By 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.

Incorrect
const err = new Error();
const dist = calculateDistance();
const fn = () => {};
Correct
const error = new Error();
const distance = calculateDistance();
const callback = () => {};
OptionTypeDefaultNotes
allowListRecord<string, boolean>built-in allow listExact names to allow. Merged with the default allow list unless extendDefaultAllowList is false.
checkDefaultAndNamespaceImportsboolean | "internal""internal"Checks default imports, namespace imports, and require(...) bindings. "internal" only checks relative and absolute imports.
checkFilenamesbooleantrueReports abbreviated file basenames.
checkPropertiesbooleanfalseReports property keys and assigned member names like obj.err = value.
checkShorthandImportsboolean | "internal""internal"Checks shorthand imports like import { err } from "./mod".
checkShorthandPropertiesbooleanfalseChecks object shorthand values like { err }.
checkVariablesbooleantrueReports variable names, parameters, class names, type aliases, and uppercase JSX component names.
extendDefaultAllowListbooleantrueKeeps the built-in allow list and adds your entries on top.
extendDefaultReplacementsbooleantrueKeeps 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.
replacementsRecord<string, Record<string, boolean> | false>built-in replacement mapAdds 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 },
},
},
],
},
},
];