📝 Enforce consistent spelling of compound words in identifiers.
💼 This rule is enabled in the following configs: ✅ recommended, ☑️ unopinionated.
💡 This rule is manually fixable by editor suggestions.
Compound words should be treated as one word when applying identifier casing conventions.
Treating the same compound word consistently prevents equivalent concepts from being cased differently across identifiers.
This rule uses a conservative curated list of common compound-word mistakes in code identifiers. It is not a spellchecker or a prose style rule.
// ❌
const passWord = 'secret';
// ✅
const password = 'secret';// ❌
const isInViewPort = true;
// ✅
const isInViewport = true;// ❌
function unSubscribe() {}
// ✅
function unsubscribe() {}This rule does not check string keys, computed properties, property reads, JSX attributes, or export aliases. These are often external API surfaces where preserving the exact spelling is more important than normalizing identifier style.
It also intentionally excludes ambiguous or common API spellings such as fileName, setUp, lookUp, and newLine. These can be natural identifiers when the words keep separate meaning, for example a newly created line instead of the newline character.
Type: object
Type: object
You can extend default replacements by passing the replacements option.
'unicorn/consistent-compound-words': [
'error',
{
replacements: {
fooBar: 'foobar',
passWord: false,
},
},
]Type: boolean
Default: true
Pass extendDefaultReplacements: false to override the default replacements completely.
Type: object
Use allowList to skip full identifier names case-sensitively. Values must be true.
'unicorn/consistent-compound-words': [
'error',
{
allowList: {
legacyUserName: true,
},
},
]Type: boolean
Default: true
Pass checkVariables: false to disable checking variable names.
Type: boolean
Default: false
Pass checkProperties: true to check property definitions and property writes.
Type: 'internal' | boolean
Default: 'internal'
'internal'- Check variables declared in default or namespace imports, but only for internal modules.true- Check variables declared in default or namespace imports.false- Don't check variables declared in default or namespace imports.
Type: 'internal' | boolean
Default: 'internal'
'internal'- Check variables declared in shorthand imports, but only for internal modules.true- Check variables declared in shorthand imports.false- Don't check variables declared in shorthand imports.
Type: boolean
Default: false
Pass checkShorthandProperties: true to check variables declared as shorthand properties in object patterns.