Skip to content

useImportsFirst

biome.json
{
"linter": {
"rules": {
"nursery": {
"useImportsFirst": "error"
}
}
}
}

Enforce that all imports appear at the top of the module.

Import statements that appear after non-import statements are harder to find and may indicate disorganized code. Keeping all imports together at the top makes dependencies immediately visible.

Directives such as "use strict" are always allowed before imports, since they are parsed separately from module items.

This rule only applies to ES module import statements. CommonJS require() calls are not covered.

import { foo } from "foo";
const bar = 1;
import { baz } from "baz";
code-block.js:3:1 lint/nursery/useImportsFirst ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This import appears after a non-import statement.

1 │ import { foo } from “foo”;
2 │ const bar = 1;
> 3 │ import { baz } from “baz”;
^^^^^^^^^^^^^^^^^^^^^^^^^^
4 │

Scattering imports makes it harder to see the module’s dependencies at a glance.

Move all import statements before any other statements.

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.

import { foo } from "foo";
import { bar } from "bar";
const baz = 1;
"use strict";
import { foo } from "foo";