You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is for those who use `eslint --fix` (autofix) a lot and want to completely forget about sorting imports!
@@ -29,6 +30,7 @@ This is for those who use `eslint --fix` (autofix) a lot and want to completely
29
30
-[Installation](#installation)
30
31
-[Usage](#usage)
31
32
-[Example configuration](#example-configuration)
33
+
-[Not for everyone](#not-for-everyone)
32
34
-[Sort order](#sort-order)
33
35
-[Grouping](#grouping)
34
36
-[imports](#imports)
@@ -161,6 +163,27 @@ It is recommended to also set up [Prettier], to help formatting your imports (an
161
163
162
164
With the above configuration, you don’t need to scroll to the top of the file to add another import. Just put it above your function! ESLint will then snap it into place (at the top of the file, in order, and without duplicates).
163
165
166
+
## Not for everyone
167
+
168
+
This plugin is not for everyone. Let me explain.
169
+
170
+
For a long time, this plugin used to have no options, which helped keeping it simple.
171
+
172
+
While the human alphabetical sorting and comment handling seems to work for a lot of people, grouping of imports is more difficult. Projects differ too much to have a one-size-fits-all grouping.
173
+
174
+
I’ve decided to have this single option but nothing more. Here are some things you can’t configure:
175
+
176
+
- The sorting within each group. It is what it is. See [Sorting].
177
+
- Sorting of [side effect imports][safe] (they always stay in the original order).
178
+
179
+
If you want more options, I recommend using the [import/order] rule (from [eslint-plugin-import]) instead. It has plenty of options, and the maintainers seem interested in expanding the feature where it makes sense.
180
+
181
+
Then why does this plugin exist? See [How is this rule different from `import/order`?][import/order-comparison].
182
+
183
+
If we start adding more options to this plugin, it won’t be eslint-plugin-<strong>simple</strong>-import-sort anymore. Eventually it would have no reason to exist – effort would be better spent contributing to [import/order].
184
+
185
+
I made this plugin for myself. I use it in many little projects and I like it. If you like it too – I’m very glad to hear! But _everyone_ won’t like it. And that’s ok.
186
+
164
187
## Sort order
165
188
166
189
This plugin is supposed to be used with autofix, ideally directly in your editor via an ESLint extension, or with [`eslint --fix`][eslint-fix] otherwise.
@@ -232,7 +255,7 @@ function compare(a, b) {
232
255
}
233
256
```
234
257
235
-
In other words, the imports/exports within groups are sorted alphabetically, case-insensitively and treating numbers like a human would, falling back to good old character code sorting in case of ties. See [Intl.Collator] for more information.
258
+
In other words, the imports/exports within groups are sorted alphabetically, case-insensitively and treating numbers like a human would, falling back to good old character code sorting in case of ties. See [Intl.Collator] for more information. Note: `Intl.Collator` sorts punctuation in _some_ defined order. I have no idea what order punctuation sorts in, and I don’t care. There’s no ordered “alphabet” for punctuation that I know of.
236
259
237
260
There’s one addition to the alphabetical rule: Directory structure. Relative imports/exports of files higher up in the directory structure come before closer ones – `"../../utils"` comes before `"../utils"`, which comes before `"."`. (In short, `.` and `/` sort before any other (non-whitespace, non-control) character. `".."` and similar sort like `"../,"` (to avoid the “shorter prefix comes first” sorting concept).)
238
261
@@ -338,17 +361,7 @@ Workaround to make the next section to appear in the table of contents.
338
361
339
362
## Custom grouping
340
363
341
-
For a long time, this plugin used to have no options, which helped keeping it simple.
342
-
343
-
While the human alphabetical sorting and comment handling seems to work for a lot of people, grouping of imports is more difficult. Projects differ too much to have a one-size-fits-all grouping. (Note, for exports the grouping is manual using comments – see [exports]).
344
-
345
-
However, the default grouping is fine for many use cases! Don’t bother learning how custom grouping works unless you _really_ need it.
346
-
347
-
> If you’re looking at custom grouping because you want to move `src/Button`, `@company/Button` and similar – also consider using names that do not look like npm packages, such as `@/Button` and `~company/Button`. Then you won’t need to customize the grouping at all, and as a bonus things might be less confusing for other people working on the code base.
348
-
>
349
-
> In the future, it would be cool if the plugin could automatically detect your “first party”/“absolute” imports for TypeScript projects by reading your tsconfig.json – see [issue #31].
350
-
351
-
There is **one** option (and I would really like it to stay that way!) called `groups` that allows you to:
364
+
There is **one** option (see [Not for everyone]) called `groups` that allows you to:
352
365
353
366
- Move `src/Button`, `@company/Button` and similar out of the (third party) “packages” group, into their own group.
354
367
- Move `react` first.
@@ -358,6 +371,12 @@ There is **one** option (and I would really like it to stay that way!) called `g
358
371
- Separate `./` and `../` imports.
359
372
- Not use groups at all and only sort alphabetically.
360
373
374
+
> If you’re looking at custom grouping because you want to move `src/Button`, `@company/Button` and similar – also consider using names that do not look like npm packages, such as `@/Button` and `~company/Button`. Then you won’t need to customize the grouping at all, and as a bonus things might be less confusing for other people working on the code base.
375
+
>
376
+
> See [issue #31] for some tips on what you can do if you have very complex requirements.
377
+
>
378
+
> Note: For exports the grouping is manual using comments – see [exports].
0 commit comments