-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow enforcement of import-specifiers #1787
Comments
While eslint’s included import { x, y, z, type A, type B, type C } from "./mod"; But I haven’t found an eslint rule capable of enforcing this style in my brief search so far. I had thought I might find it in this plugin, since it does recognize |
Does the typescript-eslint plugin have a sort-imports rule that covers it? |
No, I couldn’t find anything related in typescript-eslint. |
@bradzacher do you think this would make sense in the TS eslint plugin? |
I think that it makes more sense in this repo so we don't "compete" on rules. I've been trying to draw the line of "if you're encoding TS-specific semantics about imports in a rule, typescript-eslint, otherwise, import-js" Which is why I've added/proposed things over here instead of in our repo. |
Makes sense in general; since |
Yeah we have done it in the past with We're removing our extension in the next major and directing people towards your rule instead. So this would be the same case - instead of adding an extension rule to add support for |
I think we (the TypeScript team) would be pretty interested in having an option for this. When we migrated our codebase to modules, we enabled the core |
The other thing I noticed about eslint's base Example: import {
b,
a,
} from './module'; gets sorted to -> import {
a,
b,
} from './module'; |
For the time being, you might want to use |
@basicdays it's very unfortunate that eslint won't make changes to stylistic rules anymore, or else that would be a perfect place for that modification to be made. Does anyone have a concrete suggestion for adding an option that would govern sorting of named imports within curly braces, whether single or multi-line? Note that with multiline, comment attachment becomes quite tricky wrt autofix. |
It does use the actual |
oof, then I would strongly avoid it, since the tool's been deprecated (and afaik, unmaintained) for 4 years. |
I would recommend using the same sort order that const comapre = new Intl.Collator("en", {
sensitivity: "accent",
caseFirst: "upper",
numeric: true,
}).compare; Which is to say "sort case-insensitively with natural numbers, tie breaking with plain string comparison". We're actually looking to even this behavior out across tooling and get TS's organize import to be able to handle them evenly (via some preset mechanism). That, and, ignore the All in all, it's easiest to just play around with https://dprint.dev/playground/#code/Q/language/typescript which should show what I'm meaning. |
@jakebailey sometimes people want ascending, sometimes descending; using Intl would be a fine implementation suggestion if we could use it, but we can't because we support older nodes than where it's available. I'm asking about the schema for this option. |
Who wants descending?
Er, wouldn't that depend on its functionality and implementation? e.g. TS only had a couple of knobs, but has gained a few more (hidden for now) in 5.0, and may gain a couple more in the future as we refine it to try and accept the various different sorting mechanisms. |
I think the same settings like the ones mentioned in
I think we could even apply the same default settings as the Not sure about the name, though... what about |
huh, good call, i didn't realize Intl was available in node 0.12, for some reason I thought it was only available by default in v12. I would assume that the hope would be to design the entirety of the functionality before adding it, and I agree with @manuth that the same settings makes sense. |
Checking MDN, the API is available, but only supported |
Imports can have multiple specifiers (objects which are being imported).
Would be awesome if there would be a way to enforce alphabetization there, too:
Example:
The text was updated successfully, but these errors were encountered: