javascript-eslint-import-order
Normalize the top static ESM import block to eslint-plugin-import import/order grouping, blank-line, and alphabetical ordering conventions.
# javascript-eslint-import-order
Deterministically rewrites the top static ESM import block to follow `eslint-plugin-import` `import/order` conventions: group imports, insert exactly one blank line between non-empty groups, and alphabetize declarations within each group.
## What It Changes
- Reorders the contiguous top-level `import` block, while preserving leading directives and file-level pragmas/comments above it.
- Uses these groups, in order: `builtin`, `external`, `internal`, `parent`, `sibling`, `index`, `type`.
- Preserves side-effect-only imports (`import "x";`) in their original positions relative to other imports by default.
- Keeps comments attached to their import when they move.
- Leaves specifier lists unchanged.
## Safe Defaults And Skips
- Files with zero or one top-level static import are left unchanged.
- CommonJS `require(...)` statements are ignored.
- Files with ambiguous comments between the top import block and code are skipped unless `force=true`.
- TypeScript `import = require()` forms in the top import block are treated as unsupported and skipped.
## Supported Files
- JavaScript: `.js`, `.jsx`, `.mjs`, `.cjs`
- TypeScript: `.ts`, `.tsx`
## Parameters
- `internal_alias_prefixes`: comma-separated prefixes treated as `internal` imports. Default: `@/`
- `unsafe_sort_side_effect_imports`: when `true`, side-effect-only imports are sorted instead of preserved. Default: `false`
- `type_grouping`: `group` to emit type-only imports as a final `type` group, or `inline` to keep them in their source group. Default: `group`
- `type_position`: when `type_grouping=inline`, place type-only imports `first` or `last` within equal-source ordering. Default: `last`
- `case_sensitive`: when `true`, preserve case-sensitive alphabetical ordering. Default: `false`
- `force`: when `true`, allows rewriting files with ambiguous trailing comments after the top import block. Default: `false`
## Example
Before:
```ts
import type { Foo } from "@/types";
import { util } from "@/util";
import path from "path";
import _ from "lodash";
```
After:
```ts
import path from "path";
import _ from "lodash";
import { util } from "@/util";
import type { Foo } from "@/types";
```
## Installation
```bash
codemod run javascript-eslint-import-order
```
Or run the local package:
```bash
codemod workflow run -w .
```
## Development
```bash
pnpm test
pnpm validate
pnpm check-types
```
## License
MIT