KT.FUNCTION_ONLY_RETURNING_CONSTANT

Function only returning a single constant

A function that only returns a single constant can be misleading. Instead, prefer declaring the constant as a const val.

Noncompliant Code

Copy
fun functionReturningConstantString() = "1"

Compliant Code

Copy
const val constantString = "1"

Options

  • ignoreOverridableFunction (default: True)

    if overriden functions should be ignored

  • ignoreActualFunction (default: True)

    if actual functions should be ignored

  • excludedFunctions (default: ``)

    excluded functions

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