Skip to content

useConsistentDefaultExportStyle (JavaScript)

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

Enforce a consistent style for default-exported functions and classes.

A function or class can be declared inside the export default statement, or declared on its own and then exported by name with export default name;. Using one style across a project makes default exports easier to find and read.

By default, the rule requires functions and classes to be declared inside the export default statement. Use the functions and classes options to require the separate style instead, or to turn off the check.

The rule only checks a declaration that comes directly before export default with its name.

function foo() {}
export default foo;
code-block.js:2:1 lint/nursery/useConsistentDefaultExportStyle  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This default-exported function is declared separately from its export default statement.

1 │ function foo() {}
> 2 │ export default foo;
│ ^^^^^^^^^^^^^^^^^^^
3 │

ℹ The function is declared here.

> 1 │ function foo() {}
│ ^^^
2 │ export default foo;
3 │

ℹ This project declares default-exported functions inside the export default statement, so that all default exports look the same.

ℹ Move the declaration into the export default statement.

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

ℹ Unsafe fix: Declare the function inside the export default statement.

1 │ - function·foo()·{}
2 │ - export·default·foo;
1 │ + export·default·function·foo()·{}
3 2 │

const foo = () => {};
export default foo;
code-block.js:2:1 lint/nursery/useConsistentDefaultExportStyle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This default-exported function is declared separately from its export default statement.

1 │ const foo = () => {};
> 2 │ export default foo;
│ ^^^^^^^^^^^^^^^^^^^
3 │

ℹ The function is declared here.

> 1 │ const foo = () => {};
│ ^^^
2 │ export default foo;
3 │

ℹ This project declares default-exported functions inside the export default statement, so that all default exports look the same.

ℹ Rewrite the arrow function as a function declaration inside the export default statement, like export default function foo() {}.

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

class Foo {}
export default Foo;
code-block.js:2:1 lint/nursery/useConsistentDefaultExportStyle  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This default-exported class is declared separately from its export default statement.

1 │ class Foo {}
> 2 │ export default Foo;
│ ^^^^^^^^^^^^^^^^^^^
3 │

ℹ The class is declared here.

> 1 │ class Foo {}
│ ^^^
2 │ export default Foo;
3 │

ℹ This project declares default-exported classes inside the export default statement, so that all default exports look the same.

ℹ Move the declaration into the export default statement.

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

ℹ Unsafe fix: Declare the class inside the export default statement.

1 │ - class·Foo·{}
2 │ - export·default·Foo;
1 │ + export·default·class·Foo·{}
3 2 │

export default function foo() {}
const bar = () => {};
export { bar };
export default class Foo {}

Type: "inline" | "separate" | "ignore"

Default: "inline"

  • "inline" requires functions to be declared inside the export default statement, like export default function foo() {}.
  • "separate" requires functions to be declared as const arrow functions, then exported by name, like const foo = () => {}; followed by export default foo;. Generator functions (function*) are ignored, because an arrow function can’t be a generator.
  • "ignore" turns off the check for functions.

The following examples use "separate":

biome.json
{
"linter": {
"rules": {
"nursery": {
"useConsistentDefaultExportStyle": {
"level": "on",
"options": {
"functions": "separate"
}
}
}
}
}
}
export default function foo() {}
code-block.js:1:1 lint/nursery/useConsistentDefaultExportStyle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This function is declared inside its export default statement.

> 1 │ export default function foo() {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ This project declares default-exported functions separately, so that all default exports look the same.

ℹ Declare the function as a const arrow function, then export it with export default and its name.

ℹ 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 foo() {}
export default foo;
code-block.js:2:1 lint/nursery/useConsistentDefaultExportStyle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This default-exported function is declared with the function keyword.

1 │ function foo() {}
> 2 │ export default foo;
│ ^^^^^^^^^^^^^^^^^^^
3 │

ℹ The function is declared here.

> 1 │ function foo() {}
│ ^^^
2 │ export default foo;
3 │

ℹ This project declares default-exported functions as const arrow functions, so that all default exports look the same.

ℹ Rewrite the function as a const arrow function, like const foo = () => {};.

ℹ 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 foo = () => {};
export default foo;

Type: "inline" | "separate" | "ignore"

Default: "inline"

  • "inline" requires classes to be declared inside the export default statement, like export default class Foo {}.
  • "separate" requires classes to be declared on their own, then exported by name, like class Foo {} followed by export default Foo;.
  • "ignore" turns off the check for classes.

The following examples use "separate":

biome.json
{
"linter": {
"rules": {
"nursery": {
"useConsistentDefaultExportStyle": {
"level": "on",
"options": {
"classes": "separate"
}
}
}
}
}
}
export default class Foo {}
code-block.js:1:1 lint/nursery/useConsistentDefaultExportStyle  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This class is declared inside its export default statement.

> 1 │ export default class Foo {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ This project declares default-exported classes separately, so that all default exports look the same.

ℹ Declare the class first, then export it with export default and its name.

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

ℹ Unsafe fix: Declare the class separately.

1 │ - export·default·class·Foo·{}
1 │ + class·Foo·{}
2 │ + export·default·Foo;
2 3 │

class Foo {}
export default Foo;