Skip to content

Automatically create sort groups based on newlines in organize imports - #48330

Merged
jakebailey merged 9 commits into
microsoft:mainfrom
MQuy:feature/create-sort-groups-by-newlines
Apr 5, 2022
Merged

Automatically create sort groups based on newlines in organize imports#48330
jakebailey merged 9 commits into
microsoft:mainfrom
MQuy:feature/create-sort-groups-by-newlines

Conversation

@MQuy

@MQuyMQuy commented Mar 19, 2022

Copy link
Copy Markdown
Contributor

Closes#41494.

Based on @RyanCavanaugh's suggestion #41494 (comment)

when organizing imports in each block of newline-contiguous

importcfrom"C";importdfrom"D";importafrom"A";importbfrom"B";

turns into

importcfrom"C";importafrom"A";importbfrom"B";importdfrom"D";

@typescript-bot

This comment was marked as outdated.

@typescript-bottypescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 19, 2022
@MQuy
MQuyforce-pushed the feature/create-sort-groups-by-newlines branch from ff8df38 to b89f697CompareMarch 19, 2022 00:38
@typescript-bottypescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Mar 28, 2022

@jakebaileyjakebailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks about right to me, but I think what I'd like to see are a few more tests to cover cases where there are comments, e.g., what is the behavior when we have something like:

// polyfillimport"lib"// not polyfillimport{b}from"lib2"

or say

import"lib"// xyzimportcfrom"C"

Or similar (this isn't exhaustive). I know the original issue had some code snippets that feature comments.

Comment threadsrc/services/organizeImports.ts Outdated
Comment threadsrc/services/organizeImports.ts Outdated
Comment threadsrc/services/organizeImports.ts Outdated
Comment threadsrc/services/organizeImports.ts Outdated
Comment threadsrc/services/organizeImports.ts Outdated
Comment threadtests/cases/fourslash/organizeImportsGroup_MultiNewlines.ts
@MQuy
MQuyforce-pushed the feature/create-sort-groups-by-newlines branch from fd96817 to 2c13fecCompareMarch 28, 2022 21:08
Comment threadsrc/services/organizeImports.ts Outdated
Comment threadsrc/services/organizeImports.ts Outdated
Comment threadsrc/services/organizeImports.ts Outdated
@MQuy
MQuyforce-pushed the feature/create-sort-groups-by-newlines branch from aa759f0 to 24e4cd9CompareApril 5, 2022 17:46
@MQuy
MQuyforce-pushed the feature/create-sort-groups-by-newlines branch from f594067 to bd8ce22CompareApril 5, 2022 18:03
Comment threadsrc/services/organizeImports.ts Outdated
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Comment threadsrc/services/organizeImports.ts Outdated
@jakebailey
jakebailey merged commit 6e0447f into microsoft:mainApr 5, 2022
@DanielRosenwasserDanielRosenwasser changed the title [Feature] - Automatically create sort groups based on newlinesAutomatically create sort groups based on newlines in organize importsApr 6, 2022
@microsoftmicrosoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog BugPRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Feature request: disable organize import on specific lines

5 participants

@MQuy@typescript-bot@jakebailey@RyanCavanaugh@sandersn