Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow Use of Chained Assignment Expressions (no-multi-assign) #776

Closed
feross opened this issue Feb 8, 2017 · 7 comments

Comments

@feross
Copy link
Member

commented Feb 8, 2017

This rule disallows using multiple assignments within a single statement.

http://eslint.org/docs/rules/no-multi-assign

var a = b = c = 5 // avoid

var a = 5  // ok
var b = a
var c = a

Rule:

no-multi-assign: "error"

@feross feross added the enhancement label Feb 8, 2017

@feross feross added this to the standard v9 milestone Feb 8, 2017

@dcousens

This comment has been minimized.

Copy link
Member

commented Feb 8, 2017

var a = 5  // ok
var b = a
var c = a

Is probably more likely for the 'correct' example

@feross

This comment has been minimized.

Copy link
Member Author

commented Feb 9, 2017

@dcousens Yep, you're right. Updated the example.

@feross

This comment has been minimized.

Copy link
Member Author

commented Feb 9, 2017

This rule fails in 34 repos, and prevents a bit more than I'm comfortable with. For example:

exports.no = exports.noCase = require('no-case')
exports.dot = exports.dotCase = require('dot-case')
exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
self.readable = self.writable = false
self.socket = socketPool[self.announceUrl] = new Socket(self.announceUrl)

These all seem fine to me, so thinking we should skip this rule. Thoughts?

@feross feross removed this from the standard v9 milestone Feb 9, 2017

@timoxley

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2017

I don't see many negatives of allowing multiple assignments on one line. I use it often like in @feross's example above. I think it's good for condensing low value noise onto a single line.

@timoxley

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2017

For similar reasons I often lament standard including the "no return assignment" rule, but I do appreciate the danger of accidentally returning an assignment when you meant a conditional. Not sure this pattern suffers from that risk as much. Vote skip.

@dcousens

This comment has been minimized.

Copy link
Member

commented Feb 9, 2017

For me, this is purely a readability issue, and the only class of bugs it could relate to is:

var x = 1
var y = x = 2

instead of x + 2.
I don't think I can recall a time that has happened to me though.

@feross

This comment has been minimized.

Copy link
Member Author

commented Feb 9, 2017

Agree, it's mainly a readability issue and not a source of bugs. And it prevents valid code that we don't want to rewrite, like multiple exports on one line.

@feross feross closed this Feb 9, 2017

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.