com.jetbrains.pluginverifier.response.sarif.SarifRulesConverter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of verifier-intellij Show documentation
Show all versions of verifier-intellij Show documentation
JetBrains Plugin Verifier Classes for IntelliJ Platform integration with API usage detection and reporting.
The newest version!
package com.jetbrains.pluginverifier.response.sarif
import com.jetbrains.pluginverifier.PluginVerificationResult
internal fun PluginVerificationResult.Verified.buildRules(): List {
val warningsStructureRules = buildPluginStructureWarningsRules()
val compatibilityWarningsRules = buildCompatibilityWarningsRules()
val compatibilityProblemsRules = buildCompatibilityProblemRules()
val apiUsagesRules = buildApiUsageRules()
return warningsStructureRules + compatibilityWarningsRules + compatibilityProblemsRules + apiUsagesRules
}
internal fun PluginVerificationResult.InvalidPlugin.buildPluginStructureRules(): List {
if (pluginStructureErrors.isEmpty()) return emptyList()
val defaultError = pluginStructureErrors.first()
return listOf(
Rule(
id = defaultError.javaClass.simpleName,
shortDescription = Message(defaultError.problemType),
fullDescription = Message(defaultError.problemType),
defaultConfiguration = RuleConfiguration(
level = SeverityValue.ERROR.id,
parameters = RuleParameters(
ideaSeverity = SeverityIdea.ERROR
)
)
)
)
}
internal fun PluginVerificationResult.buildSingleRule(): List {
return listOf(
Rule(
id = this.javaClass.simpleName,
shortDescription = Message(this.verificationVerdict),
fullDescription = Message(this.verificationVerdict),
defaultConfiguration = RuleConfiguration(
level = SeverityValue.ERROR.id,
parameters = RuleParameters(
ideaSeverity = SeverityIdea.ERROR
)
)
)
)
}
private fun PluginVerificationResult.Verified.buildApiUsageRules(): List {
val apiUsages = deprecatedUsages + experimentalApiUsages + internalApiUsages + nonExtendableApiUsages + overrideOnlyMethodUsages
return apiUsages.map {
Rule(
id = it.javaClass.simpleName,
shortDescription = Message(it.problemType),
fullDescription = Message(it.problemType),
defaultConfiguration = RuleConfiguration(
level = SeverityValue.ERROR.id,
parameters = RuleParameters(
ideaSeverity = SeverityIdea.ERROR
)
)
)
}.distinctBy { it.id }
}
private fun PluginVerificationResult.Verified.buildCompatibilityProblemRules(): List {
return compatibilityProblems.map {
Rule(
id = it.javaClass.simpleName,
shortDescription = Message(it.problemType),
fullDescription = Message(it.problemType),
defaultConfiguration = RuleConfiguration(
level = SeverityValue.ERROR.id,
parameters = RuleParameters(
ideaSeverity = SeverityIdea.ERROR
)
)
)
}.distinctBy { it.id }
}
private fun PluginVerificationResult.Verified.buildCompatibilityWarningsRules(): List {
return compatibilityWarnings.map {
Rule(
id = it.javaClass.simpleName,
shortDescription = Message(it.problemType),
fullDescription = Message(it.problemType),
defaultConfiguration = RuleConfiguration(
level = SeverityValue.WARNING.id,
parameters = RuleParameters(
ideaSeverity = SeverityIdea.WARNING
)
)
)
}.distinctBy { it.id }
}
private fun PluginVerificationResult.Verified.buildPluginStructureWarningsRules(): List {
if (pluginStructureWarnings.isEmpty()) return emptyList()
val defaultWarning = pluginStructureWarnings.first()
return listOf(
Rule(
id = defaultWarning.javaClass.simpleName,
shortDescription = Message(defaultWarning.problemType),
fullDescription = Message(defaultWarning.problemType),
defaultConfiguration = RuleConfiguration(
level = SeverityValue.WARNING.id,
parameters = RuleParameters(
ideaSeverity = SeverityIdea.WARNING
)
)
)
)
}