-
Notifications
You must be signed in to change notification settings - Fork 659
feat(rome_js_analyze): noAssignInExpressions
#3928
Conversation
✅ Deploy Preview for docs-rometools ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
crates/rome_js_analyze/src/analyzers/nursery/no_assign_in_expressions.rs
Show resolved
Hide resolved
Nice! Thanks for the contribution. for (let a = 0; a < 10; a+= 5) {
}
const f = (a) => a+=1; |
Thanks for the suggestion! I will add this case.
I am more doubtful about this one. Indeed, a reader could think that the previous code is equivalent to the following:
While it is equivalent to:
Moreover, it could be confusing regarding the rule name. Although this could be renamed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this new rule interact with the noConditionalAssignment
rule ? We wouldn't want to emit two diagnostics for if(a = b) {}
, maybe it would be possible to merge them ?
@leops Thanks for the info, I did not notice this rule. I could suggest of removing |
By the way, I could add the code action of EDIT: done. |
|
@leops done :) |
crates/rome_js_analyze/tests/specs/nursery/noConditionalAssignment/invalid.js
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, let's not delete a rule from one release to another; I think it sends an incorrect signal to the users.
We should at least deprecate
the rule first and delete it in the next release cycle.
We have an API RuleDiagnostic::new().deprecated()
, and we can add a footer note telling users to use another rule. Ultimately, we should remove it from the recommended rules and update the documentation, telling users that the rule is deprecated and asking them to use the new one
crates/rome_js_analyze/src/analyzers/nursery/no_assign_in_expressions.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_assign_in_expressions.rs
Show resolved
Hide resolved
Is this really necessary if the rule is still under the |
That's on me, sorry. I didn't see that this rule was under |
The only drawback I see could be breaking a config file. |
We'll soon deliver a way to auto-magically make migration paths automatic, so this won't be a problem anymore |
I updated the branch. let a, b;
a = b = 1; |
Ready for merging |
The problem is that we now support pretty complex assignments. For example: a = (b = 1, b = 2) Even worse. Given that we support the assignment to live inside sequences, we can have a = (<ANYTHING>, b = 2, <ANYTHING>) crazy example a = (class {}, b = 2, function() {}); |
My reasoning was that a recommended rule could disallow sequences (except in for updates and init). This seems good enough to my taste. |
One problem I could see is that this rule will be recommended, while the suggested rule |
This rule is covered by noAssignInExpressions.
Makes sense. I updated the code to rule out the cases you pointed out. |
Summary
Closes #4013
This is an exclusive rule for Rome!
This disallows any assignment in an expression.
This covers two ESLint's rules: no-cond-assign and no-return-assign.
Implemenattion alternatives
The rule could be relaxed to allow assignment of assignment such as:
and void-assign:
I could keep the rule as is and open an issue to gather interest.
Test Plan
Unit tests and doc tests included.