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

no-unused-variable rule does not appear to work #21

Closed
VisionRidge opened this issue Sep 21, 2017 · 1 comment
Closed

no-unused-variable rule does not appear to work #21

VisionRidge opened this issue Sep 21, 2017 · 1 comment

Comments

@VisionRidge
Copy link

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/

@rich-newman
Copy link
Owner

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.

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

No branches or pull requests

2 participants