# Fix \`prettier-plugin-organize-imports\` plugin removes used imports \(\#9598\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/65152baa3f7a55b7a57030d7eef1f94640bb9afa)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 65152baa3f7a55b7a57030d7eef1f94640bb9afa

Requested commit: 65152baa3f7a55b7a57030d7eef1f94640bb9afa

Commit: 65152baa3f7a55b7a57030d7eef1f94640bb9afa

Tree: 572a1aafb921c3186738f55535ddf0236994314b

Author: Remco Smits

Committer: GitHub

## Message

````
Fix `prettier-plugin-organize-imports` plugin removes used imports (#9598)

### Issue
So this pull request fixes an issue that was driven me crazy. The issue
was that when you use the `prettier-plugin-organize-imports` It would
remove some imports that should not be removed before they were used
inside the module itself.

You can reproduce it with the following `prettierrc.json` config and
source code. When you **save** the file, it would remove the `import
clsx from "clsx";` import from the file.

**Prettier config**
```json
{
  "semi": true,
  "tabWidth": 4,
  "trailingComma": "es5",
  "useTabs": true,
  "plugins": [
    "prettier-plugin-tailwindcss",
    "prettier-plugin-organize-imports"
  ]
}
```

**Source code**
```typescript
import clsx from "clsx";

export default function Home() {
  return (
      <main>
	      {clsx("asdjklasdjlkasd", "asdjlkasjdjlk")}
      </main>
  );
}
``` 

### Findings
After a deep dive with @mrnugget, I was debugging deep down the prettier
plugin system and found the issue that was causing this issue. When I
was looking inside the
`node_modules/prettier-plugin-organize-imports/lib/organize.js`. I saw
the following code that looked strange to me because it falls back to
`file.ts` if `filepath` is not passed through inside the prettier config
options.

<img width="860" alt="Screenshot 2024-03-20 at 21 31 46"
src="https://github.com/zed-industries/zed/assets/62463826/47177fe5-e5a9-41d8-9f2f-0304b2c2159f">

So the issue was small, if you look at the following code, the `path`
key should be `filepath` inside the
`crates/prettier/src/prettier_server.js:205`
![Screenshot 2024-03-20 at 21 35
25](https://github.com/zed-industries/zed/assets/62463826/1eea0a88-c886-4632-9c69-9f3095126971)

Release Notes:

- Fixed prettier integration not using the correct filepath when
invoking prettier, which could lead to some prettier plugins failing to
format correctly.
([#9496](https://github.com/zed-industries/zed/issues/9496)).
````

## Parents

- [65c6bfebdac7c6970e8de353bdcec5a1f5c5668a](https://git.cafe/gitcafe/zed/commit/65c6bfebdac7c6970e8de353bdcec5a1f5c5668a?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/65152baa3f7a55b7a57030d7eef1f94640bb9afa?format=markdown)
