KT.MEMBER_NAME_EQUALS_CLASS_NAME

Member has the same name as the containing class or object

This rule reports a member that has a name the same as the containing class or object. This might result in confusion. The member should either be renamed or changed to a constructor. Factory functions that create an instance of the class are exempt from this rule.

Noncompliant Code

Copy
class MethodNameEqualsClassName {
  fun methodNameEqualsClassName() { }
}
class PropertyNameEqualsClassName {
  val propertyEqualsClassName = 0
}

Compliant Code

Copy
class Manager {
  companion object {
  // factory functions can have the same name as the class

  fun manager(): Manager {
    return Manager()
  }
 }
}

Options

  • ignoreOverridden (default: True)

    if overridden functions and properties should be ignored

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html