Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint error Unary operator '++' used no-plusplus

I am getting error with my for loop if I used i++ in for loop

var foo = 0;
    foo++;
    
    var bar = 42;
    bar--;
    
    for (i = 0; i < 1; i++) {
        return;
    }
like image 304
Mehpal Patidar Avatar asked Sep 10 '25 18:09

Mehpal Patidar


1 Answers

One option would be to replace i++ with i+=1

You can also turn that specific eslint rule off (either for the specific line, the file or global configuration). Please consider that this might be not recommended, especially at the file or line level.

The rule name you are looking for is no-plusplus.

Disable it globally

In your eslint config file add the following:

'no-plusplus': 'off' **OR** 'no-plusplus': 0

There is also an option to disable it only for the for loops:

 no-plusplus: ["error", { "allowForLoopAfterthoughts": true }]

For further information you can check eslint no-plusplus docs

Disable it at the file level

At the top of your file add the following:

/* eslint-disable no-plusplus */

Disable it for the given line

Just before the for loop, add the following:

/* eslint-disable-next-line no-plusplus */
like image 180
adrianmanduc Avatar answered Sep 12 '25 09:09

adrianmanduc