Skip to content

Latest commit

 

History

History
133 lines (88 loc) · 3.31 KB

File metadata and controls

133 lines (88 loc) · 3.31 KB

consistent-compound-words

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

Examples

// ❌
const passWord = 'secret';

// ✅
const password = 'secret';
// ❌
const isInViewPort = true;

// ✅
const isInViewport = true;
// ❌
function unSubscribe() {}

// ✅
function unsubscribe() {}

Intentionally not checked

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.

Options

Type: object

replacements

Type: object

You can extend default replacements by passing the replacements option.

'unicorn/consistent-compound-words': [
	'error',
	{
		replacements: {
			fooBar: 'foobar',
			passWord: false,
		},
	},
]

extendDefaultReplacements

Type: boolean
Default: true

Pass extendDefaultReplacements: false to override the default replacements completely.

allowList

Type: object

Use allowList to skip full identifier names case-sensitively. Values must be true.

'unicorn/consistent-compound-words': [
	'error',
	{
		allowList: {
			legacyUserName: true,
		},
	},
]

checkVariables

Type: boolean
Default: true

Pass checkVariables: false to disable checking variable names.

checkProperties

Type: boolean
Default: false

Pass checkProperties: true to check property definitions and property writes.

checkDefaultAndNamespaceImports

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.

checkShorthandImports

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.

checkShorthandProperties

Type: boolean
Default: false

Pass checkShorthandProperties: true to check variables declared as shorthand properties in object patterns.