Skip to content

Commit

Permalink
style: apply the latest Detekt and Ktlint formatting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
DanySK committed Apr 19, 2023
1 parent f84d863 commit b00fc19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GitSemVer : Plugin<Project> {
"The version '$it' is not a valid semantic versioning format"
}
project.logger.lifecycle(
"Forcing version to $it, mandated by property '$forceVersionPropertyName'"
"Forcing version to $it, mandated by property '$forceVersionPropertyName'",
)
project.version = it.toString()
} ?: run { assignGitSemanticVersion() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ open class GitSemVerExtension @JvmOverloads constructor(
val reachableCommits = runCommand("git", "rev-list", "HEAD")?.lines()?.toSet() ?: emptySet()
val tagMatcher = Regex(
"""^(\w*)\s+(${
if (includeLightweightTags.get()) "commit|" else ""
if (includeLightweightTags.get()) "commit|" else ""
}tag)\s+refs/tags/${
versionPrefix.get()
versionPrefix.get()
}(${
SemanticVersion.semVerRegexString
})$"""
SemanticVersion.semVerRegexString
})$""",
)
logger.debug("Reachable commits: $reachableCommits")
return runCommand("git", "for-each-ref", "refs/tags", "--sort=-version:refname")
Expand Down Expand Up @@ -131,7 +131,7 @@ open class GitSemVerExtension @JvmOverloads constructor(
val separator = if (devString.isBlank()) "" else preReleaseSeparator.get()
val distanceString = distance.withRadix(
distanceCounterRadix.get(),
developmentCounterLength.get()
developmentCounterLength.get(),
)
val buildSeparator = buildMetadataSeparator.get()
"$base$separator$devString$distanceString$buildSeparator$hash".take(maxVersionLength.get())
Expand Down Expand Up @@ -191,8 +191,11 @@ open class GitSemVerExtension @JvmOverloads constructor(
.takeIf { it.isNotEmpty() }

private fun Long.withRadix(radix: Int, digits: Int? = null) = toString(radix).let {
if (digits == null || it.length >= digits) it
else it.padStart(digits, '0')
if (digits == null || it.length >= digits) {
it
} else {
it.padStart(digits, '0')
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ data class PreReleaseIdentifier(
segment.toULongOrNull()
?.let { DotSeparatedIdentifier.NumericIdentifier(it) }
?: DotSeparatedIdentifier.AlphanumericIdentifier(segment)
}
},
)

/**
Expand Down
12 changes: 6 additions & 6 deletions src/test/kotlin/org/danilopianini/gradle/gitsemver/test/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal class Tests : StringSpec(
developmentIdentifier.set("") // <--- NOTICE THIS
noTagIdentifier.set("") // <--- NOTICE THIS
developmentCounterLength.set(2)
""".trimIndent()
""".trimIndent(),
)
val result = workingDirectory.runGradle()
val expectedVersion = "0.1.0+"
Expand All @@ -104,7 +104,7 @@ internal class Tests : StringSpec(
val workingDirectory = configuredPlugin(
"""
excludeLightweightTags()
""".trimIndent()
""".trimIndent(),
)
with(workingDirectory) {
initGit()
Expand All @@ -126,12 +126,12 @@ internal class Tests : StringSpec(
val result = configuredPlugin(
"""
forceVersionPropertyName.set("customVersion")
""".trimIndent()
""".trimIndent(),
).runGradle("-PcustomVersion=1.2.3", "printGitSemVer", "--stacktrace")
print(result)
result shouldContain "1.2.3"
}
}
},
) {
companion object {

Expand All @@ -156,7 +156,7 @@ internal class Tests : StringSpec(

fun TemporaryFolder.runCommand(command: String, wait: Long = 10) = runCommand(
*command.split(" ").toTypedArray(),
wait = wait
wait = wait,
)

fun TemporaryFolder.initGit() {
Expand All @@ -179,7 +179,7 @@ internal class Tests : StringSpec(
}

fun TemporaryFolder.runGradle(
vararg arguments: String = arrayOf("printGitSemVer", "--stacktrace")
vararg arguments: String = arrayOf("printGitSemVer", "--stacktrace"),
): String = GradleRunner
.create()
.withProjectDir(root)
Expand Down

0 comments on commit b00fc19

Please sign in to comment.