Bump Spotless 6.14.0 -> 6.21.0 and KtLint 0.48.2 -> 0.50.0, and reformat/fix code

This commit is contained in:
Wolf-Martell Montwé 2023-09-06 17:55:46 +02:00
parent d31737923d
commit e9535ecdaa
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
10 changed files with 47 additions and 24 deletions

View file

@ -505,6 +505,7 @@ object K9 : EarlyInit {
const val MAIL_SERVICE_WAKE_LOCK_TIMEOUT = 60000
const val BOOT_RECEIVER_WAKE_LOCK_TIMEOUT = 60000
@Suppress("ktlint:standard:class-naming")
enum class BACKGROUND_OPS {
ALWAYS, NEVER, WHEN_CHECKED_AUTO_SYNC
}

View file

@ -59,7 +59,8 @@ internal object NotificationIds {
}
private fun getBaseNotificationId(account: Account): Int {
return 1 /* skip notification ID 0 */ + NUMBER_OF_GENERAL_NOTIFICATIONS +
/* skip notification ID 0 */
return 1 + NUMBER_OF_GENERAL_NOTIFICATIONS +
account.accountNumber * NUMBER_OF_NOTIFICATIONS_PER_ACCOUNT
}
}

View file

@ -184,7 +184,7 @@ class MessageViewContainerFragment : Fragment() {
val newPosition = viewPager.currentItem - 1
return if (newPosition >= 0) {
setActiveMessage(newPosition)
viewPager.setCurrentItem(newPosition, /* smoothScroll = */ false)
viewPager.setCurrentItem(newPosition, false)
true
} else {
false
@ -195,7 +195,7 @@ class MessageViewContainerFragment : Fragment() {
val newPosition = viewPager.currentItem + 1
return if (newPosition < adapter.itemCount) {
setActiveMessage(newPosition)
viewPager.setCurrentItem(newPosition, /* smoothScroll = */ false)
viewPager.setCurrentItem(newPosition, false)
true
} else {
false

View file

@ -7,6 +7,7 @@ plugins {
configure<SpotlessExtension> {
kotlin {
ktlint(libs.versions.ktlint.get())
.userData(mapOf("android" to "true"))
target("**/*.kt")
targetExclude("**/build/", "**/resources/", "plugins/openpgp-api-lib/")
}

View file

@ -24,7 +24,7 @@ object HostNameUtils {
address in dotted-decimal ("#.#.#.#") form. The host SHOULD check
the string syntactically for a dotted-decimal number before
looking it up in the Domain Name System.
*/
*/
return isLegalIPAddress(hostName) ?: isLegalHostName(hostName)
}
@ -204,7 +204,7 @@ object HostNameUtils {
Since a complete domain name ends with the root label, this leads to
a printed form which ends in a dot.
*/
*/
return hostName.takeIf { hostName.length <= 255 && HOST_PATTERN.matches(hostName) }
}

View file

@ -4,7 +4,7 @@
[versions]
gradle = "8.3"
androidGradlePlugin = "8.0.2"
ktlint = "0.48.2"
ktlint = "0.50.0"
kotlin = "1.8.22"
kotlinxCoroutines = "1.7.3"
@ -48,7 +48,7 @@ ksp = "com.google.devtools.ksp:1.8.22-1.0.11"
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
spotless = "com.diffplug.spotless:6.14.0"
spotless = "com.diffplug.spotless:6.21.0"
detekt = "io.gitlab.arturbosch.detekt:1.23.0"
dependency-check = "com.github.ben-manes.versions:0.46.0"

View file

@ -17,10 +17,12 @@ object MimeHeaderEncoder {
}
private fun exceedsRecommendedLineLength(name: String, value: String): Boolean {
return name.length + 2 /* colon + space */ + value.length > RECOMMENDED_MAX_LINE_LENGTH
return name.length + COLON_PLUS_SPACE_LENGTH + value.length > RECOMMENDED_MAX_LINE_LENGTH
}
private fun charactersNeedEncoding(text: String): Boolean {
return text.any { !it.isVChar() && !it.isWspOrCrlf() }
}
private const val COLON_PLUS_SPACE_LENGTH = 2
}

View file

@ -13,6 +13,12 @@ object MimeParameterEncoder {
private const val ENCODED_VALUE_PREFIX = "UTF-8''"
private const val FOLDING_SPACE_LENGTH = 1
private const val EQUAL_SIGN_LENGTH = 1
private const val SEMICOLON_LENGTH = 1
private const val QUOTES_LENGTH = 2
private const val ASTERISK_LENGTH = 1
/**
* Create header field value with parameters encoded if necessary.
*/
@ -35,9 +41,9 @@ object MimeParameterEncoder {
}
private fun StringBuilder.encodeAndAppendParameter(name: String, value: String) {
val fixedCostLength = 1 /* folding space */ + name.length + 1 /* equals sign */ + 1 /* semicolon */
val fixedCostLength = FOLDING_SPACE_LENGTH + name.length + EQUAL_SIGN_LENGTH + SEMICOLON_LENGTH
val unencodedValueFitsOnSingleLine = fixedCostLength + value.length <= MAX_LINE_LENGTH
val quotedValueMightFitOnSingleLine = fixedCostLength + value.length + 2 /* quotes */ <= MAX_LINE_LENGTH
val quotedValueMightFitOnSingleLine = fixedCostLength + value.length + QUOTES_LENGTH <= MAX_LINE_LENGTH
if (unencodedValueFitsOnSingleLine && value.isToken()) {
appendParameter(name, value)
@ -56,8 +62,8 @@ object MimeParameterEncoder {
}
private fun StringBuilder.rfc2231EncodeAndAppendParameter(name: String, value: String) {
val encodedValueLength = 1 /* folding space */ + name.length + 1 /* asterisk */ + 1 /* equal sign */ +
ENCODED_VALUE_PREFIX.length + value.rfc2231EncodedLength() + 1 /* semicolon */
val encodedValueLength = FOLDING_SPACE_LENGTH + name.length + ASTERISK_LENGTH + EQUAL_SIGN_LENGTH +
ENCODED_VALUE_PREFIX.length + value.rfc2231EncodedLength() + SEMICOLON_LENGTH
if (encodedValueLength <= MAX_LINE_LENGTH) {
appendRfc2231SingleLineParameter(name, value.rfc2231Encoded())
@ -88,7 +94,7 @@ object MimeParameterEncoder {
append(ENCODED_VALUE_PREFIX)
}
remainingSpaceInLine = MAX_LINE_LENGTH - (length - lineStartIndex) - 1 /* semicolon */
remainingSpaceInLine = MAX_LINE_LENGTH - (length - lineStartIndex) - SEMICOLON_LENGTH
if (remainingSpaceInLine < 3) {
throw UnsupportedOperationException("Parameter name too long")
}
@ -182,7 +188,7 @@ object MimeParameterEncoder {
}
private fun String.quotedLength(): Int {
var length = 2 /* start and end quote */
var length = QUOTES_LENGTH
for (c in this) {
if (c.isQText() || c.isWsp()) {
length++

View file

@ -58,25 +58,27 @@ class MimeHeaderCheckerTest {
@Test
fun singleLineAtMaximumLineLength() {
val longText = "x".repeat(998 /* text limit */ - 4 /* Test */ - 2 /* colon, space */)
val test = 4
val longText = "x".repeat(MAXIMUM_LINE_LENGTH - test - COLON_PLUS_SPACE_LENGTH)
assertValidHeader("Test: $longText")
}
@Test
fun firstLineAtMaximumLineLength() {
val longText = "x".repeat(998 /* text limit */ - 4 /* Test */ - 2 /* colon, space */)
val test = 4
val longText = "x".repeat(MAXIMUM_LINE_LENGTH - test - COLON_PLUS_SPACE_LENGTH)
assertValidHeader("Test: $longText\r\n Text")
}
@Test
fun middleLineAtMaximumLineLength() {
val longText = "x".repeat(998 - 1 /* space */)
val longText = "x".repeat(MAXIMUM_LINE_LENGTH - SPACE_LENGTH)
assertValidHeader("Test: One\r\n $longText\r\n Three")
}
@Test
fun lastLineAtMaximumLineLength() {
val longText = "x".repeat(998 - 1 /* space */)
val longText = "x".repeat(MAXIMUM_LINE_LENGTH - SPACE_LENGTH)
assertValidHeader("Test: One\r\n $longText")
}
@ -92,7 +94,7 @@ class MimeHeaderCheckerTest {
@Test
fun headerNameExceedingLineLimit() {
val longName = "x".repeat(998 - 2 /* space, colon */ + 1)
val longName = "x".repeat(MAXIMUM_LINE_LENGTH - COLON_PLUS_SPACE_LENGTH + 1)
assertInvalidHeader("$longName: ")
}
@ -173,25 +175,28 @@ class MimeHeaderCheckerTest {
@Test
fun singleLineExceedingLineLength() {
val longText = "x".repeat(998 /* text limit */ - 4 /* Test */ - 2 /* colon, space */ + 1)
val test = 4
val longText = "x".repeat(MAXIMUM_LINE_LENGTH - test - COLON_PLUS_SPACE_LENGTH + 1)
assertInvalidHeader("Test: $longText")
}
@Test
fun firstLineExceedingLineLength() {
val longText = "x".repeat(998 /* text limit */ - 4 /* Test */ - 2 /* colon, space */ + 1)
val test = 4
val longText = "x".repeat(MAXIMUM_LINE_LENGTH - test - COLON_PLUS_SPACE_LENGTH + 1)
assertInvalidHeader("Test: $longText\r\n Text")
}
@Test
fun middleLineExceedingLineLength() {
val longText = "x".repeat(998 - 1 /* space */ + 1)
val longText = "x".repeat(MAXIMUM_LINE_LENGTH - SPACE_LENGTH + 1)
assertInvalidHeader("Test: One\r\n $longText\r\n Three")
}
@Test
fun lastLineExceedingLineLength() {
val longText = "x".repeat(998 - 1 /* space */ + 1)
val longText = "x".repeat(MAXIMUM_LINE_LENGTH - SPACE_LENGTH + 1)
assertInvalidHeader("Test: One\r\n $longText")
}
@ -208,4 +213,10 @@ class MimeHeaderCheckerTest {
MimeHeaderChecker.checkHeader(name, value)
}.isInstanceOf<MimeHeaderParserException>()
}
private companion object {
private const val MAXIMUM_LINE_LENGTH = 998
private const val COLON_PLUS_SPACE_LENGTH = 2
private const val SPACE_LENGTH = 1
}
}

View file

@ -100,7 +100,8 @@ internal class RealImapFolder(
try {
return executeSimpleCommand(Commands.NOOP)
} catch (ioe: IOException) {
/* don't throw */ ioExceptionHandler(connection, ioe)
/* don't throw */
ioExceptionHandler(connection, ioe)
}
}