@j4cobi/eslint-plugin-sort-imports
v1.0.2
Published
An ESLint rule that can auto fix import sorting issues.
Downloads
806
Maintainers
Readme
@j4cobi/eslint-plugin-sort-imports
An updated fork of eslint-plugin-sort-imports-es6-autofix.
An ESLint rule that can auto fix ES6 import sorting issues. It accepts the same options as the original rule, but the multiple
type corresponds to all named imports (regardless of how many are imported), while the single
type corresponds only to default imports.
This rule respects whitespace and comments between imports by only looking at the order of (and sorting) consecutive import statements (those without newlines/comments in between them).
This fork also fixes the import order on eslint --fix. To avoid problems, it will only switch out the import statements, not comments on the same line, etc.
Invalid Code
import fastify from "fastify";
import { useState } from "react";
import * as lodash from "lodash";
import { join } from "node:path";
import "./do-something";
Correct Code
import * as lodash from "lodash";
import fastify from "fastify";
import { join } from "node:path";
import { useState } from "react";
import "./do-something";
Compatibility
- ESLint v9
- TypeScript ESlint v8
Usage
Install the package with
npm i --save-dev @j4cobi/eslint-plugin-sort-imports
Then add @j4cobi/eslint-plugin-sort-imports
to the plugins section of your eslint.config.js
config.
import sortImports from "@j4cobi/eslint-plugin-sort-imports";
export default [
{
plugins: { "sort-imports": sortImports },
rules: {
"sort-imports/sort-imports": [
"error",
{
ignoreCase: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["all", "single", "multiple", "none"],
},
]
}
}
];