You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When type reordering is active and a file has import { type SomeType }-imports, the top-of-file comment gets moved around.
When the type imports are sorted, the top-of-file comment stays put.
To Reproduce
test.ts:
/* * Copyright (c) 1234-5678 Some one. * * This is my top-of-file comment */importSomeThing,{typeSomeType}from'../SomeModule'importFunctionfrom'../Functions'import*asSomeUtilfrom'Some/Other/Module'importtypeFoofrom'../Foo'
gets formatted as
importtypeFoofrom'../Foo'importtype{SomeType}from'../SomeModule'import*asSomeUtilfrom'Some/Other/Module'importFunctionfrom'../Functions'importSomeThingfrom'../SomeModule'/* * Copyright (c) 1234-5678 Some one. * * This is my top-of-file comment */
test2.ts
/* * Copyright (c) 1234-5678 Some one. * * This is my top-of-file comment */importSomeThingfrom'../SomeModule'importFunctionfrom'../Functions'import*asSomeUtilfrom'Some/Other/Module'importtype{SomeType}from'../SomeModule'importtypeFoofrom'../Foo'
becomes
/* * Copyright (c) 1234-5678 Some one. * * This is my top-of-file comment */importtypeFoofrom'../Foo'importtype{SomeType}from'../SomeModule'import*asSomeUtilfrom'Some/Other/Module'importFunctionfrom'../Functions'importSomeThingfrom'../SomeModule'
test3.ts:
/* * Copyright (c) 1234-5678 Some one. * * This is my top-of-file comment */importSomeThingfrom'../SomeModule'importFunctionfrom'../Functions'import*asSomeUtilfrom'Some/Other/Module'import{typeSomeType}from'../SomeModule'importtypeFoofrom'../Foo'
becomes
importtypeFoofrom'../Foo'importtype{SomeType}from'../SomeModule'import*asSomeUtilfrom'Some/Other/Module'importFunctionfrom'../Functions'importSomeThingfrom'../SomeModule'/* * Copyright (c) 1234-5678 Some one. * * This is my top-of-file comment */
Expected behavior
I expected the top-of-file comment to stay put in all cases.
.prettierrc:
semi: falsesingleQuote: trueuseTabs: truetrailingComma: allprintWidth: 120plugins: ["@ianvs/prettier-plugin-sort-imports"]importOrder:
- ""# Enforce a blank line after top of file comments
- "<TYPES>"
- ""# Seperator
- "<THIRD_PARTY_MODULES>"
- ""# Separator
- "^[.]"importOrderParserPlugins: ["typescript", "decorators"]importOrderTypeScriptVersion: '5.7.3'
Error log
Contribute to @ianvs/prettier-plugin-sort-imports
I'm willing to fix this bug 🥇
The text was updated successfully, but these errors were encountered:
@fbartho it sounds like this only happens when sorting types, which that test case doesn't address. Sounds like we'll need to do some investigating. Thanks for the report, @max-m.
Looks like it’s more specific @IanVS — it’s not just sorting types, it’s when “unpacking” a combined “type and normal” import into separated types and normal sections.
I don’t use this case, but I bet the unpacking migration is where a missing piece of logic lives.
Any statements that aren’t present in the import-node tree after our sort operation fall to the bottom of all imports. In the case of “splitting” an import statement into two, the old import node is deleted, and the comment statement maybe attached to that import, so it’s considered forgotten, which is treated as if it’s a line of code in the file.
Your Environment
Describe the bug
When type reordering is active and a file has
import { type SomeType }
-imports, the top-of-file comment gets moved around.When the type imports are sorted, the top-of-file comment stays put.
To Reproduce
test.ts
:gets formatted as
test2.ts
becomes
test3.ts
:becomes
Expected behavior
I expected the top-of-file comment to stay put in all cases.
.prettierrc
:Error log
Contribute to @ianvs/prettier-plugin-sort-imports
The text was updated successfully, but these errors were encountered: