prettier-plugin-organize-imports: 3.0.1 incorrectly deleting required imports from typescript files
Hi,
The 3.0.1 update seems to be incorrectly deleting required imports.
The following code demonstrates the issue:
If I have TypeScript:
import { NormalizedCacheObject } from 'apollo-cache-inmemory'
import AWSAppSyncClient from 'aws-appsync'
export class Foo {
public constructor(private readonly appSyncClient: AWSAppSyncClient<NormalizedCacheObject>) {}
getClient(): any {
return this.appSyncClient
}
}
with package.json
{
"name": "scratch",
"version": "1.0.0",
"main": "index.js",
"license": "UNLICENSED",
"private": true,
"scripts": {
"prettier": "prettier --list-different \"**/*.{json,js,ts,yml,}\""
},
"resolutions": {
"apollo-cache-inmemory": "^1.6.6"
},
"devDependencies": {
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.0.1",
"typescript": "^4.7.4"
},
"dependencies": {
"apollo-cache-inmemory": "^1.6.6",
"aws-appsync": "^4.1.7"
}
}
then the import:
import AWSAppSyncClient from 'aws-appsync'
is flagged as needing to be deleted.
If I use 3.0.0 then the import is not flagged.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 18 (7 by maintainers)
Thanks for replying, the performance regression is being tracked in #67 now. Should be able to get a fix out today.
We have a similar issue when trying to upgrade from
3.0.0to3.0.1. Here is a minimal reproduction:Create an app using
npx create-react-app organize-bug --template typescriptInstall prettier:
npm i prettier prettier-plugin-organize-importssrc/models/Tip.tssrc/App.tsxprettier-plugin-organize-importsremovesimport { Tip as TipModel } from "./models/Tip":My issue is completely resolved with good performance with 3.0.3 - thamks @simonhaenisch !
Btw @askielboe, to not get the
Reactimport removed as unused, you’ll have to change thejsxoption in tsconfig toreact(see TS handbook). Or, if you leave it asreact-jsx, it’s actually fine to have the import removed because it’s really not needed. I’ve tried and it builds and works fine without theReactimport.Will do on monday