32

When using eslint in Visual Studio Code, AirBnB style Ubuntu Linux, no-plusplus is enabled as default so using ++ for example in a for loop will error: [eslint] Unary operator '++' used. (no-plusplus)

How do you disable that setting?

Leigh Mathieson
  • 1,658
  • 2
  • 17
  • 25

5 Answers5

55

You can just override it in your .eslintrc.js file as follows:

'no-plusplus': 'off'

or if you don't want to disable it completely but only for for-loops:

'no-plusplus': [2, { allowForLoopAfterthoughts: true }]
Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
koala
  • 1,544
  • 1
  • 20
  • 33
  • Do I need to surround this with anything? I'm getting this error: `(function (exports, require, module, __filename, __dirname) { 'no-plusplus': 'off' ^ SyntaxError: Unexpected token :` – Aaron Franke Jun 06 '19 at 00:08
  • For newer versions of ESLint, use `"allowForLoopAfterthoughts": true`, as explained on the docs: https://eslint.org/docs/rules/no-plusplus#options – goetz Jun 25 '20 at 14:49
  • You can simple write += 1 instead, as suggested by ESLint. – Ashish Gupta Dec 28 '20 at 14:21
21

You can also write variable += 1 instead, as suggested by ESLint.

Fabian von Ellerts
  • 4,763
  • 40
  • 35
2

You can locate the file location you need to alter on Linux by searching for the keyword using grep, in this case to search for the file containing plusplus when in the folder eslint was installed use

grep -r plusplus

The correct file will be the eslint-config file, in this case it should be: node_modules/eslint-config-airbnb-base/rules/style.js

To disable the setting comment out the no-plusplus line, you can easily re-enable if required:

// 'no-plusplus': 'error',
Leigh Mathieson
  • 1,658
  • 2
  • 17
  • 25
  • 2
    editing a file in node_modules shouldn't be considered the "correct way" to do something – Edo Oct 17 '19 at 15:05
2

Or you can go like this:

'no-plusplus': 0,
Developerium
  • 7,155
  • 5
  • 36
  • 56
0

You can simply write your declared variable += 1 instead, as suggested by ESLint.

varible++ is similar as variable+=1.
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Ashish Gupta
  • 1,153
  • 12
  • 14
  • This answer was already suggested prior to your answer by Fabian? Some users may down-vote this as it is not adding anything new and removing credit from Fabian, suggest removing – Leigh Mathieson Dec 22 '21 at 10:13