5

The eslint documentation describes a way to forbid the increment and decrement operators ++ and --.

The description includes the sentence, that these operators

are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code.

By reading this, I still don't understand why it would be a good practice to forbid them. I could think of transpile or interpreter issues but I have no clear idea.

Also, I learned in nearly every tutorial, documentation and even at University courses to use these operators.

The following documentations also do not express concerns about them:

MDN

MSDN

W3Schools

I am very curious now what purpose it has to forbid their usage.

Jankapunkt
  • 8,128
  • 4
  • 30
  • 59
  • The page you link to shows an example of the problem. What about the example don't you understand? (Not that I think this is a useful rule. I happily use increment and decrement operators in my code. I also put semicolons where they're expected to be instead of relying on the horror of ASI.) – T.J. Crowder Jan 10 '18 at 09:40
  • Read the section about it in this answer https://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion-asi – baao Jan 10 '18 at 09:41
  • The quoted text in your question also explains the problem: "_differences in whitespace can change semantics of source code_". – Teemu Jan 10 '18 at 09:41
  • 2
    Not every eslint rule automatically means "best practice", you need to understand this. Also to be fair their example of how whitespace can change semantics of the code, is very unrealistic (implied global in their code is far more common source of the problem). – dfsq Jan 10 '18 at 09:47
  • Ok so when I get it right it is rather about the whitespace position before or after the operators in combination with a missing semicolon and ASI than about the operators themselves!? – Jankapunkt Jan 10 '18 at 21:11

0 Answers0