Skip to content
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

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

Merged

Conversation

MQuy
Copy link
Contributor

@MQuy MQuy commented Mar 19, 2022

Closes #41494.

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

when organizing imports in each block of newline-contiguous

import c from "C";

import d from "D";
import a from "A";
import b from "B";

turns into

import c from "C";

import a from "A";
import b from "B";
import d from "D";

@typescript-bot

This comment was marked as outdated.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 19, 2022
@MQuy MQuy force-pushed the feature/create-sort-groups-by-newlines branch from ff8df38 to b89f697 Compare March 19, 2022 00:38
@typescript-bot typescript-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
Copy link
Member

@jakebailey jakebailey left a comment

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:

// polyfill
import "lib"
// not polyfill
import { b } from "lib2"

or say

import "lib" // xyz

import c from "C"

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

src/services/organizeImports.ts Outdated Show resolved Hide resolved
src/services/organizeImports.ts Outdated Show resolved Hide resolved
src/services/organizeImports.ts Outdated Show resolved Hide resolved
src/services/organizeImports.ts Outdated Show resolved Hide resolved
@MQuy MQuy force-pushed the feature/create-sort-groups-by-newlines branch from fd96817 to 2c13fec Compare March 28, 2022 21:08
src/services/organizeImports.ts Outdated Show resolved Hide resolved
src/services/organizeImports.ts Outdated Show resolved Hide resolved
@MQuy MQuy force-pushed the feature/create-sort-groups-by-newlines branch from aa759f0 to 24e4cd9 Compare April 5, 2022 17:46
@MQuy MQuy force-pushed the feature/create-sort-groups-by-newlines branch from f594067 to bd8ce22 Compare April 5, 2022 18:03
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
@jakebailey jakebailey merged commit 6e0447f into microsoft:main Apr 5, 2022
@DanielRosenwasser DanielRosenwasser changed the title [Feature] - Automatically create sort groups based on newlines Automatically create sort groups based on newlines in organize imports Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs 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
4 participants