ConfigAware

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.

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.

Inheritors

Functions

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

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

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

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

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

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

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

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

Link copied to clipboard
open val active: Boolean

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.

Link copied to clipboard

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

Link copied to clipboard
open val parentPath: String?

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

Link copied to clipboard
abstract val ruleId: RuleId

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

Link copied to clipboard
abstract val ruleSetConfig: Config

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.