# io.gitlab.arturbosch.detekt.api

detekt-api
1.21.0-RC2

# Package io.gitlab.arturbosch.detekt.api

## Types

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

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.

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

Defines the visiting mechanism for KtFile's.

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

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.

Compactable
Link copied to clipboard
interface Compactable
Content copied to clipboard

Provides a compact string representation.

Config
Link copied to clipboard
interface Config
Content copied to clipboard

A configuration holds information about how to configure specific rules.

ConfigAware
Link copied to clipboard
interface ConfigAware : Config
Content copied to clipboard

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

ConfigValidator
Link copied to clipboard
interface ConfigValidator : Extension
Content copied to clipboard

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

ConsoleReport
Link copied to clipboard
abstract class ConsoleReport : Extension
Content copied to clipboard

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

Context
Link copied to clipboard
interface Context
Content copied to clipboard

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

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

Represents a code smell for that can be auto corrected.

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

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

DefaultContext
Link copied to clipboard
open class DefaultContext : Context
Content copied to clipboard

Default Context implementation.

Detektion
Link copied to clipboard
interface Detektion
Content copied to clipboard

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

DetektVisitor
Link copied to clipboard
open class DetektVisitor : KtTreeVisitorVoid
Content copied to clipboard

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

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

Stores information about a specific code fragment.

Extension
Link copied to clipboard
interface Extension
Content copied to clipboard

Defines extension points in detekt. Currently supported extensions are:

FileProcessListener
Link copied to clipboard
interface FileProcessListener : Extension
Content copied to clipboard

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

Finding
Link copied to clipboard
interface Finding : Compactable, HasEntity, HasMetrics
Content copied to clipboard

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

HasEntity
Link copied to clipboard
interface HasEntity
Content copied to clipboard

Describes a source code position.

HasMetrics
Link copied to clipboard
interface HasMetrics
Content copied to clipboard

Adds metric container behaviour.

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

An issue represents a problem in the codebase.

LazyRegex
Link copied to clipboard
class LazyRegex (key: String , default: String ) : ReadOnlyProperty < Rule , Regex >
Content copied to clipboard

LazyRegex class provides a lazy evaluation of a Regex pattern for usages inside Rules. It computes the value once when reaching the point of its usage and returns the same value when requested again.

Location
Link copied to clipboard
data class Location @ JvmOverloads constructor( val source: SourceLocation , val text: TextLocation , val file: String , val filePath: FilePath = FilePath.fromAbsolute(Paths.get(file))) : Compactable
Content copied to clipboard

Specifies a position within a source code fragment.

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

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.

MultiRule
Link copied to clipboard
abstract class MultiRule : BaseRule
Content copied to clipboard

Composite rule which delegates work to child rules. Can be used to combine different rules which do similar work like scanning the source code line by line to increase performance.

Notification
Link copied to clipboard
interface Notification
Content copied to clipboard

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.

OutputReport
Link copied to clipboard
abstract class OutputReport : Extension
Content copied to clipboard

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

ProjectMetric
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)
Content copied to clipboard

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

PropertiesAware
Link copied to clipboard
interface PropertiesAware
Content copied to clipboard

Properties holder. Allows to store and retrieve any data.

ReportingExtension
Link copied to clipboard
interface ReportingExtension : Extension
Content copied to clipboard

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

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

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.

RuleId
Link copied to clipboard
typealias RuleId = String
Content copied to clipboard

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

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

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

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

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

SetupContext
Link copied to clipboard
interface SetupContext : PropertiesAware
Content copied to clipboard

Context providing useful processing settings to initialize extensions.

Severity
Link copied to clipboard
enum Severity : Enum < Severity >
Content copied to clipboard

Note: This will be replaced by SeverityLevel in future versions of Detekt.

SeverityLevel
Link copied to clipboard
enum SeverityLevel : Enum < SeverityLevel >
Content copied to clipboard

The severity level for each Issue. This will be printed to the output, such as XML or Sarif.

SingleAssign
Link copied to clipboard
class SingleAssign < T : Any >
Content copied to clipboard

Allows to assign a property just once. Further assignments result in IllegalStateException's.

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

Stores line and column information of a location.

SplitPattern
Link copied to clipboard
open class SplitPattern ( text: String , delimiters: String = ",", removeTrailingAsterisks: Boolean = true)
Content copied to clipboard

Splits given text into parts and provides testing utilities for its elements. Basic use cases are to specify different function or class names in the detekt yaml config and test for their appearance in specific rules.

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

Stores character start and end positions of a text file.

ThresholdedCodeSmell
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
Content copied to clipboard

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

ThresholdRule
Link copied to clipboard
abstract class ThresholdRule (config: Config , defaultThreshold: Int ) : Rule
Content copied to clipboard

Provides a threshold attribute for this rule, which is specified manually for default values but can be also obtained from within a configuration object.

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

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

ValuesWithReason
Link copied to clipboard
data class ValuesWithReason : Iterable < ValueWithReason >
Content 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.

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

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

## Functions

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

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

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

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 >
Content copied to clipboard

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.

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

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 >
Content copied to clipboard

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.

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

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 >
Content copied to clipboard

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.

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

Allows to retrieve stored properties in a type safe way.

simplePatternToRegex
Link copied to clipboard
fun String . simplePatternToRegex (): Regex
Content copied to clipboard

Convert a simple pattern String to a Regex

valuesWithReason
Link copied to clipboard
fun valuesWithReason (vararg values: Pair < String , String ?>): ValuesWithReason
Content 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:

fun valuesWithReason (values: List < ValueWithReason >): ValuesWithReason
Content 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.

## Properties

DEFAULT_FLOAT_CONVERSION_FACTOR
Link copied to clipboard
const val DEFAULT_FLOAT_CONVERSION_FACTOR : Int = 100
Content 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)