Skip to content

noMutableExports (JavaScript)

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

Disallow exporting variables declared with let or var.

A variable declared with let or var can be reassigned. When a module exports such a variable, every module that imports it sees the new value after a reassignment. Values that change from far away make code harder to follow and debug.

Exporting a const variable, a function, or a class is allowed. If a value has to change over time, export functions that read and update it instead.

Type declaration files (.d.ts) and ambient declare code only describe code that lives elsewhere, so they are ignored.

export let count = 1;
code-block.js:1:1 lint/nursery/noMutableExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This export can be reassigned because it is declared with let.

> 1 │ export let count = 1;
│ ^^^^^^^^^^
2 │

ℹ Modules that import this variable see its value change whenever it is reassigned, which makes the code harder to follow.

ℹ Declare the variable with const instead. If the value needs to change, export functions that read and update it.

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

export var count = 1;
code-block.js:1:1 lint/nursery/noMutableExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This export can be reassigned because it is declared with var.

> 1 │ export var count = 1;
│ ^^^^^^^^^^
2 │

ℹ Modules that import this variable see its value change whenever it is reassigned, which makes the code harder to follow.

ℹ Declare the variable with const instead. If the value needs to change, export functions that read and update it.

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

let count = 1;
export { count };
code-block.js:2:10 lint/nursery/noMutableExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This export refers to count, which can be reassigned because it is declared with let.

1 │ let count = 1;
> 2 │ export { count };
│ ^^^^^
3 │

ℹ The variable is declared here.

> 1 │ let count = 1;
│ ^^^
2 │ export { count };
3 │

ℹ Modules that import this variable see its value change whenever it is reassigned, which makes the code harder to follow.

ℹ Declare the variable with const instead. If the value needs to change, export functions that read and update it.

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

let count = 1;
export default count;
code-block.js:2:16 lint/nursery/noMutableExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This export refers to count, which can be reassigned because it is declared with let.

1 │ let count = 1;
> 2 │ export default count;
│ ^^^^^
3 │

ℹ The variable is declared here.

> 1 │ let count = 1;
│ ^^^
2 │ export default count;
3 │

ℹ A default export keeps the value the variable had when the module ran, so importers don't see later reassignments. This makes it easy to read an outdated value.

ℹ Declare the variable with const instead. If the value needs to change, export functions that read and update it.

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

export const count = 1;
export function getCount() {}
export class Counter {}
const total = 1;
export { total as default };