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

Suggestion: Show unused imports in VS Code Editor as grayed #8165

Closed
ghost opened this issue Apr 19, 2016 · 16 comments · Fixed by #22361
Closed

Suggestion: Show unused imports in VS Code Editor as grayed #8165

ghost opened this issue Apr 19, 2016 · 16 comments · Fixed by #22361
Labels
API Relates to the public API for TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@ghost
Copy link

ghost commented Apr 19, 2016

I do a refactory of a large project. I split large modules into smaller ones.
So when i move imports to a new module i want to remove unused imports.
This can not be done easily as i click in context menu "Find All references" it shows all the references in the current project - "it is very unuseful i admit".

So, if it is by design, then this problem can be ameliorated by showing unused imports as grayed.

@s-panferov
Copy link

@BBGONE have you tried to use tslint and corresponding editor plugin? It can highlight unused imports.

@ghost
Copy link
Author

ghost commented Apr 19, 2016

@s-panferov Thanks, i did not try, yet. It will be very helpful in my case.

@mhegazy mhegazy added Suggestion An idea for TypeScript API Relates to the public API for TypeScript labels Apr 19, 2016
@donaldpipowitch
Copy link
Contributor

I think this would be solved if noUnusedParameters and noUnusedLocals would be shown as warnings, not as errors. See for example #13408.

@ghost
Copy link
Author

ghost commented Mar 1, 2017

in fact noUnusedParameters and noUnusedLocals behave very rough.
For example i have a code like this:

obj.addOnPropertyChange("*", function (s, a) {
           if (props.indexOf(a.property) > -1) {
               fn_onChange(a.property);
           }
       }, self.uniqueID);

where the s parameter is not used, but it's not an error. I can not remove it because it's the function's signature and is required, and it's not the last parameter which i can not simply ommit.
Another problem when i declare an abstract class which members should be overriden. It's member functions have some parameters which is not used, but are used when overriden.
So these compiler options should account for the above situations.

@donaldpipowitch
Copy link
Contributor

donaldpipowitch commented Mar 1, 2017

Regarding:

obj.addOnPropertyChange("*", function (s, a) {
           if (props.indexOf(a.property) > -1) {
               fn_onChange(a.property);
           }
       }, self.uniqueID);

Yeah, that's why it should be warning and not an error. (And maybe not even a warning in this case.)

By the way you can "fix" this by writing _s instead of s. Now TypeScript will just ignore it.

@demisx
Copy link

demisx commented Dec 17, 2017

Though, version 1.19 underlines unused symbols in the imports now I wish the entire import was greyed out similar to other IDEs. That would make such imports easier to spot.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 10, 2018

@andy-ms this is related to the non-error suggestions feature.

@vytautas-pranskunas-
Copy link

any progress on this?

@DavidVotrubec
Copy link

I am looking forward this feature too

@ghost
Copy link
Author

ghost commented Feb 16, 2018

now, for me it's all ok when unused imports is an error. If there's an error, i just remove the unused import.

@demisx
Copy link

demisx commented Feb 16, 2018

We would rather have it as a grayed warning. Errors break the build.

@ghost ghost added the Fixed A PR has been merged for this issue label Mar 12, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.8.1, TypeScript 2.8.2, TypeScript 2.9 Mar 22, 2018
@erzhtor

This comment has been minimized.

@ghost ghost closed this as completed in #22361 Apr 5, 2018
@mm420admin

This comment has been minimized.

@marioteik

This comment has been minimized.

@mjbvz
Copy link
Contributor

mjbvz commented May 17, 2018

Just merged in support for this into VS Code: microsoft/vscode#15710

Should be in tomorrows VS Code insiders. It is controlled by the settings:

"javascript.showUnused.enabled": true,
"typescript.showUnused.enabled": true,

@SerkanSipahi
Copy link

@mjbvz when it will be published for all?

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Relates to the public API for TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
12 participants