Skip to main content

Require Naming Convention

Enforce context-aware naming conventions because consistent casing per identifier type (camelCase for variables, PascalCase for classes, UPPER_SNAKE_CASE for constants) makes intent visible from the name alone.

Summary

The require-naming-convention rule checks identifier names against the expected casing for their declaration context.

UPPER_SNAKE_CASE is reserved for const declarations with immutable values (primitives and regex literals). Arrays, objects, instances, and function return values use camelCase even when declared with const. A const with an immutable value may use either UPPER_SNAKE_CASE or camelCase — both are accepted (so const apiUrl = 'x' is fine).

Type aliases default to UnderscorePascalCase — segments are individually PascalCased and joined with underscores (for example, Tests_TypeDeclarations_ExtractObjectTypes_ObjectType). This pairs with the require-type-naming rule, which derives prefixes from the file path in the same format.

Why Use This Rule?

  1. Casing tells the reader what kind of identifier it is — MAX_RETRIES is a constant, maxRetries is a variable, MaxRetries is a class.
  2. Prevents mixed conventions that make the codebase inconsistent and hard to scan.
  3. Catches common mistakes like UPPER_SNAKE_CASE on a mutable let or camelCase on a class.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
classDeclarationstringPascalCaseCasing for class names.
classMethodstringcamelCaseCasing for class methods.
classPropertystringcamelCaseCasing for class properties.
constructorVariablestringPascalCaseCasing for variables used with new.
constantstringUPPER_SNAKE_CASECasing for const with immutable values.
enumstringPascalCaseCasing for enum declarations.
enumMemberstringPascalCaseCasing for enum members.
functionstringcamelCaseCasing for function declarations.
ignoreFilesstring[][]File names to skip. Supports a leading-* suffix (*.test.ts), an exact path, or a trailing path segment; ** globs are not supported.
interfacestringPascalCaseCasing for interfaces.
parameterstringcamelCaseCasing for function parameters.
reactComponentstringPascalCaseCasing for React component functions.
typeAliasstringUnderscorePascalCaseCasing for type aliases.
variablestringcamelCaseCasing for let/var variables.

Accepted casing values: camelCase, PascalCase, UnderscorePascalCase, UPPER_SNAKE_CASE.

Migration in 0.18.0

The default for typeAlias changed from PascalCase to UnderscorePascalCase in 0.18.0 so type aliases align with the prefixes produced by require-type-naming. UnderscorePascalCase is a superset of PascalCase, so glued names like CliUtilityChangelog still pass this rule — the underscore-segmented prefix is enforced separately by require-type-naming.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • const array is flagged for camelCaseUPPER_SNAKE_CASE is only for const with immutable values (primitives and regex literals). Arrays, objects, and function return values use camelCase even when declared with const. A const with an immutable value may also use camelCase — both casings are accepted for it.
  • A non-component function with an uppercase name is treated as a React component — the rule classifies any function declaration whose name starts with an uppercase letter as a React component and applies the reactComponent casing; lowercase-first names use the function casing.
  • Arrow-function and function-expression assignments are not checkedconst handler = () => {} is skipped by the variable check (it is not treated as a constant or plain variable for casing).
  • Leading underscore is flagged — A single leading underscore (e.g., _unused) is tolerated by the camelCase pattern for unused-variable prefixes; the rest of the name is still checked, and only camelCase contexts allow it.