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
If we allow any string there, then adding any new options goes from being a semver-minor to a semver-major, and there'd be no easy way to tell people when they have to update their configs.
What if the prefixes were done in a second option prefixGroups, like so?
"import/order": ["error", {
"groups": ["builtins", "external"]
"prefixGroups": [
{
"prefix": "/lib",
"before": "external"
},
{
"prefix": "/client",
"after": "external"
},
}]
The before and after arguments allow for ordering alongside the base groups that you have.
That would avoid the conflict I specified.
Also, instead of a prefix, we'd probably want to use globs - ie, /lib/** would be for a prefix, *_test.js for a suffix, etc (call it "pattern")
Globs would work as well. And I like the addition of the suffix.
What's the difficulty of doing something like this? I'd love to contribute this myself if possible. Do you have any suggested resources (aside from the code itself) on how to get started with writing part of a linter plugin?
I am also interested in this. Are there any plans to implement this?
Yea I would also like to see support for this.
Is it posible to also declare imports based on imported file extension?
For example I want to have .css and .md imports at the bottom of the list.
See my comment in https://github.com/benmosher/eslint-plugin-import/issues/807#issuecomment-415358830
I think in times of yarn/lerna workspaces, users need some degree of control about e.g. what is "internal". Having namespaced packages should actually help the situation.
Would love to see some action on this feature request.
Using babel-plugin-root-import, I wish import/order could interpret all my ~/ imports as one group.
Any news on this? :(
Most helpful comment
Yea I would also like to see support for this.
Is it posible to also declare imports based on imported file extension?
For example I want to have
.cssand.mdimports at the bottom of the list.