Skip to content

Commit

Permalink
style: ktfmt 0.49 format
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon406 committed May 30, 2024
1 parent ed84b00 commit 0f9d983
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 28 deletions.
3 changes: 1 addition & 2 deletions app/src/main/kotlin/me/leon/ext/File.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ fun File.realExtension() =
} else {
magics[key]
})
}
?: "$extension(probably)".also { println("unknown magic number $this $name") }
} ?: "$extension(probably)".also { println("unknown magic number $this $name") }
}
}
} else {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/kotlin/me/leon/ext/Net.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ fun String.readBytesFromNet(
}
.takeIf { it.responseCode == RESPONSE_OK || it.responseCode == RESPONSE_NOT_FOUND }
?.stream()
?.readBytes()
?: byteArrayOf()
?.readBytes() ?: byteArrayOf()
}
.getOrElse {
println("read bytes err ${it.stacktrace()} ")
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/kotlin/me/leon/ext/ocr/BaiduOcr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ object BaiduOcr {
.also { println(it) }
.fromJson(BaiduOcrBean::class.java)
.results
?.joinToString(System.lineSeparator()) { it.words }
?: error("request failed")
?.joinToString(System.lineSeparator()) { it.words } ?: error("request failed")
}
}
7 changes: 2 additions & 5 deletions app/src/main/kotlin/me/leon/view/EncodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class EncodeView : Fragment(messages["encodeAndDecode"]) {
isEncode ||
encodeType in arrayOf(EncodeType.DECIMAL, EncodeType.OCTAL) ||
fileMode.get()
}
?: taInput.text.takeUnless { decodeIgnoreSpace.get() }
?: taInput.text.stripAllSpace()
} ?: taInput.text.takeUnless { decodeIgnoreSpace.get() } ?: taInput.text.stripAllSpace()

private val outputText: String
get() = taOutput.text
Expand Down Expand Up @@ -350,8 +348,7 @@ class EncodeView : Fragment(messages["encodeAndDecode"]) {
?.run {
encodeMethods.add(first)
encoded = second
}
?: break
} ?: break
}
encodeMethods.mapIndexed { i, type -> "${i + 1} $type" }.joinToString("-->")
} ui
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/kotlin/me/leon/view/StringProcessView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,7 @@ class StringProcessView : Fragment(messages["stringProcess"]) {
.lines()
.filter { it.isNotEmpty() }
.map { it.toFile() }
.firstOrNull { it.exists() && it.name.contains(dictType) }
?: defaultFile
.firstOrNull { it.exists() && it.name.contains(dictType) } ?: defaultFile
} else {
defaultFile
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ class TranslateTest {
runCatching { translatedFile.readText() }
.getOrNull()
?.lines()
?.map { it.split("\t")[0] }
?: emptyList()
?.map { it.split("\t")[0] } ?: emptyList()
val lines = toTranslate.readText().lines()
val exclusion = noTranslation.readText().lines().toSet()
val diff = lines - translated.toSet() - exclusion
Expand Down
2 changes: 1 addition & 1 deletion config/codeQuality.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ spotless {
kotlin {
target "src/**/*.kt"
// https://github.com/facebookincubator/ktfmt/releases
ktfmt('0.44').kotlinlangStyle()
ktfmt('0.49').kotlinlangStyle()
}
}
2 changes: 1 addition & 1 deletion config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ style:
CanBeNonNullable:
active: false
CascadingCallWrapping:
active: true
active: false
ClassOrdering:
active: true
CollapsibleIfStatements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ fun String.methodParse(): String {
tmp = tmp.methodParse()
}
replace(this.groupValues.first(), this.groupValues[1].methodCall(tmp))
}
?: this
} ?: this
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ object HttpUrlUtil {

fun Map<String, Any>.toParams(isEncode: Boolean = false) =
entries.joinToString("&") {
(it.key.takeUnless { isEncode }
?: it.key.urlEncoded) +
(it.key.takeUnless { isEncode } ?: it.key.urlEncoded) +
"=" +
(it.value.takeUnless { isEncode } ?: it.value.toString().urlEncoded)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ object NetHelper {
URLDecoder.decode(
response.getHeaderField("Content-Disposition")?.let { getFileName(it) }
?: response.getHeaderField("content-disposition")?.let { getFileName(it) }
?: getUrlFileName(response.url.toString())
?: "unknownfile_${System.currentTimeMillis()}"
?: getUrlFileName(response.url.toString())
?: "unknownfile_${System.currentTimeMillis()}"
)
)

private fun getCorrectUrl(url: String) =
url.toByteArray(Charsets.ISO_8859_1).toString(Charsets.UTF_8).takeIf {
REG_CHINESE.matcher(it).find()
}
?: url
} ?: url

/**
* 通过 ‘?’ 和 ‘/’ 判断文件名
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@ class LocationParse {
?: bean.pois?.firstOrNull {
it.name?.run {
contains(addr[2]) && contains("居委会|村委会|综合服务中心|党群服务中心".toRegex())
}
?: false
} ?: false
}
?: bean.pois?.first().also {
?: bean.pois?.first().also {
println("$location 可能不准确 \n\t\t${bean.pois}")
}
calculateDistance(poi, addr, location)
Expand Down

0 comments on commit 0f9d983

Please sign in to comment.