From 91c173c3f846a6e7bfce044af3209ca5afdf0a15 Mon Sep 17 00:00:00 2001
From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com>
Date: Wed, 2 Aug 2023 19:01:05 -0300
Subject: [PATCH] Remove DuplicateTextInPreferencesXml lint
Preferences layout previews work well now in Android Studio, so the dev can easily check their changes.
This way, the lint can be removed in order to increase performance
---
.../java/com/ichi2/anki/lint/IssueRegistry.kt | 2 -
.../rules/DuplicateTextInPreferencesXml.kt | 71 --------------
.../DuplicateTextInPreferencesXmlTest.kt | 96 -------------------
3 files changed, 169 deletions(-)
delete mode 100644 lint-rules/src/main/java/com/ichi2/anki/lint/rules/DuplicateTextInPreferencesXml.kt
delete mode 100644 lint-rules/src/test/java/com/ichi2/anki/lint/rules/DuplicateTextInPreferencesXmlTest.kt
diff --git a/lint-rules/src/main/java/com/ichi2/anki/lint/IssueRegistry.kt b/lint-rules/src/main/java/com/ichi2/anki/lint/IssueRegistry.kt
index aff29e96570d..3ac67aa3931d 100644
--- a/lint-rules/src/main/java/com/ichi2/anki/lint/IssueRegistry.kt
+++ b/lint-rules/src/main/java/com/ichi2/anki/lint/IssueRegistry.kt
@@ -30,7 +30,6 @@ import com.ichi2.anki.lint.rules.DirectSystemCurrentTimeMillisUsage
import com.ichi2.anki.lint.rules.DirectSystemTimeInstantiation
import com.ichi2.anki.lint.rules.DirectToastMakeTextUsage
import com.ichi2.anki.lint.rules.DuplicateCrowdInStrings
-import com.ichi2.anki.lint.rules.DuplicateTextInPreferencesXml
import com.ichi2.anki.lint.rules.FixedPreferencesTitleLength
import com.ichi2.anki.lint.rules.HardcodedPreferenceKey
import com.ichi2.anki.lint.rules.InvalidStringFormatDetector
@@ -54,7 +53,6 @@ class IssueRegistry : IssueRegistry() {
DirectSystemTimeInstantiation.ISSUE,
DirectToastMakeTextUsage.ISSUE,
DuplicateCrowdInStrings.ISSUE,
- DuplicateTextInPreferencesXml.ISSUE,
HardcodedPreferenceKey.ISSUE,
JUnitNullAssertionDetector.ISSUE,
PrintStackTraceUsage.ISSUE,
diff --git a/lint-rules/src/main/java/com/ichi2/anki/lint/rules/DuplicateTextInPreferencesXml.kt b/lint-rules/src/main/java/com/ichi2/anki/lint/rules/DuplicateTextInPreferencesXml.kt
deleted file mode 100644
index 9050e1729a63..000000000000
--- a/lint-rules/src/main/java/com/ichi2/anki/lint/rules/DuplicateTextInPreferencesXml.kt
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************************
- * Copyright (c) 2020 lukstbit <52494258+lukstbit@users.noreply.github.com> *
- * *
- * This program is free software; you can redistribute it and/or modify it under *
- * the terms of the GNU General Public License as published by the Free Software *
- * Foundation; either version 3 of the License, or (at your option) any later *
- * version. *
- * *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
- * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License along with *
- * this program. If not, see . *
- ****************************************************************************************/
-
-@file:Suppress("UnstableApiUsage")
-
-package com.ichi2.anki.lint.rules
-
-import com.android.resources.ResourceFolderType
-import com.android.tools.lint.detector.api.*
-import com.google.common.annotations.VisibleForTesting
-import com.ichi2.anki.lint.utils.Constants
-import org.w3c.dom.Element
-
-/**
- * A Lint check to prevent using the same string for the title and summary of a preference.
- */
-class DuplicateTextInPreferencesXml : ResourceXmlDetector() {
-
- companion object {
- @VisibleForTesting
- val ID = "DuplicateTextInPreferencesXml"
-
- @VisibleForTesting
- val DESCRIPTION = "Do not use the same string for the title and summary of a preference"
- private const val EXPLANATION = "Use different strings for the title and summary of a preference to better " +
- "explain what that preference is for"
- private val implementation = Implementation(DuplicateTextInPreferencesXml::class.java, Scope.RESOURCE_FILE_SCOPE)
- val ISSUE: Issue = Issue.create(
- ID,
- DESCRIPTION,
- EXPLANATION,
- Constants.ANKI_TIME_CATEGORY,
- Constants.ANKI_TIME_PRIORITY,
- Constants.ANKI_TIME_SEVERITY,
- implementation
- )
- private const val ATTR_TITLE = "android:title"
- private const val ATTR_SUMMARY = "android:summary"
- }
-
- override fun getApplicableElements(): Collection? {
- return ALL
- }
-
- override fun visitElement(context: XmlContext, element: Element) {
- if (element.hasAttribute(ATTR_TITLE) && element.hasAttribute(ATTR_SUMMARY)) {
- val titleValue = element.getAttribute(ATTR_TITLE)
- val summaryValue = element.getAttribute(ATTR_SUMMARY)
- if (titleValue == summaryValue) {
- context.report(ISSUE, element, context.getLocation(element), DESCRIPTION)
- }
- }
- }
-
- override fun appliesTo(folderType: ResourceFolderType): Boolean {
- return folderType == ResourceFolderType.XML
- }
-}
diff --git a/lint-rules/src/test/java/com/ichi2/anki/lint/rules/DuplicateTextInPreferencesXmlTest.kt b/lint-rules/src/test/java/com/ichi2/anki/lint/rules/DuplicateTextInPreferencesXmlTest.kt
deleted file mode 100644
index 7acdb09766ce..000000000000
--- a/lint-rules/src/test/java/com/ichi2/anki/lint/rules/DuplicateTextInPreferencesXmlTest.kt
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************************
- * Copyright (c) 2020 lukstbit <52494258+lukstbit@users.noreply.github.com> *
- * *
- * This program is free software; you can redistribute it and/or modify it under *
- * the terms of the GNU General Public License as published by the Free Software *
- * Foundation; either version 3 of the License, or (at your option) any later *
- * version. *
- * *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
- * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License along with *
- * this program. If not, see . *
- ****************************************************************************************/
-package com.ichi2.anki.lint.rules
-
-import com.android.tools.lint.checks.infrastructure.TestFiles
-import com.android.tools.lint.checks.infrastructure.TestLintTask.lint
-import org.intellij.lang.annotations.Language
-import org.junit.Test
-
-class DuplicateTextInPreferencesXmlTest {
- @Language("XML")
- private val invalidXmlFile =
- """
-
-
-
-
- """.trimIndent()
-
- @Language("XML")
- private val validXmlFile =
- """
-
-
-
-
- """.trimIndent()
-
- @Test
- fun showsErrorForInvalidFile() {
- lint()
- .allowMissingSdk()
- .allowCompilationErrors()
- .files(TestFiles.xml("res/xml/invalidpreference.xml", invalidXmlFile))
- .issues(DuplicateTextInPreferencesXml.ISSUE)
- .run()
- .expectErrorCount(2)
- .expect(
- """
- res/xml/invalidpreference.xml:1: Error: Do not use the same string for the title and summary of a preference [DuplicateTextInPreferencesXml]
-