Search code examples
javascripttypescripteslint

eslint for "empty" statements


I accidentally wrote some pretty crappy code.

My intention was to write this

let a = 0;
...
a = 2;

But instead of assigning to a, I accidentally got a double =

let a = 0;
...
a == 2;

I know that it is valid javascript and typescript, but I feel like there has to be some lint checks that blocks this sort of thing from happening, because I cannot for the life of me see any point in writing such code.

So is there an eslint rule I can use that checks for these types of noop/empty statements?


Solution

  • For JavaScript, you can use no-unused-expressions.

    For TypeScript, you can use @typescript-eslint/no-unused-expressions.

    Also check out this demos in ESLint playground and TypeScript ESLint playground.