Skip to content

Commit

Permalink
Fix [#38](#38) (#42)
Browse files Browse the repository at this point in the history
* Fix [#38](#38)

* Fix [#40](#40)
  • Loading branch information
5peak2me authored Jun 29, 2022
1 parent b24e3e9 commit 7253697
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions gradlekotlinconverter.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if (!args.contains("skipintro")) {
println(intro)
}


var isInClipBoardMode = args.isEmpty()

val input = if (!isInClipBoardMode) args.first() else ""
Expand Down Expand Up @@ -420,15 +421,15 @@ fun String.addParentheses(): String {
// becomes
// id("io.gitlab.arturbosch.detekt") version "1.0.0.RC8"
fun String.addParenthesisToId(): String {

// this will only catch id "..." version ..., should skip id("...")
// should get the id "..."
val idExp = "id\\s*\".*?\"".toRegex()
val idExp = "(id)\\s*\"(.*?)\"".toRegex()

return this.replace(idExp) {
// remove the "id " before the real id
val idValue = it.value.replace("id\\s*".toRegex(), "")
"id($idValue)"
val (id, value) = it.destructured
"""$id("$value")"""
}
}

Expand All @@ -438,13 +439,14 @@ fun String.addParenthesisToId(): String {
// versionCode = 4
fun String.addEquals(): String {

val compileSdk = "compileSdk"
val signing = "keyAlias|keyPassword|storeFile|storePassword"
val other = "multiDexEnabled|correctErrorTypes|javaMaxHeapSize|jumboMode|dimension|useSupportLibrary"
val databinding = "dataBinding|viewBinding"
val defaultConfig = "applicationId|versionCode|versionName|testInstrumentationRunner"
val defaultConfig = "applicationId|minSdk|targetSdk|versionCode|versionName|testInstrumentationRunner"
val negativeLookAhead = "(?!\\{)[^\\s]" // Don't want '{' as next word character

val versionExp = """($defaultConfig|$signing|$other|$databinding)\s*${negativeLookAhead}.*""".toRegex()
val versionExp = """($compileSdk|$defaultConfig|$signing|$other|$databinding)\s*${negativeLookAhead}.*""".toRegex()

return this.replace(versionExp) {
val split = it.value.split(" ")
Expand Down

0 comments on commit 7253697

Please sign in to comment.