Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Support no-unused-vars rule like in eslint #171

Closed
ikokostya opened this issue Jan 17, 2017 · 5 comments
Closed

Support no-unused-vars rule like in eslint #171

ikokostya opened this issue Jan 17, 2017 · 5 comments

Comments

@ikokostya
Copy link
Contributor

ikokostya commented Jan 17, 2017

Rule no-unused-vars rule was deprecated in tslint.

But recommended TypeScript options --noUnusedParameters and --noUnusedLocals have a lot of limitations:

Also TypeScript options noUnusedLocals and noUnusedParameters can produce errors during debugging, when unused temporary variables are not a problem. At this point of view linter is applied after compilation and can be disabled during debugging or testing.

I propose to return this rule back and make it similar to eslint no-unused-vars rule.

@jmlopez-rod
Copy link
Collaborator

The --noUnusedParameters and --noUnusedLocals do work better than a linter in my opinion. It is true that you cannot disable the error like the linter but ... (you can, in a different way)

function someFunctionInProgress(a: number, b: number) {
  console.log("I'm not going to use the value of a, just b:", b);
}

This type of function would raise the the error that a is being unused. Which is good, now you can remove it before making the function available. In some cases however, you may want to keep the variable in there. To make typescript aware of this simply use the prefix _.

function someFunctionInProgress(_a: number, b: number) {
 console.log("typescript is happy even if i don't use the first argument: b = ", b);
}

I much rather add the prefix _ to the start of the variable and be aware that it is named like that because we do not use the variable than having to add the tslint disable comment.

See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#flag-unused-declarations-with---nounusedparameters-and---nounusedlocals for info on the prefix.

@ikokostya
Copy link
Contributor Author

ikokostya commented Jan 17, 2017

I known about prefix _, but it works only for parameters. Consider situation when tests in project are failed and you need investigate why this happen. Typically during this process you need print some variable or add debugger statement, i.e. create temporary variables. In this situation code is syntactically correct, but contains undesirable (for production) constructions.

For this reason I apply linter only after compilation. Now I must disable noUnusedParameters , noUnusedLocals rules in tslint.json and later should don't forget enable its again. I need do it every time when add some unused variable for debugging. This is very annoying.

Problem can be solved if typescript compiler will add support for error severities: print warnings for unused locals, but compile code anyway.

@ikokostya
Copy link
Contributor Author

no-unused-vars was undeprecated in tslint. So, this issue can be closed.

@jmlopez-rod
Copy link
Collaborator

Time to update the docs stating that it is available on tslint. I'll reopen to have it as a reminder.

@ikokostya
Copy link
Contributor Author

Rule no-unused-var was deprecated again in tslint. I think this issue should be reopen for further discussion.

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

3 participants