Import sorting
See original GitHub issueIn order to avoid unnecessary git changes, we sort our import statements using the default sort feature of Atom or VSCode. We do this by selecting all import lines and running the sort action.
This works okayish but breaks complelty when we break multiple imports into multiple lines, e.g:
import {
Foo,
Bar,
Baz
} from 'foobarbaz';
Since this will (obviously) be sorted to:
Bar,
Baz
Foo,
} from 'foobarbaz';
import {
Are there any plans to support sorting of import blocks using prettier?
The idea would be to detect blocks that consists of import lines like:
import Bar from 'foo';
import Foo from 'foo';
import foo from 'foo';
import bar from 'foo';
import {
Foo,
Bar
} from 'foo';
import * from 'foo';
import { Bar } from 'foo';
import {
foo,
bar
} from 'foo';
import { Foo } from 'foo';
import type Foo from 'foo';
import type Bar from 'foo';
import { bar } from 'foo';
import { foo } from 'foo';
and turn it to something like:
import { bar } from 'foo';
import { Bar } from 'foo';
import { foo } from 'foo';
import { Foo } from 'foo';
import {
foo,
bar
} from 'foo';
import {
Foo,
Bar
} from 'foo';
import * from 'foo';
import Bar from 'foo';
import bar from 'foo';
import foo from 'foo';
import Foo from 'foo';
import type Bar from 'foo';
import type Foo from 'foo';
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:7 (6 by maintainers)
Top Results From Across the Web
sort-imports - ESLint - Pluggable JavaScript Linter
This rule checks all import declarations and verifies that all imports are first sorted by the used member syntax and then alphabetically by...
Read more >lydell/eslint-plugin-simple-import-sort - GitHub
Easy autofixable import sorting. ✅️ Runs via eslint --fix – no new tooling; ✅️ Also sorts exports where possible; ✅️ Handles ...
Read more >Sorting your imports with ESLint - DEV Community
The "react" import should always come first; Package imports should come next, sorted by alphabetical order; The named imports should be sorted ......
Read more >eslint-plugin-simple-import-sort - npm
Easy autofixable import sorting. ✅️ Runs via eslint --fix – no new tooling; ✅️ Also sorts exports where possible; ✅️ Handles ...
Read more >How to Sort Imports in React Project - Level Up Coding
Sort imports with Eslint ... Eslint has many plugin for sort imports, like eslint-plugin-simple-import-sort, eslint-plugin-import, sort-imports. I prefer to use ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately, importing modules can have side effects so changing the order of imports is not safe. So I guess this one has to be closed for the same reasons as #323 and #766. You could use the sort-imports ESLint rule, though.
FYI/for future readers,
eslint-plugin-import
’simport/order
rule can enforce an import order based on module location (but not alphabetization). However, the rule is not fixable.