Skip to content

useConsistentFunctionStyle (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useConsistentFunctionStyle": "error"
}
}
}
}

Enforce consistent use of function declarations or expressions assigned to variables.

A consistent function style makes function definitions easier to recognize. Use the style option to choose the style that matches your project’s conventions.

In both styles, callbacks, methods, and default exports are ignored. Named exports follow the configured style.

function greet() {
return "Hello";
}
code-block.js:1:10 lint/nursery/useConsistentFunctionStyle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Function expressions are required here, but this is a declaration.

> 1 │ function greet() {
^^^^^
2 │ return "Hello";
3 │ }

Using a consistent function style makes function definitions easier to recognize.

Use a function expression assigned to a variable.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const greet = function() {
return "Hello";
};
const farewell = () => "Goodbye";
export default function greet() {
return "Hello";
}

Type: "expression" | "declaration"

Default: "expression"

With "expression", the rule requires function expressions or arrow functions assigned to variables.

These functions can only be called after the variable is initialized. TypeScript overloads are allowed because they require declarations.

function identity(value: string): string;
function identity(value: number): number;
function identity(value: string | number) {
return value;
}

With "declaration", the rule requires function declarations.

These are hoisted and can be called before their definition. Arrow functions that directly use this or super are allowed to preserve their lexical binding. Variables with TypeScript type annotations are also allowed because a function declaration cannot be annotated with an existing function type. A return type annotation on the function does not qualify for this exception.

The following examples use "declaration":

biome.json
{
"linter": {
"rules": {
"nursery": {
"useConsistentFunctionStyle": {
"level": "on",
"options": {
"style": "declaration"
}
}
}
}
}
}
const greet = function() {};
code-block.js:1:7 lint/nursery/useConsistentFunctionStyle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Function declarations are required here, but this is an expression.

> 1 │ const greet = function() {};
^^^^^
2 │

Using a consistent function style makes function definitions easier to recognize.

Use a function declaration.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const greet = (): string => "Hello";
code-block.ts:1:7 lint/nursery/useConsistentFunctionStyle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Function declarations are required here, but this is an expression.

> 1 │ const greet = (): string => "Hello";
^^^^^
2 │

Using a consistent function style makes function definitions easier to recognize.

Use a function declaration.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

function greet() {}
const getContext = () => this;
type Greeting = () => string;
const greet: Greeting = () => "Hello";
const farewell: Greeting = function() { return "Goodbye"; };

Type: boolean

Default: false

Allow arrow functions regardless of style setting. Arrow functions are always allowed when expressions are required.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useConsistentFunctionStyle": {
"level": "on",
"options": {
"style": "declaration",
"allowArrowFunctions": true
}
}
}
}
}
}
const greet = function() { return "Hello"; };
code-block.js:1:7 lint/nursery/useConsistentFunctionStyle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Function declarations are required here, but this is an expression.

> 1 │ const greet = function() { return "Hello"; };
^^^^^
2 │

Using a consistent function style makes function definitions easier to recognize.

Use a function declaration.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

function greet() { return "Hello"; }
const farewell = () => "Goodbye";