TypeScript · correctness
enforce-file-structure
eslint:enforce-file-structure Require imports before body statements and require `use server` to be the first statement.
- Default
- error
- Fix
- none
- Languages
- typescript
Why
Interleaved imports obscure module dependencies, while a displaced `use server` string is not an active directive.
Fix
Move `use server` to the first statement when present, then place imports before declarations and executable statements.
Before / after
Executed by this rule’s unit tests.
Before
An import follows a module declaration
export const x = 1;
import { z } from 'zod'; After
Imports precede module declarations
import { z } from 'zod';
export const schema = z.string(); Limits
- The rule skips tests and generated files, treats re-exports as neutral, and does not order body declarations.
Message IDs
importsFirstuseServerDirective