You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The no-unused-variable rule has always been problematic, and at one stage the tslint team were going to deprecate it completely. It's now a semantic rule. It thus only works if you use tsconfig.json files to define your project.
I tried myself and I did manage to get no-unused-variable to work in the TypeScript Analyzer. Follow the steps below:
Create a new TypeScript 'Blank Node.js Console Application' project
Change app.ts so it contains only the one line of code below: function test() { const a = 5; }
Add a tsconfig.json file: the default Visual Studio one is fine (Add/New Item on the project context menu in Solution Explorer, TypeScript JSON Configuration File). Make sure it's actually called 'tsconfig.json'.
Tools/Options/TypeScript Analyzer and make sure 'Use tsconfig.json files' is set to True.
Tools/TypeScript Analyzer/Edit TSLint Settings (tslint.json) and add '"no-unused-variable": true,' to the tslint.json file in the rules section.
Run the analyzer and you should get a no-unused-variable warning: 'a' is declared but never used
There's quite a lot of discussion about this rule on the tslint site, see issues 1481, 2235, 1618, 2933 and there are plenty more issues referenced from those.
I added "no-unused-variable": true rule to tslint.json, but rule does not appear to raise warnings
https://palantir.github.io/tslint/rules/no-unused-variable/
The text was updated successfully, but these errors were encountered: