import-js/eslint-plugin-import

import/order group by prefix

Open

#795 geöffnet am 6. Apr. 2017

Auf GitHub ansehen
 (9 Kommentare) (5 Reaktionen) (0 zugewiesene Personen)JavaScript (1.540 Forks)batch import
enhancementhelp wantedimport/export ordering

Repository-Metriken

Stars
 (4.946 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 138T 22h) (3 gemergte PRs in 30 T)

Beschreibung

I import from all over my app, with a mix of relative and root imports. The current order rule covers most of my cases, and with #629 fixing #389 (sorting alphabetically), that will cover more. But one case that won't be covered is that I prefer to have all my global functions imported first, which come from a /lib directory, followed by my components which come from a /client/modules directory.

Sorting alphabetically, I would have to do

import someComponent from '/client/modules/someComponent';
import someFunction from '/lib/someFunction';

But I'd rather do

import someFunction from '/lib/someFunction';
import someComponent from '/client/modules/someComponent';

Within the rule itself, there's one way I could see it being defined

Use the existing groups option, and anything that isn't currently an option (builtins, sibling, etc) would be considered a prefix "import/order": ["error", {"groups": ["builtins", "external", "/lib", "/client"]}]

This would also handle the concern in this comment that people will start to request a bunch of order types and exceptions to them

Contributor Guide