trivago / prettier-plugin-sort-imports

A prettier plugin to sort imports in typescript and javascript files by the provided RegEx order.
Apache License 2.0
3.28k stars 129 forks source link

Prettier > 3 doesn't work #245

Closed mike667 closed 1 year ago

mike667 commented 1 year ago

Hello maintainers, thank you for amazing package. Could you help me with my issue?

Your Environment

Describe the bug Sort doesn't work with prettier 3.0.0.

I use latest version. "@trivago/prettier-plugin-sort-imports": "^4.2.0". When I update prettier to version 3.0.0 sorting silently stop working, after rollback to v2.8.8 everything works as expected.

My .prettierrc

{
    "importOrder": [
        "^(common|components)(.*)$",
        "^data-service(.*)$",
        "^(hooks|utils|context)(.*)$",
        "^(constants|themes|route-urls)(.*)$",
        "^../(.*)$",
        "^./(.*)$"
     ],
    "importOrderSeparation": true,
    "importOrderSortSpecifiers": true
}
timgcarlson commented 1 year ago

I'm also encourting this issue with prettier 3.0.0. To resolve I had to downgrade back to 2.8.8, and also had to downgrade eslint-plugin-prettier to 4.2.1 (from 5.0.0).

Rhym commented 1 year ago

I migrated to https://github.com/IanVS/prettier-plugin-sort-imports, and it has been great.

sascha-kaleidoscode commented 1 year ago

I only added

plugins: ['@trivago/prettier-plugin-sort-imports']

to my configuration and it works just fine.


If you are using VS Code you may need to restart the ESLint Server

pallymore commented 1 year ago

Hi looks like we just need to specify this plugin in the prettierrc file.

// .prettierrc
plugins: ['@trivago/prettier-plugin-sort-imports']
FrancescoSaverioZuppichini commented 1 year ago

what is prettierrc? I have prettier.config and If I run prettier --write app the imports do not get sorted - thanks a lot

pallymore commented 1 year ago

what is prettierrc? I have prettier.config and If I run prettier --write app the imports do not get sorted - thanks a lot

https://prettier.io/docs/en/configuration.html

yep sorry it should be the prettier config file (we picked the filename .prettierrc ) - it works fine for us once we added this to the plugins field.

smenshikov commented 1 year ago

Probably this trick about plugins: ['@trivago/prettier-plugin-sort-imports'] should be described in README until the problem is solved

mike667 commented 1 year ago

Thank you @pallymore

FrancescoSaverioZuppichini commented 1 year ago

what is prettierrc? I have prettier.config and If I run prettier --write app the imports do not get sorted - thanks a lot

https://prettier.io/docs/en/configuration.html

yep sorry it should be the prettier config file (we picked the filename .prettierrc ) - it works fine for us once we added this to the plugins field.

Thanks a lot for the reply. I apologies, I am a noob here - could you give me a little more context or just a couple of steps I need to do 😃

austinschrader commented 1 year ago

This worked for me as well, with a tweak. My .prettierrc is written in JSON so the plugin had to be formatted as below shows.

Full .prettierrc for reference

{
    "singleQuote": true,
    "importOrder": [
        "<THIRD_PARTY_MODULES>",
        "^@internal/(.*)$",
        "^[./].*(?<!\\.(c|le|sc)ss)$",
        "^[.]/[-a-zA-Z0-9_]+[.](module)[.](css|scss|less)$"
    ],
    "importOrderSeparation": true,
    "importOrderSortSpecifiers": true,
    "printWidth": 120,
    "plugins": [
        "@trivago/prettier-plugin-sort-imports"
    ]
}
dominictobias commented 5 months ago

Hi looks like we just need to specify this plugin in the prettierrc file.

// .prettierrc
plugins: ['@trivago/prettier-plugin-sort-imports']

Would be handy if this was in the readme, well it kinda is but it's not clear to me that this should go in the prettier file, it looked like it was some special config file for some pnpm issue

eagleeyejack commented 4 months ago

Might be late to the party with this one but just restarting my IDE did the trick, classic 😅