first
Ensure all imports appear before other statements
💼 This rule is enabled in the following configs: recommended, typescript.
Rule Details
Imports are hoisted: they run before the module body no matter where they are written. Writing them first keeps the file honest about that. This rule reports every import that comes after a statement that is not an import, not only the one right below it.
- An import is
import ... from 'm', a side-effectimport 'm', and TSimport x = require('m'). - The directive prologue (
'use client','use strict', any string directive at the very top) is not a statement of the module body and may come first. A string after an import is no directive: it is an ordinary statement. import x = N.yaliases a namespace; it loads no module and neither counts as an import nor pushes imports down.
❌ Incorrect
const ready = true;
import a from './a';
import b from './b'; // also after `ready`
import c from './c';
('use client');
import d from './d';✅ Correct
'use client';
'use strict';
import a from './a';
import b = require('./b');
const ready = true;Options
[]No options.
When Not To Use It
When a file must run code before an import on purpose; imports are hoisted anyway, so that code does not run first.
Use this rule
npm install -D oxlint-plugin-import-next{ "jsPlugins": ["oxlint-plugin-import-next"], "rules": { "import-next/first": "error" }}import { defineConfig } from 'vite-plus';export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-import-next'], rules: { 'import-next/first': 'error', }, },});oxlint-plugin-import-next re-exports eslint-plugin-import-next/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.
Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.