@feliperohdee/eslint-plugin-imports
v1.0.1
Published
Opinionated ESLint flat-config rule that groups imports (npm → @/ → relative) and sorts each group by the full import line.
Downloads
145
Maintainers
Readme
@feliperohdee/eslint-plugin-imports
Opinionated ESLint flat-config rule that groups your imports and sorts each group by the full import line — matching Cursor / VS Code "Sort Lines Ascending" exactly. Auto-fixable, zero runtime dependencies.
What it does
sort-imports-by-line rewrites the leading block of import statements so that:
- Groups, in this order, separated by a single blank line:
- npm / package imports
@/alias imports- relative imports (
./,../)
- Sorts within each group by the entire import line using a default
Intl.Collator(case-insensitive, punctuation before letters) — the same ordering you get from editor "Sort Lines Ascending". So_/__-named imports come first, then{ named }imports, then letter-named defaults (clsxbeforeReact). - Pushes multi-line imports to the end of their group.
It leaves a block untouched when it has fewer than two imports, or when a comment lives between the imports (so a comment is never dropped by the reorder).
Before
import sibling from './sibling';
import React from 'react';
import { Button } from '@/components/button';
import _ from 'lodash';After
import _ from 'lodash';
import React from 'react';
import { Button } from '@/components/button';
import sibling from './sibling';Install
yarn add -D @feliperohdee/eslint-plugin-importsRequires ESLint >=8.57.0 (flat config).
Usage
In eslint.config.js / eslint.config.mjs, either spread the recommended
config:
import imports from '@feliperohdee/eslint-plugin-imports';
export default [imports.configs.recommended];…or register the plugin yourself for full control:
import imports from '@feliperohdee/eslint-plugin-imports';
export default [
{
files: ['**/*.{ts,tsx,js,jsx}'],
plugins: {
'@feliperohdee/imports': imports
},
rules: {
'@feliperohdee/imports/sort-imports-by-line': 'error'
}
}
];Run eslint . --fix to apply the ordering.
License
MIT
