Skip to content

Commit

Permalink
Miscellaneous stuff / address some inspection hints (#34)
Browse files Browse the repository at this point in the history
* refactor(SemverSettings): Extract common regex options

Slightly deduplicate code.

* chore: Remove redundant semicolons

This addresses an inspection hint.
  • Loading branch information
sschuberth authored Sep 21, 2023
1 parent 6ebd563 commit 1372b84
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private const val MESSAGE = "Message"

class ChangeLogFormatter(private val settings: SemverSettings, private val format: ChangeLogSettings) {

private val changeLogRegex = format.changeLogPattern.toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE))
private val changeLogRegex = format.changeLogPattern.toRegex(SemverSettings.REGEX_OPTIONS)

internal fun formatLog(changeLog: List<Commit>): String {

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/git/semver/plugin/gradle/PrintTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ open class PrintTask @Inject constructor(private val prop: () -> Any, desc: Stri

@TaskAction
fun print() {
val fileName = this.file;
val fileName = this.file
if (fileName != null) {
File(fileName).writeText(prop().toString(), StandardCharsets.UTF_8)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/git/semver/plugin/semver/SemVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,6 @@ class SemVersion(
val isPreRelease
get() = prefix.isNotEmpty() || number != null

override fun toString() = prefix + (number ?: "");
override fun toString() = prefix + (number ?: "")
}
}
11 changes: 7 additions & 4 deletions src/main/kotlin/git/semver/plugin/semver/SemverSettings.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package git.semver.plugin.semver

open class SemverSettings {
companion object {
val REGEX_OPTIONS = setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)
}

var defaultPreRelease = "SNAPSHOT"
var releasePattern = "\\Arelease(?:\\([^()]+\\))?:"
Expand All @@ -14,8 +17,8 @@ open class SemverSettings {
var noDirtyCheck = false
var noAutoBump = false

internal val releaseRegex: Regex by lazy { releasePattern.toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)) }
internal val patchRegex: Regex by lazy { patchPattern.toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)) }
internal val minorRegex: Regex by lazy { minorPattern.toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)) }
internal val majorRegex: Regex by lazy { majorPattern.toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)) }
internal val releaseRegex: Regex by lazy { releasePattern.toRegex(REGEX_OPTIONS) }
internal val patchRegex: Regex by lazy { patchPattern.toRegex(REGEX_OPTIONS) }
internal val minorRegex: Regex by lazy { minorPattern.toRegex(REGEX_OPTIONS) }
internal val majorRegex: Regex by lazy { majorPattern.toRegex(REGEX_OPTIONS) }
}

0 comments on commit 1372b84

Please sign in to comment.