useImportsFirst
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useImportsFirst - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
import/first
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useImportsFirst": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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";Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.