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

Organize imports should remove blank lines within imports #22914

Open
mjbvz opened this issue Mar 27, 2018 · 9 comments
Open

Organize imports should remove blank lines within imports #22914

mjbvz opened this issue Mar 27, 2018 · 9 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: Organize Imports Issues with the organize imports feature Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Mar 27, 2018

TypeScript Version: 2.9.0-dev.20190327

Search Terms:

  • Organize imports

Code

  1. For the js:
import { x } from 'x';


import { y } from 'y';

console.log(x, y)
  1. Run organize imports.

Expected behavior:
Blank lines within the import are removed

import { x } from 'x';
import { y } from 'y';

console.log(x, y)

Actual behavior:
Blanklines preserved but shifted to end of imports:

import { x } from 'x';
import { y } from 'y';



console.log(x, y)
@mhegazy mhegazy added the Suggestion An idea for TypeScript label Mar 27, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Mar 27, 2018
@mhegazy mhegazy added the Domain: Organize Imports Issues with the organize imports feature label Mar 27, 2018
@Horaddrim
Copy link

Just to makes dure, I'm New gere, it's approved for community to help on this onde? Evento without the label 😕

@Horaddrim
Copy link

Sorry, my auto complete feature fault, I'm new here, and we can help on this one? Even without the label?

@AlCalzone
Copy link
Contributor

Out of interest: How should this behave if there's something else between the imports? I usually structure my code in test suites in two blocks: 1. framework-related imports, 2. component related imports, e.g.:

import { assert, expect, should } from "chai";
// ... more framework-related imports
// enable the should interface with sinon
should();

// ^^^ --- I want the space here --- vvv

import * as nodeUrl from "url";
// ... more component-related imports

@Horaddrim
Copy link

@AlCalzone I do this too, and in my regular files too, I think it's cool to stay 👍

@mhegazy mhegazy removed this from the TypeScript 2.9 milestone Apr 26, 2018
@mhegazy mhegazy added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label Apr 26, 2018
@marcelh-gh
Copy link

I agree that the current behavior of moving blank lines to the end of the imports is not helpful.
But removing them in general is also not always desired. I like to group my imports using blank lines.
For example one block of imports could be related to DB stuff and another one to features from math libraries.

Maybe the removal of blank lines could be optional via a config flag?

@tschundler
Copy link

I also group my imports with space between them. (libraries/frameworks vs my own code)
Keeping the groups would be helpful, but moving the blank lines to the bottom is never useful. So I think a reasonable behavior is a flag to preserve space. If true, imports are pruned as usual, but sorting is only done within contiguous blocks and any comments / empty lines are kept as-is.

If preserveSpace is false, then it behaves like it does now, but removing empty lines rather than collecting them at the bottom.

@PeterStaev
Copy link

+1 to have a flag to allow keeping spaces/groups.

@jakebailey
Copy link
Member

After #41494 and #48330, we no longer move imports between groups, so the original repro here is no longer valid. That being said, we don't remove blank lines between groups, so this isn't entirely closable.

@codesman
Copy link

codesman commented Aug 3, 2023

In my experience manually organizing imports by grouping is a maintenance burden that has little value and creates another thing to disagree about. It's a bit easier if the tooling supports it but especially cumbersome when there is also sorting based on some arbitrary hierarchy of importance to the team or individual that birthed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: Organize Imports Issues with the organize imports feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests