Skip to content

Commit

Permalink
Limit Kotlin version warning suppression scope in build (#5156)
Browse files Browse the repository at this point in the history
* Apply Gradle plugin-specific Kotlin compilation flags only to plugin build

* Update code to Kotlin API 1.7
  • Loading branch information
3flex committed Aug 1, 2022
1 parent 5584794 commit 736524f
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 20 deletions.
11 changes: 2 additions & 9 deletions build-logic/src/main/kotlin/module.gradle.kts
Expand Up @@ -51,17 +51,10 @@ tasks.withType<Test>().configureEach {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = Versions.JVM_TARGET
apiVersion = "1.4"
freeCompilerArgs = listOf(
freeCompilerArgs += listOf(
"-progressive",
"-Xsuppress-version-warnings",
)
// Note: Currently there are warnings for detekt-gradle-plugin that seemingly can't be fixed
// until Gradle releases an update (https://github.com/gradle/gradle/issues/16345)
allWarningsAsErrors = when (project.name) {
"detekt-gradle-plugin" -> false
else -> project.findProperty("warningsAsErrors") == "true"
}
allWarningsAsErrors = project.findProperty("warningsAsErrors") == "true"
}
}

Expand Down
Expand Up @@ -72,7 +72,7 @@ abstract class Rule(
private fun computeSeverity(): SeverityLevel {
val configValue: String = valueOrNull(SEVERITY_KEY)
?: ruleSetConfig.valueOrDefault(SEVERITY_KEY, "warning")
return enumValueOf(configValue.toUpperCase(Locale.US))
return enumValueOf(configValue.uppercase(Locale.US))
}

/**
Expand Down
Expand Up @@ -42,7 +42,7 @@ class DetektPrinter(private val arguments: GeneratorArgs) {
check(ruleSet.length > 1) { "Rule set name must be not empty or less than two symbols." }
return """
|---
|title: ${ruleSet[0].toUpperCase()}${ruleSet.substring(1)} Rule Set
|title: ${ruleSet[0].uppercaseChar()}${ruleSet.substring(1)} Rule Set
|sidebar: home_sidebar
|keywords: [rules, $ruleSet]
|permalink: $ruleSet.html
Expand Down
12 changes: 12 additions & 0 deletions detekt-gradle-plugin/build.gradle.kts
Expand Up @@ -154,6 +154,18 @@ tasks.withType<Sign>().configureEach {
notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/13470")
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
apiVersion = "1.4"
freeCompilerArgs += listOf(
"-Xsuppress-version-warnings",
)
// Note: Currently there are warnings for detekt-gradle-plugin that seemingly can't be fixed
// until Gradle releases an update (https://github.com/gradle/gradle/issues/16345)
allWarningsAsErrors = false
}
}

afterEvaluate {
publishing {
publications.filterIsInstance<MavenPublication>().forEach {
Expand Down
Expand Up @@ -123,7 +123,7 @@ class HtmlOutputReport : OutputReport() {
span("description") { text(findings.first().issue.description) }
}

a("$DETEKT_WEBSITE_BASE_URL/docs/rules/${group.toLowerCase(Locale.US)}#${rule.toLowerCase(Locale.US)}") {
a("$DETEKT_WEBSITE_BASE_URL/docs/rules/${group.lowercase(Locale.US)}#${rule.lowercase(Locale.US)}") {
+"Documentation"
}

Expand Down
Expand Up @@ -97,7 +97,7 @@ private fun MarkdownContent.renderRule(rule: String, group: String, findings: Li
paragraph {
link(
"Documentation",
"$DETEKT_WEBSITE_BASE_URL/docs/rules/${group.toLowerCase(Locale.US)}#${rule.toLowerCase(Locale.US)}"
"$DETEKT_WEBSITE_BASE_URL/docs/rules/${group.lowercase(Locale.US)}#${rule.lowercase(Locale.US)}"
)
}

Expand Down
Expand Up @@ -36,8 +36,8 @@ private fun MultiRule.toDescriptors(ruleSetId: RuleSetId): List<ReportingDescrip
this.rules.map { it.toDescriptor(ruleSetId) }

private fun Rule.toDescriptor(ruleSetId: RuleSetId): ReportingDescriptor {
val formattedRuleSetId = ruleSetId.toLowerCase(Locale.US)
val formattedRuleId = ruleId.toLowerCase(Locale.US)
val formattedRuleSetId = ruleSetId.lowercase(Locale.US)
val formattedRuleId = ruleId.lowercase(Locale.US)

return ReportingDescriptor(
id = "detekt.$ruleSetId.$ruleId",
Expand Down
Expand Up @@ -276,7 +276,7 @@ private object Xml10EscapeSymbolsInitializer {
}

private operator fun ByteArray.set(c: Char, value: Byte) {
set(c.toInt(), value)
set(c.code, value)
}

/**
Expand Down
Expand Up @@ -17,7 +17,7 @@ class XmlOutputReport : OutputReport() {
override val name = "Checkstyle XML report"

private val Finding.severityLabel: String
get() = severity.name.toLowerCase(Locale.US)
get() = severity.name.lowercase(Locale.US)

override fun render(detektion: Detektion): String {
val smells = detektion.findings.flatMap { it.value }
Expand Down
Expand Up @@ -188,7 +188,7 @@ class XmlOutputFormatSpec {
@ParameterizedTest
@EnumSource(SeverityLevel::class)
fun `renders detektion with severity as XML with severity`(severity: SeverityLevel) {
val xmlSeverity = severity.name.toLowerCase(Locale.US)
val xmlSeverity = severity.name.lowercase(Locale.US)
val finding = object : CodeSmell(
issue = Issue("issue_id", Severity.CodeSmell, "issue description", Debt.FIVE_MINS),
entity = entity1,
Expand Down
Expand Up @@ -178,7 +178,7 @@ class MagicNumber(config: Config = Config.empty) : Rule(config) {

private fun normalizeForParsingAsDouble(text: String): String {
return text.trim()
.toLowerCase(Locale.US)
.lowercase(Locale.US)
.replace("_", "")
.removeSuffix("l")
.removeSuffix("d")
Expand Down
Expand Up @@ -105,7 +105,7 @@ class UnderscoresInNumericLiterals(config: Config = Config.empty) : Rule(config)

private fun normalizeForMatching(text: String): String {
return text.trim()
.toLowerCase(Locale.ROOT)
.lowercase(Locale.ROOT)
.removeSuffix("l")
.removeSuffix("d")
.removeSuffix("f")
Expand Down

0 comments on commit 736524f

Please sign in to comment.