How do you disable no-plusplus when using eslint?
Asked Answered
M

5

33

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?

Mandorla answered 9/12, 2017 at 13:14 Comment(0)
A
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 }]
Arnaldo answered 27/12, 2017 at 17:40 Comment(3)
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 :Cox
For newer versions of ESLint, use "allowForLoopAfterthoughts": true, as explained on the docs: eslint.org/docs/rules/no-plusplus#optionsDestiny
You can simple write <variable> += 1 instead, as suggested by ESLint.Torrent
B
21

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

Brutality answered 15/5, 2019 at 14:39 Comment(2)
I think this is the best answerAisne
@БагдаулетСайын except it doesn't even answer the question ...Gaylordgaylussac
M
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',
Mandorla answered 9/12, 2017 at 13:27 Comment(1)
editing a file in node_modules shouldn't be considered the "correct way" to do somethingPer
S
2

Or you can go like this:

'no-plusplus': 0,
Swallowtailed answered 23/8, 2019 at 13:46 Comment(0)
T
0

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

varible++ is similar as variable+=1.
Torrent answered 28/12, 2020 at 14:22 Comment(1)
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 removingMandorla

© 2022 - 2024 — McMap. All rights reserved.