New rule: no-decreasing-immutability #526
Labels
Accepted
This issue or PR has been accepted.
Priority: Low
Nice addition, maybe... someday...
Type: Feature
New features or options.
Suggestion
A new rule to prevent assignment of one value to another where the target has a lower immutability level (per https://github.com/RebeccaStevens/is-immutable-type/#definitions) than the source.
Such assignments can lead to surprising mutations in the source value.
For example, we might flag this as an issue:
That example uses an assignment expression, but the rule would ideally target method passing, return values, etc.
And of course that example uses Immutable and DeepReadonly, but it would ideally catch any step downwards down that hierarchy.
Strictly speaking, assignments in the other direction are unsafe too (can lead to later surprising mutation in the immutable value that was assigned to). Anything that leads to two handles to the same value where those handles have different opinions about mutability will lead to the issue, but in practice its the downward direction assignments that cause the most trouble imo.
Some tentative stabs in that direction:
The text was updated successfully, but these errors were encountered: