All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.go.rules.go.S4144.html Maven / Gradle / Ivy

There is a newer version: 1.1.1.2000
Show newest version

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