KT.MATCHING_DECLARATION_NAME

Single non-private class is not named as file name

If a Kotlin file contains a single non-private class (potentially with related top-level declarations), its name should be the same as the name of the class, with the .kt extension appended. If a file contains multiple classes, or only top-level declarations, choose a name describing what the file contains, and name the file accordingly. Use camel humps with an uppercase first letter (e.g. ProcessDeclarations.kt). The name of the file should describe what the code in the file does. Therefore, you should avoid using meaningless words such as Util in file names. - Official Kotlin Style Guide More information at: https://kotlinlang.org/docs/coding-conventions.html

Noncompliant Code

Copy
class Foo // FooUtils.kt
fun Bar.toFoo(): Foo = ...
fun Foo.toBar(): Bar = ...

Compliant Code

Copy
class Foo { // Foo.kt
  fun stuff() = 42
}
fun Bar.toFoo(): Foo = ...

Options

  • mustBeFirst (default: True)

    name should only be checked if the file starts with a class or object

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