deno_lint icon indicating copy to clipboard operation
deno_lint copied to clipboard

Add lint inspection for unused value

Open KotlinIsland opened this issue 4 years ago • 3 comments

(1).toFixed;
1;

These should be reported as unused values.

KotlinIsland avatar Mar 17 '21 00:03 KotlinIsland

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.

magurotuna avatar Mar 17 '21 01:03 magurotuna

True, then this should be just for literals and references that aren't using getters eg:

const a = 1;
a;

KotlinIsland avatar Mar 17 '21 02:03 KotlinIsland

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.

rivy avatar Sep 12 '21 00:09 rivy