Package-level declarations

Types

Link copied to clipboard
class AvoidFirstOrLastOnList(config: Config) : Rule

Reports calls to accessors such as first(), last(), or single() on a List, Array, or Sequence since they throw an exception when no matching element is present. Prefer the *OrNull counterparts, which return null instead of throwing. The set of forbidden accessors is configurable via the methods option.

Link copied to clipboard
class AvoidGlobalScope(config: Config) : Rule

Reports usages of GlobalScope. Coroutines launched in GlobalScope are not bound to any lifecycle, so they leak work, are not cancelled on failure, and swallow crashes. Prefer a structured CoroutineScope, e.g. viewModelScope or lifecycleScope on Android.

Link copied to clipboard
class AvoidMutableCollections(config: Config) : Rule

Reports usages of mutable collection types, e.g. MutableList, since shared mutable state can lead to unexpected behavior. Prefer read-only collections and functional transformations. Expressions inside the standard library collection builders (buildList, buildSet, and buildMap) are not reported, since their whole purpose is localized mutation that produces a read-only collection. Set allowPrivateAndLocal to allow mutable collections in private declarations and inside function bodies. Platform types from Java interop, e.g. (MutableList..List), are not reported since they are only possibly mutable.

Link copied to clipboard
class AvoidToIntOrThrowingConversions(config: Config) : Rule

Reports String conversions such as toInt() that throw NumberFormatException on malformed input. Prefer the *OrNull counterparts, e.g. toIntOrNull(), and handle the null case. The set of forbidden conversions is configurable via the methods option.

Link copied to clipboard
class AvoidVarsExceptWithDelegate(config: Config) : Rule

Reports var properties since mutable state is likely to lead to bugs, prefer a val or a reactive type such as a Flow. An exception is made for vars implemented with a delegate matching one of the allowedDelegates regexes, which is particularly common with Compose.

Link copied to clipboard
class DontForceCast(config: Config) : Rule

Reports unsafe casts with as, which throw ClassCastException when the value has an unexpected type. Prefer safely casting with as? and handling the null case.

Link copied to clipboard
class HbmartinRuleSetProvider : RuleSetProvider
Link copied to clipboard
class MutableTypeShouldBePrivate(config: Config) : Rule

Reports publicly exposed Mutable* types, e.g. MutableStateFlow, since mutation by consumers can lead to unexpected behavior. Prefer exposing a read-only type instead, e.g. with _mutableStateFlow.asStateFlow(). Type names matching a regex in allowedTypes are permitted.

Link copied to clipboard
class NoCallbacksInFunctions(config: Config) : Rule

Reports function-type (callback) parameters in functions. Callbacks mix concurrency paradigms and are likely to lead to bugs or stalled threads, prefer suspend functions instead. Receiver lambdas, extension functions, and inline functions can be permitted with the allowReceivers, allowExtensions, and allowInline options, and ignoreAnnotated: ['Composable'] permits callbacks in composables.

Link copied to clipboard
class NoDeferredResultInPublicApi(config: Config) : Rule

Reports public functions and properties with an explicitly declared Deferred type. Returning a Deferred leaks the concurrency implementation to callers and makes crashes hard to trace when await() is called far from where the failure happened. Prefer a suspend function returning the awaited value. Declarations with inferred types are not detected.

Link copied to clipboard
class NoLateinitVar(config: Config) : Rule

Reports lateinit var properties. Accessing a lateinit property before it is initialized crashes with UninitializedPropertyAccessException, and lateinit also forces the property to be mutable. Prefer constructor parameters, a nullable val, or lazy initialization. Annotations that legitimately require lateinit, e.g. @Inject, can be permitted with the allowedAnnotations option.

Link copied to clipboard
class NoNotNullOperator(config: Config) : Rule

Reports usage of the NPE inducing !! operator, prefer safe unwrapping with ?., ?:, or requireNotNull. To allow !! in some contexts, e.g. tests, use detekt's standard ignoreAnnotated (e.g. ignoreAnnotated: ['Test']) or excludes (e.g. a glob matching your test source sets) options on this rule.

Link copied to clipboard
class NoRunBlocking(config: Config) : Rule

Reports calls to runBlocking, which blocks the current thread until its coroutine finishes and can deadlock or freeze the UI when used on a main thread. Prefer exposing suspend functions and launching coroutines from a structured CoroutineScope. This check matches by name and so also flags runBlocking helpers from other packages. To allow it in some contexts, e.g. tests, use detekt's standard ignoreAnnotated or excludes options on this rule.

Link copied to clipboard
class NoVarsInConstructor(config: Config) : Rule

Reports var parameters in class constructors since mutable state is likely to lead to bugs. Prefer val and create modified copies as needed, e.g. with a data class copy.

Link copied to clipboard
class WhenBranchSingleLineOrBraces(config: Config) : Rule

A stylistic rule requiring that a when branch body either starts on the same line as the arrow with a single space after it, or uses braces.