deno_lint
deno_lint copied to clipboard
Add lint inspection for unused value
(1).toFixed;
1;
These should be reported as unused values.
I think that's essentially difficult.
Your second example (just a statement that consists of a numerical literal) could be reported easily, while as to your first example, which has property access or a method call, things get complicated because it may have side effects.
We (programmers) know toFixed method doesn't have any side effect, but the linter also would need to have such knowledge or to check whether a method has side effects or not, which doesn't seem realistic to me.
True, then this should be just for literals and references that aren't using getters eg:
const a = 1;
a;
This could catch a lot of otherwise silent errors when using common JS/TS constructions.
It looks like tslint and SonarLint have implemented a version of this rule (see https://github.com/typescript-eslint/typescript-eslint/issues/1314 and SonarJS rule ~ no-ignored-return).
The unicorn plugin for eslint is has an accepted an issue requesting an implementation for this rule which discusses some relevant issues.