-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Organize type imports #55269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Organize type imports #55269
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
14afb68
add organizeImports option to sort types first, last, or inline
iisaduan f44793d
Merge branch 'main' of https://github.com/iisaduan/TypeScript into or…
iisaduan e720377
update tests
iisaduan 3652bce
change detection to account for type ordering
iisaduan ee32e43
add tests for autoimports
iisaduan d47d1b6
Merge branch 'main' of https://github.com/iisaduan/TypeScript into or…
iisaduan bb47232
update baselines
iisaduan 44b07dd
Merge auto-import-type
iisaduan 4a83f8c
change default order to "last"
iisaduan 489e92a
add types to detection, adjust tests accordingly
iisaduan 11929fe
fix potential organizeImports chaining in test calls
iisaduan 63dcdb6
Merge branch 'main' of https://github.com/microsoft/TypeScript into o…
iisaduan 4560a6b
post-merge bug fix
iisaduan 42033fc
fixed tests and verify.importFixes
iisaduan dca9ba6
fix verifyImportFixAtPosition
iisaduan d408f5a
add comments
iisaduan 7902488
update baselines
iisaduan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @verbatimModuleSyntax: true | ||
// @target: esnext | ||
|
||
// @Filename: /foo.ts | ||
//// export const A = 1; | ||
//// export type B = { x: number }; | ||
//// export type C = 1; | ||
//// export class D = { y: string }; | ||
|
||
// @Filename: /test.ts | ||
//// import { A, D, type C } from './foo'; | ||
//// const b: B/**/ | C; | ||
//// console.log(A, D); | ||
|
||
goTo.marker(""); | ||
|
||
// importFixes should only place the import in sorted position if the existing imports are sorted as specified, | ||
// otherwise the import should be placed at the end | ||
verify.importFixAtPosition([ | ||
`import { A, D, type C, type B } from './foo'; | ||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "inline" } | ||
// `type B` is added to the end since the existing imports are not sorted as specified | ||
); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, D, type B, type C } from './foo'; | ||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "last" } | ||
// `type B` is added to the sorted position since the existing imports *are* sorted as specified | ||
); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, D, type C, type B } from './foo'; | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "first" } | ||
// `type B` is added to the end (default behavior) since the existing imports are not sorted as specified | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @verbatimModuleSyntax: true | ||
// @target: esnext | ||
|
||
// @Filename: /foo.ts | ||
//// export const A = 1; | ||
//// export type B = { x: number }; | ||
//// export type C = 1; | ||
//// export class D = { y: string }; | ||
|
||
// @Filename: /test.ts | ||
//// import { A, type C, D } from './foo'; | ||
//// const b: B/**/ | C; | ||
//// console.log(A, D); | ||
|
||
goTo.marker(""); | ||
|
||
// importFixes should only place the import in sorted position if the existing imports are sorted as specified, | ||
// otherwise the import should be placed at the end | ||
verify.importFixAtPosition([ | ||
`import { A, type B, type C, D } from './foo'; | ||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "inline" } | ||
); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, type C, D, type B } from './foo'; | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "last" } | ||
); | ||
|
||
verify.importFixAtPosition([ | ||
`import { A, type C, D, type B } from './foo'; | ||
const b: B | C; | ||
console.log(A, D);`], | ||
/*errorCode*/ undefined, | ||
{ organizeImportsTypeOrder: "first" } | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this one turn out to have C first? The next one doesn't which feels odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's adding
type B
and it's determined that the types are unsorted (since it specifiedinline
), it adds it on to the end. If the imports were unsorted before, it would always add onto the end, otherwise it might add the import somewhere weird in the middle, since we're not changing the order of the rest of the imports