com.braisgabin.detekt.compiler.CompilerWarning.kt Maven / Gradle / Ivy
package com.braisgabin.detekt.compiler
import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Debt
import io.gitlab.arturbosch.detekt.api.Entity
import io.gitlab.arturbosch.detekt.api.Issue
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import io.gitlab.arturbosch.detekt.api.config
import org.jetbrains.kotlin.diagnostics.Severity.WARNING
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext
class CompilerWarning(config: Config) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.CodeSmell,
"Reports the warnings raised by the compiler",
Debt.FIVE_MINS,
)
private val ignoreDiagnostic: List by config(listOf("OPT_IN_IS_NOT_ENABLED"))
override fun visitKtFile(file: KtFile) {
if (bindingContext == BindingContext.EMPTY) return
bindingContext.diagnostics
.filterBySeverityAndFile(WARNING, file, ignoreDiagnostic)
.forEach { diagnostic ->
report(
CodeSmell(
issue,
Entity.from(diagnostic.psiElement),
"Kotlin compiler warning: ${diagnostic.factoryName}",
)
)
}
}
}