ggascoigne / prettier-plugin-import-sort

Prettier plugin to pass javascript and typescript through import-sort
MIT License
110 stars 11 forks source link

Configuration and editors #20

Closed tony closed 3 years ago

tony commented 3 years ago

When I tried this with vim and VSCode, the settings for importSort give different results than running vim through CLI

I think it could have to do with #11 but not sure.

We use the https://github.com/unsplash/import-sort-style-unsplash as an import style, e.g.

{
  "importSort": {
    ".js, .jsx, .ts, .tsx": {
      "style": "unsplash" 
    }
  }
}

Has anyone else had luck getting the settings to work with their editor?

ggascoigne commented 3 years ago

You're not really saying what's not working, or which command line you are talking about. But to answer your question, yes, I use this with the module style in my editor all of the time and it gives the same results as running prettier from the command line.

tony commented 3 years ago

Are there any commands you know where I could provide more diagnostic information? I'd be happy to provide more info!

It spent 2+ hours reading through the code of this and import-sort. It's not obvious where and how settings get applied to import-sort. I think the issue stems from import-sort's configuration having a lot of magic.

I use this with the module style in my editor all of the time and it gives the same results as running prettier from the command line.

That's good!

Any more details? Editor? What sort of setup is involved? Just running prettier via a plugin, or does it run import-sort separately after?

What does the project configuration look like (between this plugin and prettier)?

ggascoigne commented 3 years ago

well I'm using it in IntelliJ rather than VSCode, I've tested it in VSCode but don't actively use it.

That said, there are a couple of things that might be worth digging into related to working directly.

I'm pretty sure that the VSCode plugin assumes that the package.json and the node_modules will be loaded from the root folder of the project - if that's not the case for you, then you'll likely need to do something about that.

tony commented 3 years ago

I'm pretty sure that the VSCode plugin assumes that the package.json and the node_modules will be loaded from the root folder of the project - if that's not the case for you, then you'll likely need to do something about that.

I verified that - it looks fine, I believe.

This really looks like a PR needs to be made for the import-sort-config package, it needs to somehow:

  1. Trace where and how the config is being resolved (e.g. set an env variable to output it maybe)
  2. Accept options directly (no side effects, like a old-fashioned API function)

In order to solve the first part I will take a look at how eslint/babel/prettier/etc resolves their configs. I'm assuming hopefully they have a sane way of doing that.

As for what to do with this card - do you want to close it? Keep it open to see if anyone else comes by with input?

ggascoigne commented 3 years ago

I'll leave it open for now - as you said it might help someone. But yes, all in all there's very little in the plugin and most everything else is in the import-sort package itself.