
org.sonar.l10n.go.rules.go.S4144.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonar-go-plugin Show documentation
Show all versions of sonar-go-plugin Show documentation
SonarQube analyzer for Go language
Why is this an issue?
Two functions having the same implementation are suspicious. It might be that something else was intended. Or the duplication is intentional, which
becomes a maintenance burden.
func fun1() (x, y int) {
a, b := 1, 2
b, a = a, b
return a, b
}
func fun2() (x, y int) { // Noncompliant; duplicates fun1
a, b := 1, 2
b, a = a, b
return a, b
}
If the identical logic is intentional, the code should be refactored to avoid duplication. For example, by having both functions call the same
function or by having one implementation invoke the other.
func fun1() (x, y int) {
a, b := 1, 2
b, a = a, b
return a, b
}
func fun2() (x, y int) { // Intent is clear
return fun1()
}
Exceptions
Functions with fewer than 2 statements are ignored.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy