-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add absolute-first-group
option to imports-first
#246
Add absolute-first-group
option to imports-first
#246
Conversation
I think this may be covered by the |
Yeah, this behaviour is covered by |
@jfmengels I tried to configure |
Ah sorry. I thought you only wanted to group the same "type" of imports together, but you want that and also to get the newline between each group? If so, my bad, and no, that is not supported. The rule only the grouping and ordering of the groups, no ordering inside of the groups nor adding lines between the groups. |
@jfmengels Yeah, I could make a PR to Basically I was think about two kind of options for that:
"import-order/import-order": [2, {"order": ["index", "sibling", "parent", "external", "builtin"]}] you would have eg. : "import-order/import-order": [2, {"order": [
[ "builtin", "external" ], //first group
[ "index", "sibling", "parent" ] //second group
}] Having it configured that way gives you huge amount of flexibility and IMHO is still very readable. |
Yeah, you should hold ;)
Sure, I'm fine with it (as long as it's not a default). The name can a bit shorter, like
I thought of the same thing, and I like it. The only downside I see, is that it loosens the rule schema, and unexpected arguments can then slip in. Other than that, I think this is nice. (cc @sindresorhus who might be interested in the discussion) |
What kind of arguments do you have in mind? |
Right now, The |
@jfmengels Ah, got it. Currently I cannot think of a better way of defining those groups, but maybe I will figure out something in the meantime. Hey @lo1tuma, we could use your expertise here - could you help ?:) |
What about making a separate rule for import grouping, e.g. Which could be configured as So the following would be considered as a problem: import url from 'url';
import express from 'express'; // <-- missing new line after this statement
import foo from './foo'; This would not be considered as a problem: import url from 'url';
import express from 'express';
import foo from './foo';
import http from 'http'; As you can see this rule doesn’t care about the import order, so there are two import groups that import builtin modules, but they are still separated by a new line. This would also supercede #245 when configured with only on group including all types of imports |
I feel that a new rule would need to have almost all of the same logic that is in import url from 'url'; // <-- missing new line after this statement
import bar from './bar'; // <-- missing new line after this statement
import express from 'express'; // <-- missing new line after this statement
import foo from './foo'; // <-- missing new line after this statement
foo(); Also, I don't see why someone would want to have the newline rule on and not |
Well the logic could be extracted to a separate file which could be used by both rules.
Personally I also don’t have this need but I could imagine that some people don’t care about the order but just want to visually separate the different kind of groups. |
Absolutely.
Me neither. I would actually prefer to have a rule that disallows empty lines between imports.
If we take the following invalid example: import url from 'url'; // <-- missing new line after this statement
import bar from './bar'; // <-- missing new line after this statement
import express from 'express'; // <-- missing new line after this statement
import bar from '/bar';
import foo from './foo'; // <-- missing new line after this statement
foo(); the valid, fixed (without re-ordering) version would be this: import url from 'url';
import bar from './bar';
import express from 'express';
import bar from '/bar';
import foo from './foo';
foo(); which doesn't make much sense IMO. There are separations between "groups", but they just feel kind of random. |
As we're trying to enforce formatting rules for imports like below:
this is addition to previously created #245. I have doubts about option name though - it is in fact some kind of visual grouping, yet it doesn't speak to me in 100%.