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

Support 'Organize Imports' feature #10020

Closed
akosyakov opened this issue Jul 29, 2016 · 16 comments
Closed

Support 'Organize Imports' feature #10020

akosyakov opened this issue Jul 29, 2016 · 16 comments
Assignees
Labels
Domain: Organize Imports Issues with the organize imports feature Domain: Refactorings e.g. extract to constant or function, rename symbol Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue

Comments

@akosyakov
Copy link

It should:

  • remove unused imports;
  • remove duplicate imports;
  • add imports for unresolved elements;
  • ask a user to disambiguous imports in the case if several can be used for an unresolved element.
@basarat
Copy link
Contributor

basarat commented Jul 29, 2016

Personal Opinion: Nice idea for quickfixes / additional refactorings to be added into release 2.1 : https://github.com/Microsoft/TypeScript/wiki/Roadmap#21 🌹

@waderyan waderyan added the VS Code Tracked There is a VS Code equivalent to this issue label Nov 2, 2016
@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol labels Nov 21, 2016
@johnnyreilly
Copy link

I'd love to see this implemented.

@akosyakov
Copy link
Author

It would be also nice if this feature respects index.ts files and imports stuff with the shortest possible import declaration.

@niklas-dahl
Copy link

would be awesome if it could unite imports, too.

from

import { Component } from '@angular/core';
import { Input } from '@angular/core';

to

import { Component, Input } from '@angular/core';

@RyanCavanaugh
Copy link
Member

@MgSam
Copy link

MgSam commented Feb 16, 2018

It would also be great if this feature alphabetized both the objects inside the import {} brackets and the import lines themselves (by file path).

So this:

import { Foo, Bar } from './banana';
import { Dog, Cat } from './apple';

becomes this:

import { Cat, Dog } from './apple';
import { Bar, Foo } from './banana';

@pelotom
Copy link

pelotom commented Feb 16, 2018

TSLint has a rule for this: ordered-imports. And it’s auto-fixable.

@jbrownson
Copy link

It'd be nice if it were inserted in order in the first place so it didn't require the extra auto-fix steps

@madhugb
Copy link

madhugb commented Feb 21, 2018

Right now sort will put the imports on top of the document, and it moves the comments / copyright / author info to the bottom of imports.

Is there a way to preserve the comments on top of the document?

@amcasey
Copy link
Member

amcasey commented Feb 21, 2018

@jbrownson, sort on import is covered by #16119.

@amcasey
Copy link
Member

amcasey commented Feb 21, 2018

@madhugb How are you sorting? I didn't think any of the editors had shipped a version consuming the new organizeImports protocol command.

@amcasey
Copy link
Member

amcasey commented Feb 21, 2018

@MgSam I believe that was covered by #21909.

@amcasey
Copy link
Member

amcasey commented Feb 21, 2018

@niklas-dahl I believe that was covered by #21909.

@amcasey
Copy link
Member

amcasey commented Feb 21, 2018

@akosyakov at present, we're retaining module specifiers as-is. Would you mind filing a new issue suggesting they be simplified when possible?

@amcasey
Copy link
Member

amcasey commented Feb 21, 2018

Also note that adding missing imports is being handled separately using code fixes (which should support fix-all).

@akosyakov
Copy link
Author

@amcasey Are you referencing to shortening imports? As now it works quite nicely for us, except when imports are inserted as . or .., it would be better to ignore index.ts in such cases.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 27, 2018
@mhegazy mhegazy added the Domain: Organize Imports Issues with the organize imports feature label Mar 27, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: Organize Imports Issues with the organize imports feature Domain: Refactorings e.g. extract to constant or function, rename symbol Fixed A PR has been merged for this issue Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests