From f8fcf0a4b567365b393b0687419d0b113ab63930 Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Wed, 2 Aug 2023 18:54:20 -0300 Subject: [PATCH] Remove kotlin migration related lint --- .../java/com/ichi2/anki/lint/IssueRegistry.kt | 4 - .../lint/rules/KotlinMigrationBrokenEmails.kt | 79 ------------------ .../rules/KotlinMigrationFixLineBreaks.kt | 81 ------------------- 3 files changed, 164 deletions(-) delete mode 100644 lint-rules/src/main/java/com/ichi2/anki/lint/rules/KotlinMigrationBrokenEmails.kt delete mode 100644 lint-rules/src/main/java/com/ichi2/anki/lint/rules/KotlinMigrationFixLineBreaks.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 493fe6c88e..aff29e9657 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 @@ -35,8 +35,6 @@ import com.ichi2.anki.lint.rules.FixedPreferencesTitleLength import com.ichi2.anki.lint.rules.HardcodedPreferenceKey import com.ichi2.anki.lint.rules.InvalidStringFormatDetector import com.ichi2.anki.lint.rules.JUnitNullAssertionDetector -import com.ichi2.anki.lint.rules.KotlinMigrationBrokenEmails -import com.ichi2.anki.lint.rules.KotlinMigrationFixLineBreaks import com.ichi2.anki.lint.rules.NonPositionalFormatSubstitutions import com.ichi2.anki.lint.rules.PrintStackTraceUsage import com.ichi2.anki.lint.rules.VariableNamingDetector @@ -59,8 +57,6 @@ class IssueRegistry : IssueRegistry() { DuplicateTextInPreferencesXml.ISSUE, HardcodedPreferenceKey.ISSUE, JUnitNullAssertionDetector.ISSUE, - KotlinMigrationBrokenEmails.ISSUE, - KotlinMigrationFixLineBreaks.ISSUE, PrintStackTraceUsage.ISSUE, NonPositionalFormatSubstitutions.ISSUE, FixedPreferencesTitleLength.ISSUE_MAX_LENGTH, diff --git a/lint-rules/src/main/java/com/ichi2/anki/lint/rules/KotlinMigrationBrokenEmails.kt b/lint-rules/src/main/java/com/ichi2/anki/lint/rules/KotlinMigrationBrokenEmails.kt deleted file mode 100644 index 4e9b4ea6dc..0000000000 --- a/lint-rules/src/main/java/com/ichi2/anki/lint/rules/KotlinMigrationBrokenEmails.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2021 David Allison - * - * 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.tools.lint.detector.api.* -import com.google.common.annotations.Beta -import com.google.common.annotations.VisibleForTesting -import com.ichi2.anki.lint.utils.Constants -import org.jetbrains.uast.UClass -import java.util.* -import java.util.regex.Pattern - -@Beta -class KotlinMigrationBrokenEmails : Detector(), SourceCodeScanner { - override fun getApplicableUastTypes() = listOf(UClass::class.java) - - override fun afterCheckFile(context: Context) { - val contents = context.getContents() - if (contents == null || !BAD_KOTLIN_MIGRATION_PATTERN.matcher(contents).find()) { - return - } - - // select from the start to the first line with content - var end = 0 - var foundChar = false - for (i in contents.indices) { - foundChar = foundChar or !Character.isWhitespace(contents[i]) - if (foundChar && contents[i] == '\n') { - end = i - break - } - } - - // If there is no line break, highlight the contents - val endOffset = if (end == 0) contents.length else end - val location: Location = Location.create(context.file, contents.subSequence(0, endOffset), 0, endOffset) - context.report(ISSUE, location, DESCRIPTION) - } - - companion object { - /** Java -> Kotlin converts // */ - private val BAD_KOTLIN_MIGRATION_PATTERN = Pattern.compile(Pattern.quote("")) - - @VisibleForTesting - val ID = "KotlinMigrationBrokenEmails" - - @VisibleForTesting - val DESCRIPTION = "Comment contents were corrupted by the Kotlin migration. For example: " - private const val EXPLANATION = " was detected in the file.\n" + - "Check all comments to see if this also affected emails.\n" + - "This can be fixed before conversion by changing the comments from /** to /* if appropriate" - private val implementation = Implementation(KotlinMigrationBrokenEmails::class.java, EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES)) - val ISSUE: Issue = Issue.create( - ID, - DESCRIPTION, - EXPLANATION, - Constants.ANKI_CODE_STYLE_CATEGORY, - Constants.ANKI_CODE_STYLE_PRIORITY, - Constants.ANKI_CODE_STYLE_SEVERITY, - implementation - ) - } -} diff --git a/lint-rules/src/main/java/com/ichi2/anki/lint/rules/KotlinMigrationFixLineBreaks.kt b/lint-rules/src/main/java/com/ichi2/anki/lint/rules/KotlinMigrationFixLineBreaks.kt deleted file mode 100644 index 04f8be7e44..0000000000 --- a/lint-rules/src/main/java/com/ichi2/anki/lint/rules/KotlinMigrationFixLineBreaks.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2021 David Allison - * Copyright (c) 2022 Akshit Sinha - * - * 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.tools.lint.detector.api.* -import com.google.common.annotations.Beta -import com.google.common.annotations.VisibleForTesting -import com.ichi2.anki.lint.utils.Constants -import org.jetbrains.uast.UClass -import java.util.* -import java.util.regex.Pattern - -@Beta -class KotlinMigrationFixLineBreaks : Detector(), SourceCodeScanner { - override fun getApplicableUastTypes() = listOf(UClass::class.java) - - override fun afterCheckFile(context: Context) { - val contents = context.getContents() - if (contents == null || !BAD_KOTLIN_MIGRATION_PATTERN.matcher(contents).find()) { - return - } - - // select from the start to the first line with content - var end = 0 - var foundChar = false - for (i in contents.indices) { - foundChar = foundChar or !Character.isWhitespace(contents[i]) - if (foundChar && contents[i] == '\n') { - end = i - break - } - } - - // If there is no line break, highlight the contents - // TODO: Improve the 'Location' code to be usable fot entire file, not just copyright header - val endOffset = if (end == 0) contents.length else end - val location: Location = Location.create(context.file, contents.subSequence(0, endOffset), 0, endOffset) - context.report(ISSUE, location, DESCRIPTION) - } - - companion object { - /** Java -> Kotlin converts
to

*/ - private val BAD_KOTLIN_MIGRATION_PATTERN = Pattern.compile(Pattern.quote("

")) - - @VisibleForTesting - val ID = "KotlinMigrationFixLineBreaks" - - @VisibleForTesting - val DESCRIPTION = "Tags were corrupted by the Kotlin migration. For example:

" - private const val EXPLANATION = "

was detected in the file.\n" + - "Please check the relevant piece of code.\n" + - "And change instances of

to a newline: Kotlin supports Markdown formatting." - private val implementation = Implementation(KotlinMigrationFixLineBreaks::class.java, EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES)) - val ISSUE: Issue = Issue.create( - ID, - DESCRIPTION, - EXPLANATION, - Constants.ANKI_CODE_STYLE_CATEGORY, - Constants.ANKI_CODE_STYLE_PRIORITY, - Constants.ANKI_CODE_STYLE_SEVERITY, - implementation - ) - } -}