Package-level declarations

Types

Link copied to clipboard
class AnnotationExcluder(root: KtFile, excludes: List<Regex>, context: BindingContext)

Primary use case for an AnnotationExcluder is to decide if a KtElement should be excluded from further analysis. This is done by checking if a special annotation is present over the element.

Link copied to clipboard
abstract class BaseRule(context: Context = DefaultContext()) : DetektVisitor, Context

Defines the visiting mechanism for KtFile's.

Link copied to clipboard
open class CodeSmell(val issue: Issue, val entity: Entity, val message: String, val references: List<Entity> = emptyList()) : Finding

A code smell indicates any possible design problem inside a program's source code. The type of a code smell is described by an Issue.

Link copied to clipboard
interface Compactable

Provides a compact string representation.

Link copied to clipboard
interface Config

A configuration holds information about how to configure specific rules.

Link copied to clipboard
interface ConfigAware : Config

Interface which is implemented by each Rule class to provide utility functions to retrieve specific or generic properties from the underlying detekt configuration file.

Link copied to clipboard

An extension which allows users to validate parts of the configuration.

Link copied to clipboard
abstract class ConsoleReport : Extension

Extension point which describes how findings should be printed on the console.

Link copied to clipboard
interface Context

A context describes the storing and reporting mechanism of Finding's inside a Rule. Additionally it handles suppression and aliases management.

Link copied to clipboard
open class CorrectableCodeSmell(val issue: Issue, val entity: Entity, val message: String, val references: List<Entity> = emptyList(), val autoCorrectEnabled: Boolean) : CodeSmell

Represents a code smell for that can be auto corrected.

Link copied to clipboard
class Debt(val days: Int = 0, val hours: Int = 0, val mins: Int = 0)

Debt describes the estimated amount of work needed to fix a given issue.

Link copied to clipboard
interface Detektion : UserDataHolder

Storage for all kinds of findings and additional information which needs to be transferred from the detekt engine to the user.

Link copied to clipboard
open class DetektVisitor : KtTreeVisitorVoid

Basic visitor which is used inside detekt. Guarantees a better looking name as the extended base class :).

Link copied to clipboard
class Entity(val name: String, val signature: String, val location: Location, val ktElement: KtElement? = null) : Compactable

Stores information about a specific code fragment.

Link copied to clipboard
interface Extension

Defines extension points in detekt. Currently supported extensions are:

Link copied to clipboard

Gather additional metrics about the analyzed kotlin file. Pay attention to the thread policy of each function!

Link copied to clipboard

Base interface of detection findings. Inherits a bunch of useful behaviour from sub interfaces.

Link copied to clipboard
interface HasEntity

Describes a source code position.

Link copied to clipboard
class Issue(val id: String, val description: String, val debt: Debt)

An issue represents a problem in the codebase.

Link copied to clipboard
class Location(val source: SourceLocation, val endSource: SourceLocation = source, val text: TextLocation, val filePath: FilePath) : Compactable

Specifies a position within a source code fragment.

Link copied to clipboard
class Metric(val value: Int, val threshold: Int, val isDouble: Boolean = false, val conversionFactor: Int = DEFAULT_FLOAT_CONVERSION_FACTOR)

Metric type, can be an integer or double value. Internally it is stored as an integer, but the conversion factor and is double attributes can be used to retrieve it as a double value.

Link copied to clipboard
interface Notification

Any kind of notification which should be printed to the console. For example when using the formatting rule set, any change to your kotlin file is a notification.

Link copied to clipboard
abstract class OutputReport : Extension

Translates detekt's result container - Detektion - into an output report which is written inside a file.

Link copied to clipboard
open class ProjectMetric(val type: String, val value: Int, val priority: Int = -1, val isDouble: Boolean = false, val conversionFactor: Int = DEFAULT_FLOAT_CONVERSION_FACTOR)

Anything that can be expressed as a numeric value for projects.

Link copied to clipboard
interface PropertiesAware

Properties holder. Allows to store and retrieve any data.

Link copied to clipboard

Allows to intercept detekt's result container by listening to the initial and final state and manipulate the reported findings.

Link copied to clipboard
abstract class Rule(val ruleSetConfig: Config = Config.empty, ruleContext: Context = DefaultContext()) : BaseRule, ConfigAware

A rule defines how one specific code structure should look like. If code is found which does not meet this structure, it is considered as harmful regarding maintainability or readability.

Link copied to clipboard
typealias RuleId = String

