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: https://github.com/Microsoft/TypeScript/issues/15344
As a workaround the tslint-language-service plugin removes the 'no-unused-variable' rule from the user's configuration.
actually I'll leave this open until we get verification that it's fixed via #2819
@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.
@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).
Similar As @BurtHarris, the same warning keeps comming. Apparently, there is no fix yet.
Can someone summarise what needs to be done to get no-unused-variable support in vscode-ts-tslint? Thx.
@donaldpipowitch here is my attempt of a summary:
A big thank you! 馃憦
@donaldpipowitch please do not forgot that using tslint as a TS language server plugin has several limitations: https://github.com/angelozerr/tslint-language-service/issues/32
Any plans on fixing this?
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).
@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).
@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.
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.
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
Most helpful comment
As the
no-unused-variablesrule 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).