Skip to content
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

feat: Opinionated import order #1332

Closed
rortan134 opened this issue Apr 3, 2023 · 12 comments · Fixed by #1392
Closed

feat: Opinionated import order #1332

rortan134 opened this issue Apr 3, 2023 · 12 comments · Fixed by #1392
Labels
🌟 enhancement New feature or request

Comments

@rortan134
Copy link

Is your feature request related to a problem? Please describe.

Is there any plans on creating an opinionated prettier import auto-sorter for the t3 base template?

Describe the solution you'd like to see

Something like @trivago/prettier-plugin-sort-imports or @ianvs/prettier-plugin-sort-imports would be very nice to have already set-up.

Code_656t1Kovbi

Describe alternate solutions

Import order structure example:

importOrder: [
        "^react",
        "^next/*",
        "<THIRD_PARTY_MODULES>",
        "",
        "^@/components/(.*)$",
        "^@/utils/(.*)$",
        "",
        "^@/lib/(.*)$",
        "",
        "^[./]", // local files
        "^@public/*", // root/public
    ],

Additional information

No response

@rortan134 rortan134 added the 🌟 enhancement New feature or request label Apr 3, 2023
@c-ehrlich
Copy link
Member

I think I'm in favor of this. It's something I have in all of my non trivial projects. We would need to make it work with the custom base path, but that should be doable.

I guess the argument against is "user can add it", and we tend to stay away from opinionated linting/formatting by default. Curious to see what others think.

@PiotrekPKP
Copy link
Contributor

I'd love to see that!

It made managing imports in my projects 100 times better and the only reason I usually don't have it in them is that I'm too lazy to install it 🤷

@juliusmarminge
Copy link
Member

I'm very pleased with ianvs sorter. Works a lot better than trivago, especially if you take into account "use client" / "use server" directives in upcoming RSC and Server Actions.

@FinnDore
Copy link
Contributor

FinnDore commented Apr 4, 2023

I think cta turbo indoctrinationated me here since I add this to all my projects.

Re the custom paths. Maybe we could read the file replace a certain string in the file and write the file back out.

E.g

"<IMOPORT-ALIAS>"

@juliusmarminge
Copy link
Member

We wouldn't need to do a custom sort order, the default from ianvs is enough and if devs want their own they can add themselves. Just having the plugin and some basic rules (like no duplicates etc) goes a long way for consistency and keeping git diffs small

@FinnDore
Copy link
Contributor

FinnDore commented Apr 4, 2023

Oh that's true tbf

@ronanru
Copy link
Contributor

ronanru commented Apr 8, 2023

I like prettier-plugin-organize-imports. It uses TypeScript LSP to sort imports.

@iAverages
Copy link
Contributor

I'd definitely like to see this added :)

@its-monotype
Copy link

@FinnDore
Copy link
Contributor

Is someone doing this, i see a couple of prs but not much movement. i can bash a pr out today if people want?

@FinnDore
Copy link
Contributor

So something i forgor was that the default cta app does not incude prettier. so do we only want to include this if they chose tailwind?

@FinnDore
Copy link
Contributor

not technically closed yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants