Avoid self-assigned variables

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

5362

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.