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
no-multi-assign option only when declaring variables. #12545
Comments
Thanks for the proposal. Could you clarify what problem you’re trying to solve? |
Yes of course. The project I work for called PhET Interactive Simulations (https://github.com/phetsims/) has decided on code style that allows multi-assign when when not declaring a variable, but disallows multi-assign when declaring. So this would be flagged as an error:
Where this would be allowed: x = {};
y = {};
x.something = y.something = 'string value'; Currently there is no way to make the eslint rule |
Thanks for the explanation. This seems like a reasonable request to me, though I wonder if we can come up with an option name that's more along the lines of |
Whoops, sorry, didn't mean to close this 😅 |
Brainstorming a few more possibilities here:
|
I think that generally makes more sense and falls in line with some of other rules. We could create flags with the AST node type as the key (both defaulting to {
VariableDeclaration: boolean;
AssignmentExpression: boolean;
} |
I'll champion this. Let's see what the rest of the team has to say. |
This rule is in the
An error on So I'm 👍 for an option to disable this check in statements as a user's preference because it allows the user to keep the rule enabled to report possible errors in declarations. |
Thanks for looking into it you two! |
+1 for |
Marking this as accepted as there are 3 👍 from team members. From above comments, marking this with |
@zepumph you can submit a PR if you want else let me know. |
@anikethsaha @zepumph I added |
I will try sending a pull request. |
What rule do you want to change?
no-multi-assign
https://eslint.org/docs/rules/no-multi-assign
Does this change cause the rule to produce more or fewer warnings?
For this rule, it produces fewer.
How will the change be implemented? (New option, new default behavior, etc.)?
I think it should be an option, something like
onlyForVariableDeclation
of type{boolean}
. When true,no-multi-assign
will only trigger when multi-assign occurs when a variable is being declared. That said. I don't have a firm grasp on all the possible option schemas available, and I'm sure there is likely a better one for this case.Please provide some example code that this change will affect:
What does the rule currently do for this code?
It errors out both when declaring variables in the statement as well as when no declaring.
What will the rule do after it's changed?
You will have the option to only error out when declaring variables
Are you willing to submit a pull request to implement this change?
I am, though this is likely a simple change, and I have not set up the eslint dev environment before. If someone else feels passionately, then likely I won't be the most efficient implementer.
Here is a copy of the rule, outfitted with a first pass at the changes, for review:
no-multi-assign.js with added option
The text was updated successfully, but these errors were encountered: