From b8756a667c56f67d14b25286f2568f3eb3e8e9f3 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 5 Mar 2022 19:17:48 +0530 Subject: Cleanup IDE reported lints in autofill-parser and format-common (#1765) --- .../autofillparser/AutofillScenario.kt | 2 +- .../lib/publicsuffixlist/PublicSuffixListData.kt | 20 ++++++++++---------- .../components/lib/publicsuffixlist/ext/ByteArray.kt | 1 - 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'autofill-parser/src') diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt index 66ef6d0e..33a2a3fd 100644 --- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt +++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt @@ -181,7 +181,7 @@ internal data class ClassifiedAutofillScenario( override val passwordFieldsToFillOnGenerate get() = newPassword override val passwordFieldsToSave - get() = if (newPassword.isNotEmpty()) newPassword else currentPassword + get() = newPassword.ifEmpty { currentPassword } } @RequiresApi(Build.VERSION_CODES.O) diff --git a/autofill-parser/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListData.kt b/autofill-parser/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListData.kt index 2bdf5f70..b64b1b2f 100644 --- a/autofill-parser/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListData.kt +++ b/autofill-parser/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListData.kt @@ -39,16 +39,16 @@ internal class PublicSuffixListData( val rule = findMatchingRule(domainLabels) - if (domainLabels.size == rule.size && rule[0][0] != PublicSuffixListData.EXCEPTION_MARKER) { + if (domainLabels.size == rule.size && rule[0][0] != EXCEPTION_MARKER) { // The domain is a public suffix. - return if (rule == PublicSuffixListData.PREVAILING_RULE) { + return if (rule == PREVAILING_RULE) { PublicSuffixOffset.PrevailingRule } else { PublicSuffixOffset.PublicSuffix } } - return if (rule[0][0] == PublicSuffixListData.EXCEPTION_MARKER) { + return if (rule[0][0] == EXCEPTION_MARKER) { // Exception rules hold the effective TLD plus one. PublicSuffixOffset.Offset(domainLabels.size - rule.size) } else { @@ -72,15 +72,15 @@ internal class PublicSuffixListData( val exceptionMatch = findExceptionMatch(domainLabelsBytes, wildcardMatch) if (exceptionMatch != null) { - return ("${PublicSuffixListData.EXCEPTION_MARKER}$exceptionMatch").split('.') + return ("$EXCEPTION_MARKER$exceptionMatch").split('.') } if (exactMatch == null && wildcardMatch == null) { - return PublicSuffixListData.PREVAILING_RULE + return PREVAILING_RULE } - val exactRuleLabels = exactMatch?.split('.') ?: PublicSuffixListData.EMPTY_RULE - val wildcardRuleLabels = wildcardMatch?.split('.') ?: PublicSuffixListData.EMPTY_RULE + val exactRuleLabels = exactMatch?.split('.') ?: EMPTY_RULE + val wildcardRuleLabels = wildcardMatch?.split('.') ?: EMPTY_RULE return if (exactRuleLabels.size > wildcardRuleLabels.size) { exactRuleLabels @@ -95,7 +95,7 @@ internal class PublicSuffixListData( // foo.bar.com // will look like: [foo, bar, com], [bar, com], [com]. The longest matching rule wins. - for (i in 0 until labels.size) { + for (i in labels.indices) { val rule = binarySearchRules(labels, i) if (rule != null) { @@ -118,7 +118,7 @@ internal class PublicSuffixListData( if (labels.size > 1) { val labelsWithWildcard = labels.toMutableList() for (labelIndex in 0 until labelsWithWildcard.size) { - labelsWithWildcard[labelIndex] = PublicSuffixListData.WILDCARD_LABEL + labelsWithWildcard[labelIndex] = WILDCARD_LABEL val rule = binarySearchRules(labelsWithWildcard, labelIndex) if (rule != null) { return rule @@ -135,7 +135,7 @@ internal class PublicSuffixListData( return null } - for (labelIndex in 0 until labels.size) { + for (labelIndex in labels.indices) { val rule = binarySearchExceptions(labels, labelIndex) if (rule != null) { return rule diff --git a/autofill-parser/src/main/java/mozilla/components/lib/publicsuffixlist/ext/ByteArray.kt b/autofill-parser/src/main/java/mozilla/components/lib/publicsuffixlist/ext/ByteArray.kt index 5665db60..9deb9275 100644 --- a/autofill-parser/src/main/java/mozilla/components/lib/publicsuffixlist/ext/ByteArray.kt +++ b/autofill-parser/src/main/java/mozilla/components/lib/publicsuffixlist/ext/ByteArray.kt @@ -19,7 +19,6 @@ private const val BITMASK = 0xff.toByte() * https://github.com/square/okhttp/blob/1977136/okhttp/src/main/kotlin/okhttp3/internal/publicsuffix/PublicSuffixDatabase.kt */ @Suppress("ComplexMethod", "NestedBlockDepth") -@OptIn(ExperimentalUnsignedTypes::class) internal fun ByteArray.binarySearch(labels: List, labelIndex: Int): String? { var low = 0 var high = size -- cgit v1.2.3