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.

Rule proposal: disallow chained variable assignment

See original GitHub issue

When the rules will warn. Include a description as well as sample code.

Chained variable assignment creates implicit global variables. Although these should be caught by the no-undef rule, people may want to prevent chained variable assignment for readability purposes.

// Bad (this fails no-undef)
var a = b = c = 1;

// Bad (this passes no-undef)
var b;
var c; 
var a = b = c = 1;

// Good
var a = 1;
var b = a;
var c = a;

Whether the rule prevents an error or is stylistic.

This rule prevents an error if the no-undef rule is not enabled, otherwise it is stylistic and similar to the one-var rule.

Why the rule should be in the core instead of creating a custom rule.

This is a basic JavaScript syntax rule that is generally applicable to anyone writing JavaScript.

Are you willing to create the rule yourself?

Sure.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Aug 18, 2016

@ljharb What you’re saying makes sense and is basically what I had been thinking in my head earlier. I just wanted to give the ESLint team a chance to jump in and let me know if I had missed something.

I’ll probably champion this, once we figure out how exactly we want to do it.

2reactions
ljharbcommented, Aug 18, 2016

I think it makes the most sense as a new rule. one-var might work, but even when you don’t want to require or disallow multiple var statements, you may want to govern this pattern. no-undef also might work, but this is not saying “don’t use undefined/global vars”, it’s saying “don’t accidentally create some global vars with one local”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disallow assignments in conditions and remove the Yoda ...
Drop the handbook rule that requires Yoda conditions and instead explicitly disallow using them. Remove Yoda condition as a requirement.
Read more >
no-multi-assign - Pluggable JavaScript Linter - ESLint
Chaining the assignment of variables can lead to unexpected results and be ... This rule disallows using multiple assignments within a single statement....
Read more >
Proposed rule: Private Fund Advisers - SEC.gov
We propose to require registered investment advisers to private funds to provide transparency to their investors regarding the full cost of ...
Read more >
how to break a long line of chained assignments in python
As a single statement, there are no subexpressions to parenthesize. I'm not a fan of explicit line continuations, but this is probably a ......
Read more >
Assignment operators (C# reference) - Microsoft Learn
C# assignment operators assign an expression to a variable. Assignment sets the value of the expression. `ref` assignment sets the reference ...
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