Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

The implementation of the 'no-unused-variable' rule breaks the tslint language service plugin #2649

Closed
egamma opened this issue Apr 28, 2017 · 14 comments

Comments

@egamma
Copy link

egamma commented Apr 28, 2017

The short story is that the implementation of the 'no-unused-variable' rule reuses the TS compiler options noUnusedLocals and noUnusedParameters. This is done by creating a typescript Program with these options enabled. The Program is created with a 'fake' Host object, This Host object doesn't honor the platform's case sensitive conventions. This has the side effect that the Program ends up in an inconsistent state and breaks the TypeScript server and makes the tslint-languageservice-plugin unusable.

The full details of the issue can be found here: microsoft/TypeScript#15344

As a workaround the tslint-language-service plugin removes the 'no-unused-variable' rule from the user's configuration.

@adidahiya
Copy link
Contributor

actually I'll leave this open until we get verification that it's fixed via #2819

@BurtHarris
Copy link

@adidahiya, I seem to still be hitting this with the following:

"tslint": "^5.5.0",
"tslint-config-standard": "^6.0.1",
"tslint-language-service": "^0.9.6",
"typescript": "^2.4.1"

Workaround of disabling rule no-unused-variable in tslint.json works OK.

@cartant
Copy link

cartant commented Jul 9, 2017

@BurtHarris @adidahiya There is another issue - #2876 - with the no-unused-variable rule that also sees the Program placed into an inconsistent state (after the error occurs, unrelated rules that are otherwise okay, also effect errors).

@e-cloud
Copy link

e-cloud commented Jul 10, 2017

Similar As @BurtHarris, the same warning keeps comming. Apparently, there is no fix yet.

@donaldpipowitch
Copy link
Contributor

Can someone summarise what needs to be done to get no-unused-variable support in vscode-ts-tslint? Thx.

@egamma
Copy link
Author

egamma commented Sep 26, 2017

@donaldpipowitch here is my attempt of a summary:

vscode-vs-tslint

tslint

@donaldpipowitch
Copy link
Contributor

A big thank you! 👏

@egamma
Copy link
Author

egamma commented Sep 26, 2017

@donaldpipowitch please do not forgot that using tslint as a TS language server plugin has several limitations: angelozerr/tslint-language-service#32

@jscharett
Copy link

Any plans on fixing this?

@strax
Copy link

strax commented Jun 16, 2018

As the no-unused-variables rule is deprecated for >= TS 2.9, I published a custom rule no-unused that uses TypeScript 2.9's new unused locals diagnostics.
Compared to using the compiler options this approach does not affect compilation and it also works with the language server plugin (but still needs type information).

@sbusch
Copy link

sbusch commented Jun 18, 2018

@strax works for me, many thanks!

Do you have plans for this plugin to differentiate between unused parameters and locals (noUnusedParameters / noUnusedLocals)? I only want warnings for the latter (unused imports).

@strax
Copy link

strax commented Jun 19, 2018

@sbusch That might be tricky since TS emits the same error code for both unused variables and suggestions, and there's no obvious way to get the related symbol / AST node. PRs for the functionality are certainly welcome.

@bajtos
Copy link

bajtos commented Dec 14, 2018

I came to this issue while looking for a solution allowing us to use no-unused-variable together with typescript-tslint-plugin. The module no-unused did not work well enough as it was too strict in rejecting unused parameters.

Personally, I much more like the rule no-unused from tslint-consistent-codestyle. We can unused parameters can prefixed with underscore to disable the warning (e.g. _param). Even better, the check for unused parameters can be disabled entirely via tslint config.

YMMV.

@JoshuaKGoldberg
Copy link
Contributor

Oh hey, this issue can be closed now that no-unused-variable is deprecated in TSLint core.

Discussion on how to reenable it (and hopefully other language features such as noImplicitAny): #4100

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests