We need to enforce:
a += b
instead of:
a = a + b
The same applies for all other operators: -, &, **, etc
https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
The first version is correct and short. This is a consistency rule.
I would like to work on this
You are assigned!
@Sam-wyre hey, how's it going? Do you need any help from my side? Feel free to ask for help or drop this task in case you are willing to.
Good evening! Let's I'll do it.
Thanks a lot, @slapshin! You are on it.
Hi! Should we handle such situations a = a + b - c -> a += b - c?
Yes.
Sorry, another question. For example:
a = a + b can be shortened to a += b
a = b + a also can be shortened to a += b, because + is commutative operation. But need some code analyzing. Should linter do it? It can lead to potentials problems in complex expressions.
What do you think?
No, we don't need to analyse the code. We should turn both a = a + b and a = b + a into a += b.
Any errors are on user's side. Plus should be commutative.
>>> a = [1]
>>> b = [2]
>>> a += b
>>> a
[1, 2]
>>> a = [1]
>>> b = [2]
>>> a = b + a
>>> a
[2, 1]
¯\_(ツ)_/¯
@kxepal great point! I start to agree to that a = b + a is a different case, that should not be covered.
Ok. We will not handle commutative cases in this rule
@sobolevn ok. Thanks!
It is quite related and you can take some inspiration from it.
Hi! Simple cases (a = a + b, a = a - b,...) are done. There are difficulties with more complex expressions. For example,
a = a + b + c # can be simply converted to a += b + c
a = a + b - c # can be simply converted to a += b - c
a = a - b + c # can't be converted to a -= b + c (means, a = a - (b + c))
a = a * b + c # can't be converted to a *= b + c
a = a * b * c # can be simply converted to a *= b * c
Also, there are cases with brackets. I have no big experience in auto code analyzing, but it looks like we need more deep research here. Maybe you can help me with an idea? Maybe already exists something like this in the system?
Let's start with simple cases. Later we can adjust this rule for more than one math sign.
Thanks a lot, @slapshin!