The type to use when referring to rule ids giving it more context then a String would.

Link copied to clipboard
class RuleSet(val id: RuleSetId, val rules: List<BaseRule>)

A rule set is a collection of rules and must be defined within a rule set provider implementation.

Link copied to clipboard
typealias RuleSetId = String
Link copied to clipboard
interface RuleSetProvider

A rule set provider, as the name states, is responsible for creating rule sets.

Link copied to clipboard

Context providing useful processing settings to initialize extensions.

Link copied to clipboard

The severity for each Issue. This will be printed to the output, such as XML or Sarif. Depending on the severity of the issues found, the build process result is determined.

Link copied to clipboard
class SourceLocation(val line: Int, val column: Int)

Stores line and column information of a location.

Link copied to clipboard
class TextLocation(val start: Int, val end: Int)

Stores character start and end positions of a text file.

Link copied to clipboard
open class ThresholdedCodeSmell(val issue: Issue, val entity: Entity, val metric: Metric, val message: String, val references: List<Entity> = emptyList()) : CodeSmell

Represents a code smell for which a specific metric can be determined which is responsible for the existence of this rule violation.

Link copied to clipboard
annotation class UnstableApi(val reason: String = "")

Experimental detekt api which may change on minor or patch versions.

Link copied to clipboard

ValuesWithReason is essentially the same as List of ValueWithReason. Due to type erasure we cannot use the list directly. Instances of this type should always created using the valuesWithReason factory method.

Link copied to clipboard
class ValueWithReason(val value: String, val reason: String? = null)

A ValueWithReason represents a single configuration value that may have an explanation as to why it is used.

Properties

Link copied to clipboard

To represent a value of 0.5, use the metric value 50 and the conversion factor of 100. (50 / 100 = 0.5)

Functions

Link copied to clipboard
fun String.commaSeparatedPattern(vararg delimiters: String = arrayOf(",")): Sequence<String>

Splits given String into a sequence of strings split by the provided delimiters ("," by default).

Link copied to clipboard
fun <T : Any> config(defaultValue: T): ReadOnlyProperty<ConfigAware, T>

Creates a delegated read-only property that can be used in ConfigAware objects. The name of the property is the key that is used during configuration lookup. The value of the property is evaluated only once.

fun <T : Any, U : Any> config(defaultValue: T, transformer: (T) -> U): ReadOnlyProperty<ConfigAware, U>

Creates a delegated read-only property that can be used in ConfigAware objects. The name of the property is the key that is used during configuration lookup. The value of the property is evaluated and transformed only once.

Link copied to clipboard
fun <T : Any> configWithAndroidVariants(defaultValue: T, defaultAndroidValue: T): ReadOnlyProperty<ConfigAware, T>

Creates a delegated read-only property that can be used in ConfigAware objects. The name of the property is the key that is used during configuration lookup. The value of the property is evaluated only once.

fun <T : Any, U : Any> configWithAndroidVariants(defaultValue: T, defaultAndroidValue: T, transformer: (T) -> U): ReadOnlyProperty<ConfigAware, U>

Creates a delegated read-only property that can be used in ConfigAware objects. The name of the property is the key that is used during configuration lookup. The value of the property is evaluated and transformed only once.

Link copied to clipboard
fun <T : Any> configWithFallback(fallbackProperty: KProperty0<T>, defaultValue: T): ReadOnlyProperty<ConfigAware, T>

Creates a delegated read-only property that can be used in ConfigAware objects. The name of the property is the key that is used during configuration lookup. If there is no such property, the value of the supplied fallbackProperty is also considered before using the defaultValue. The value of the property is evaluated only once.

fun <T : Any, U : Any> configWithFallback(fallbackProperty: KProperty0<U>, defaultValue: T, transformer: (T) -> U): ReadOnlyProperty<ConfigAware, U>

Creates a delegated read-only property that can be used in ConfigAware objects. The name of the property is the key that is used during configuration lookup. If there is no such property, the value of the supplied fallbackProperty is also considered before using the defaultValue. The value of the property is evaluated and transformed only once.

Link copied to clipboard
inline fun <T : Any> PropertiesAware.getOrNull(key: String): T?

Allows to retrieve stored properties in a type safe way.

Link copied to clipboard

Convert a simple pattern String to a Regex

Link copied to clipboard

This factory method can be used by rule authors to specify one or many configuration values along with an explanation for each value. For example:

This factory method can be used by rule authors to specify one or many configuration values along with an explanation for each value.