question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`no-plusplus` rule errors with valid JS code, requires more code as workaround

See original GitHub issue

What rule do you want to change? no-plusplus

Does this change cause the rule to produce more or fewer warnings? fewer, depends on approach taken to solve it

How will the change be implemented? (New option, new default behavior, etc.)? I’m here to suggest a change in a high-level, haven’t looked at the source code to suggest a solution implementation.

Please provide some example code that this change will affect:

let a = 1;
let b;
let c = b || a++;

What does the rule currently do for this code? At the moment the above throws a violation of the no-plusplus rule. The only workaround for satisfying the rule is to increment a in a new statement to have the same effect, because: let c = b || a+=1; (which is the recommended solution from the docs) throws Uncaught ReferenceError: Invalid left-hand side in assignment, and let c = b || (a+1); increments a before assigning to c, which isn’t the intention here.

What will the rule do after it’s changed? It should either allow valid statements like the above or only throw a warning instead of an error

Are you willing to submit a pull request to implement this change? Possibly, haven’t looked at the source code yet.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Feb 13, 2019

I think advocates for the no-plusplus rule would argue that code like c = b || a++ is confusing to read. The code is “valid” in that it doesn’t cause a runtime error, but it’s the type of thing that (one might argue) you shouldn’t use. It seems like every piece of code reported by no-plusplus is similarly “valid” but potentially confusing, so it might be better to simply disable the no-plusplus rule if you want to use code like that.

0reactions
kurecicommented, Feb 13, 2019

@platinumazure you’re right indeed, I don’t need to be using this rule. It’s just because I’m using Airbnb’s ESLint as the base, and therefore now need to ‘disable’ the rule as it’s enabled in the base.

Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-plusplus - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
How do you disable no-plusplus when using eslint?
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...
Read more >
Reduce smelling code and detect JavaScript issues with ESLint
Problem statement: Smelling Code Have you ever had to fix an error in someone else's code - but you had to reformat the...
Read more >
Working with Rules - ESLint - Breword 文档集合
In a custom rule or plugin, you can omit docs or include any properties that you need in it. fixable (string) is either...
Read more >
eslint-config-nicestyle - npm package - Snyk
Learn more about eslint-config-nicestyle: package health score, popularity, security, maintenance, versions and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found