Skip to main content
Version: 1.23.6

Suppressing Issues

detekt supports the Java (@SuppressWarnings) and Kotlin (@Suppress) style suppression. If both annotations are present, Kotlin's annotation is favored!

To suppress an issue, the id of the rule must be written inside the values field of the annotation (e.g. @Suppress("LongMethod")).

If a LargeClass is reported, but that is totally fine for you codebase, then just annotate it:

@Suppress("LargeClass") // or use complexity.LargeClass
object Constants {
...
}

It is also possible to prefix the rule id with detekt and/or the ruleset id such as @Suppress("detekt:LongMethod") or @Suppress("complexity:LongParameterList").

The following table shows the various supported suppression formats.

Example SuppressionDescription
all, detekt:all, detekt.allSuppresses all detekt findings.
style, detekt:style, detekt.styleSuppresses all findings from rules in the style rule set.
MagicNumber, style:MagicNumber, style.MagicNumber, detekt:style:MagicNumber, detekt.style.MagicNumberSuppresses all MagicNumber rule findings.

Some rules like TooManyFunctions can only be suppressed by using a file level annotation @file:Suppress("TooManyFunctions").

Formatting rules suppression

Please note that rules inside the formatting ruleset can only be suppressed at the file level.

Rules inside this ruleset are wrappers around KtLint rules, and we don't have the same reporting capabilities that we offer for first party rules. For example, you can suppress the MaximumLineLength rule only in your entire file with:

@file:Suppress("MaximumLineLength")
package com.example

object AClassWithLongLines {
//...
}

Several rules in the formatting ruleset also have a "first party" counterpart. For instance you can use the MaxLineLength rule instead from the style ruleset.

For those rules, you can suppress the inspection also locally (on top of an expression, function, class, etc.).