-
Notifications
You must be signed in to change notification settings - Fork 71
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
hyphens and slashes ordered differently than with dprint #127
Comments
Hi! Previous issue about this, in case you are curious: #87 and #91
I’m just trying to understand your case. Is it like this?
If that’s correct, then yes, I think it could make sense to mention this in the readme! |
Hi! Thank you for your response & sorry for the dupe, I just searched the issue tracker for "dprint". 🙂 And you're right that it's perfectly documented, I somehow didn't find that but used GitHub code search to discover it... Yes, that's mostly correct, except the order: In retrospect I'm not sure why it was so hard to find the option in dprint's documentation. 😅 |
@jakebailey Is this a problem for your “sorting consistency between TypeScript, dprint and eslint-plugin-simple-import-sort” goal? (#124) That the tools might disagree about the order of these two: import { App } from 'app/app';
import { appInit } from 'app-init'; |
Testing TS 5.0 with:
Both dprint and TS's "sort imports" sort the above example like: import { appInit } from 'app-init';
import { App } from 'app/app'; But this plugin sorts it like: import { App } from 'app/app';
import { appInit } from 'app-init'; I'm a little confused because the above settings in TS 5.0 should match the plugin because both use |
Of course, the best setting for dprint when used with the plugin is probably to set it to maintain on all of the import/export related settings, which makes it match prettier (which won't move them at all). Though I do hope to be able to bulk-reformat using dprint and not have to run things back and forth between eslint and dprint to reach the steady state, so maybe it is a problem. So, from my perspective, the PR that adds the note is fine, but I am a little more concerned about TS and the plugin not agreeing for some reason (since I'm trying my best to get alignment so stuff like auto-imports agrees with the desired ordering). Thankfully this is probably a really uncommon case, unlike type imports. |
Just for reference, this is effectively what TS is setting with the above config: ["app/app", "app-init"].sort(new Intl.Collator("en", {
sensitivity: "base",
caseFirst: "upper",
numeric: true,
}).compare) Which my console says is So the fact that the plugin is returning the opposite is curious. |
TypeScript is doing the reasonable thing; this plugin is the odd one out. I implemented the “ Last time this was reported, my answer was that it doesn’t matter what order punctuation is sorted in as long as it was stable. But now there’s seems to be a reason to change. |
@lydell FWIW I think your way with special handling of But yeah not going against TS might be more pragmatic, ultimately. |
Yeah, it's tricky; I think I'd actually expect them to be sorted by first splitting on slashes, then sorting them in pieces, but that's not what this new (still unstable) TS feature does, as well as dprint (probably because such a thing is slow). Thankfully I think this sort of thing is rare. I'm planning on investing some time into checking all of these edge cases soon; I don't want to accidentally make the plugin change again only to be wrong and have to do another release, so feel free to leave the behavior and suggest disabling dprint instead. |
Is there a way I can play around with the new sorting in TypeScript? I also noticed that this is sorted according to import a from "./a";
import React from "react"; But dprint sorts it as: import React from "react";
import a from "./a"; Lots of nuance here, it seems. |
Sure, you can set this in your user or workspace config: https://github.com/microsoft/TypeScript/pull/52090/files#diff-3bf027c5abb5653676adae4eb5c21ffc57cbf3b883b7b4ca691f356fde61e792 And then install the TS nightly extension in VS Code and ensure that the selected version is some version of 5.0 (there's a command palette command for selecting the version). I've just been checking out that PR and making a random file in the compiler folder and testing there. |
Feedback is welcomed; this isn't fully polished yet. |
If we have one import
foo/bar
and anotherfoo-bar
, this (excellent) plugin and dprint seem to have different opinions about the correct order of those.(In my case it was
{ App } from 'app/app'
and{ appInit } from 'app-init'
).I'm not saying that either is right, but the fix was a bit hard to find because the option isn't documented in dprint's TypeScript plugin.
My solution was set
"module.sortImportDeclarations": "maintain"
in dprint.json.Maybe a note in the README could be helpful, otherwise please feel free to close this as it can still be found by searching. And thank you for the nice plugin.
The text was updated successfully, but these errors were encountered: