detekt-api
1.21.0-RC2

# ConfigAware

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.

Be aware that there are three config levels by default:

- the top level config layer specifies rule sets and detekt engine properties

- the rule set level specifies properties concerning the whole rule set and rules

- the rule level provides additional properties which are used to configure rules

This interface operates on the rule set level as the rule set config is passed to each rule in the #RuleSetProvider interface. This is due the fact that users create the rule set and all rules upfront and letting them 'sub config' the rule set config would be error-prone.

## Functions

subConfig
Link copied to clipboard
open override fun subConfig (key: String ): Config
Content copied to clipboard

Tries to retrieve part of the configuration based on given key.

valueOrDefault
Link copied to clipboard
open override fun < T : Any > valueOrDefault (key: String , default: T ): T
Content copied to clipboard

Retrieves a sub configuration or value based on given key. If configuration property cannot be found the specified default value is returned.

valueOrNull
Link copied to clipboard
open override fun < T : Any > valueOrNull (key: String ): T ?
Content copied to clipboard

Retrieves a sub configuration or value based on given key. If the configuration property cannot be found, null is returned.

withAutoCorrect
Link copied to clipboard
open fun withAutoCorrect (block: () -> Unit )
Content copied to clipboard

If your rule supports to automatically correct the misbehaviour of underlying smell, specify your code inside this method call, to allow the user of your rule to trigger auto correction only when needed.

## Properties

active
Link copied to clipboard
open val active : Boolean
Content copied to clipboard

Is this rule specified as active in configuration? If a rule is not specified in the underlying configuration, we assume it should not be run.

autoCorrect
Link copied to clipboard
open val autoCorrect : Boolean
Content copied to clipboard

Does this rule have auto correct specified in configuration? For auto correction to work the rule set itself enable it.

parentPath
Link copied to clipboard
open val parentPath : String ?
Content copied to clipboard

Keeps track of which key was taken to subConfig this configuration. Sub-sequential calls to subConfig are tracked with '>' as a separator.

ruleId
Link copied to clipboard
abstract val ruleId : RuleId
Content copied to clipboard

Id which is used to retrieve the sub config for the rule implementing this interface.

ruleSetConfig
Link copied to clipboard
abstract val ruleSetConfig : Config
Content copied to clipboard

Wrapped configuration of the ruleSet this rule is in. Use valueOrDefault function to retrieve properties specified for the rule implementing this interface instead. Only use this property directly if you need a specific rule set property.

## Inheritors

Rule
Link copied to clipboard