-
Notifications
You must be signed in to change notification settings - Fork 25
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
Also sort the exports #119
Comments
@eduardodallmann unfortunately sorting exports could break code. For example: export const FooAPI = new MyAPI(args);
// export our default implementation separately
export const beAwesome = FooAPI.beAwesome: If you sorted this, your output would break! Obviously this is a trivial example, there’s tons of other ways to case moving around exports to be a problem. This is a neat idea, that might make sense in someone’s codebase, so I encourage you to to make a prettier-plugin-sort-exports library. I just think that’s out-of-scope for this library! |
You are correct. Sorting export lines can cause a lot of problems. But I believe that organizing just the de-structuring could be good. This plugin does that https://github.com/simonhaenisch/prettier-plugin-organize-imports |
There are potentially also cases where we could sort re-exports based on the source, which you show in your original example. I have some files in my own project which could benefit from that. But technically I think it might be difficult to achieve with the current way this plugin works, since exports can be spread throughout the file, whereas imports are always at the top (at least by convention, since they execute first). I'll take off the Thanks for mentioning prettier-plugin-organize-imports. I haven't looked into that one too closely, what are your impressions on the main differences between that library and this one, and are you currently using either one of them? |
I'm currently using the prettier-plugin-sort-imports lib. In my opinion it is much better because it is more like trivago but solves many of the problems. The only thing I like about prettier-plugin-organize-imports is organizing the export. I'm in a remix.run project, and by convention the routes have loader and action functions being exported. But to better separate and organize the codebase I did it this way:
login.server.ts
route.tsx
|
I'm looking exactly for something like this, but there are not maintained libraries at the moment, and honestly, I don't understand why. |
@SalahAdDin, are you looking for sorting exports, or only re-exports from other files? |
Sorting exports, We don't have to go to every file and sort them manually hahahahaha. |
I mean, do you want to sort all exports? If a file exports two functions and a constant, you want to sort those? Or only sort re-exports like this? export foo from "./foo"; |
Not re-export, the file exports, that is the most common use for the export function (i think). |
Can you give an example of a before and after? |
Input:
Ouput:
|
ok, so just the specifiers within a named export block, got it. I think that could potentially be doable, but it would need to be placed behind a new option, defaulted to false, to avoid unexpected changes. I don't have time to work on it right now, but I'd be willing to review a PR if someone else wants to take a shot. If anyone plans to work on it, let us know and we can discuss the details. |
Yes, re-exports should also be sorted just like |
Is your feature request related to a problem?
Sort also export not just imports.
Describe the solution you'd like
When I have code like that:
To be sorted like that:
Describe alternatives you've considered
None
Additional context
Related: trivago/prettier-plugin-sort-imports#159
The text was updated successfully, but these errors were encountered: