Why you should care
There is no reason to re-assign a variable to itself. Either this statement is redundant and should be removed, or the re-assignment is a mistake and some other value or variable was intended for the assignment instead.
How we detect
This Code Insight counts one occurrence each time a variable is re-assigned to itself.
Bad Code
func (user *User) rename(name string) { name = name // Noncompliant }
Good CodeÂ
func (user *User) rename(name string) { user.name = name }
References
https://wiki.sei.cmu.edu/confluence/display/c/MSC12-C.+Detect+and+remove+code+that+has+no+effect+or+is+never+executed
https://rules.sonarsource.com/go/RSPEC-1656
https://rules.sonarsource.com/go/RSPEC-1656
About CAST and Highlight’s Code Insights
Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.