Skip to content

useNamingConvention (since v1.0.0)

Diagnostic Category: lint/style/useNamingConvention

Inspired from: naming-convention

Enforce naming conventions for everything across a codebase.

Enforcing naming conventions helps to keep the codebase consistent, and reduces overhead when thinking about the name case of a variable.

All names can be prefixed and suffixed by underscores _ and dollar signs $.

All variables, including function parameters and catch parameters, are in camelCase.

Additionally, top-level variables declared as const or var may be in CONSTANT_CASE or PascalCase. Top-level variables are declared at module or script level. Variables declared in a TypeScript module or namespace are also considered top-level.

function f(param, _unusedParam) {
let localValue = 0;
try {
/* ... */
} catch (customError) {
/* ... */
}
}
export const A_CONSTANT = 5;
export const Person = class {}
let aVariable = 0;
export namespace ns {
export const ANOTHER_CONSTANT = "";
}

Examples of incorrect names:

let a_value = 0;
style/useNamingConvention.js:1:5 lint/style/useNamingConvention  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

   This top-level let name should be in camelCase.
  
  > 1 │ let a_value = 0;
       ^^^^^^^
    2 │ 
  
   The name could be renamed to `aValue`.
  
   Safe fix: Rename this symbol in camelCase.
  
    1  - let·a_value·=·0;
      1+ let·aValue·=·0;
    2 2  
  
const fooYPosition = 0;
style/useNamingConvention.js:1:7 lint/style/useNamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Two consecutive uppercase characters are not allowed in camelCase and PascalCase because strictCase is set to `true`.
  
  > 1 │ const fooYPosition = 0;
         ^^^^^^^^^^^^
    2 │ 
  
   If you want to use consecutive uppercase characters in camelCase and PascalCase, then set the strictCase option to `false`.
    See the rule options for more details.
  
function f(FirstParam) {}
style/useNamingConvention.js:1:12 lint/style/useNamingConvention  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

   This function parameter name should be in camelCase.
  
  > 1 │ function f(FirstParam) {}
              ^^^^^^^^^^
    2 │ 
  
   The name could be renamed to `firstParam`.
  
   Safe fix: Rename this symbol in camelCase.
  
    1  - function·f(FirstParam)·{}
      1+ function·f(firstParam)·{}
    2 2  
  

A function name is in camelCase or PascalCase.

function trimString(s) { /*...*/ }
function Component() {
return <div></div>;
}

A TypeScript enum name is in PascalCase.

enum members are by default in PascalCase. However, you can configure the case of enum members. See options for more details.

enum Status {
Open,
Close,
}
class Person {
static MAX_FRIEND_COUNT = 256;
static get SPECIAL_PERSON_INSTANCE() { /*...*/ }
initializedProperty = 0;
specialMethod() {}
}

TypeScript type aliases and interface

Section titled TypeScript type aliases and interface
  • A type alias or an interface name are in PascalCase.

  • Property and method names in a type are in camelCase.

  • readonly property and getter names can also be in CONSTANT_CASE.

type Named = {
readonly fullName: string;
specialMethod(): void;
};
interface Named {
readonly fullName: string;
specialMethod(): void;
}
interface PersonConstructor {
readonly MAX_FRIEND_COUNT: number;
get SPECIAL_PERSON_INSTANCE(): Person;
new(): Person;
}

Examples of an incorrect type alias:

type person = { fullName: string };
style/useNamingConvention.js:1:6 lint/style/useNamingConvention  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

   This type alias name should be in PascalCase.
  
  > 1 │ type person = { fullName: string };
        ^^^^^^
    2 │ 
  
   The name could be renamed to `Person`.
  
   Safe fix: Rename this symbol in PascalCase.
  
    1  - type·person·=·{·fullName:·string·};
      1+ type·Person·=·{·fullName:·string·};
    2 2  
  

Literal object property and method names

Section titled Literal object property and method names

Literal object property and method names are in camelCase.

const alice = {
fullName: "Alice",
}

Example of an incorrect name:

const alice = {
FULL_NAME: "Alice",
}
style/useNamingConvention.js:2:5 lint/style/useNamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This object property name should be in camelCase.
  
    1 │ const alice = {
  > 2 │     FULL_NAME: "Alice",
       ^^^^^^^^^
    3 │ }
    4 │ 
  
   The name could be renamed to `fullName`.
  

Imported and exported module aliases

Section titled Imported and exported module aliases

Imported and exported module aliases are in camelCase or PascalCase.

import * as myLib from "my-lib";
import * as Framework from "framework";
export * as myLib from "my-lib";
export * as Framework from "framework";

import and export aliases are in camelCase, PascalCase, or CONSTANT_CASE:

import assert, {
deepStrictEqual as deepEqual,
AssertionError as AssertError
} from "node:assert";

Examples of an incorrect name:

import * as MY_LIB from "my-lib";
style/useNamingConvention.js:1:13 lint/style/useNamingConvention  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

   This import namespace name should be in camelCase or PascalCase.
  
  > 1 │ import * as MY_LIB from "my-lib";
               ^^^^^^
    2 │ 
  
   The name could be renamed to `myLib`.
  
   Safe fix: Rename this symbol in camelCase.
  
    1  - import·*·as·MY_LIB·from·"my-lib";
      1+ import·*·as·myLib·from·"my-lib";
    2 2  
  

TypeScript type parameter names

Section titled TypeScript type parameter names

A TypeScript type parameter name is in PascalCase.

function id<Val>(value: Val): Val { /* ... */}

A TypeScript namespace name is in camelCase or in PascalCase.

namespace mathExtra {
/*...*/
}
namespace MathExtra {
/*...*/
}

The rule provides two options that are detailed in the following subsections.

{
"//": "...",
"options": {
"strictCase": false,
"enumMemberCase": "CONSTANT_CASE"
}
}

When this option is set to true, it forbids consecutive uppercase characters in camelCase and PascalCase. For instance, when the option is set to true, HTTPServer or aHTTPServer will throw an error. These names should be renamed to HttpServer and aHttpServer

When the option is set to false, consecutive uppercase characters are allowed. HTTPServer and aHTTPServer are so valid.

Default: true

When this option is set to true, it forbids names that include non-ASCII characters. For instance, when the option is set to true, café or 안녕하세요 will throw an error.

When the option is set to false, anames may include non-ASCII characters. café and 안녕하세요 are so valid.

Default: false

This option will be turned on by default in Biome 2.0.

By default, the rule enforces the naming convention followed by the TypeScript Compiler team: an enum member is in PascalCase.

You can enforce another convention by setting enumMemberCase option. The supported cases are: PascalCase, CONSTANT_CASE, and camelCase.