KT-39869 Add ObsoleteKotlinJsPackagesInspection inspection
- This inspection allows to migrate from `kotlin.dom|kotlin.browser` to `kotlinx.dom|kotlinx.browser` packages respectively - This inspection is available from the import statements, and also from the `Run migrations` action - ^KT-39869 Fixed
This commit is contained in:
committed by
Roman Golyshev
parent
ec087e8f3d
commit
75de352ce2
@@ -0,0 +1,6 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
This inspection reports usages of 'kotlin.dom' and 'kotlin.browser' packages which were moved to 'kotlinx.dom' and 'kotlinx.browser'
|
||||||
|
respectively in Kotlin 1.4+.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1314,11 +1314,16 @@ missing.documentation=Missing documentation
|
|||||||
library.should.be.updated.to.be.compatible.with.kotlin.1.3=Library should be updated to be compatible with Kotlin 1.3
|
library.should.be.updated.to.be.compatible.with.kotlin.1.3=Library should be updated to be compatible with Kotlin 1.3
|
||||||
it.s.prohibited.to.call.0.with.min.value.step.since.1.3=It''s prohibited to call {0} with MIN_VALUE step since 1.3
|
it.s.prohibited.to.call.0.with.min.value.step.since.1.3=It''s prohibited to call {0} with MIN_VALUE step since 1.3
|
||||||
obsolete.coroutine.usage.in.whole.fix.family.name=Fix experimental coroutines usages in the project
|
obsolete.coroutine.usage.in.whole.fix.family.name=Fix experimental coroutines usages in the project
|
||||||
|
obsolete.kotlin.js.packages.usage.in.whole.fix.family.name=Fix 'kotlin.dom' and 'kotlin.browser' packages usages in the project
|
||||||
apply.in.the.project.0=Apply in the project: {0}
|
apply.in.the.project.0=Apply in the project: {0}
|
||||||
obsolete.coroutine.usage.fix.family.name=Fix experimental coroutines usage
|
obsolete.coroutine.usage.fix.family.name=Fix experimental coroutines usage
|
||||||
|
obsolete.kotlin.browser.usage.fix.family.name=Fix 'kotlin.browser' package usage
|
||||||
|
obsolete.kotlin.dom.usage.fix.family.name=Fix 'kotlin.dom' package usage
|
||||||
0.is.expected.to.be.used.since.kotlin.1.3=`{0}` is expected to be used since Kotlin 1.3
|
0.is.expected.to.be.used.since.kotlin.1.3=`{0}` is expected to be used since Kotlin 1.3
|
||||||
methods.are.absent.in.coroutines.class.since.1.3=Methods are absent in coroutines class since 1.3
|
methods.are.absent.in.coroutines.class.since.1.3=Methods are absent in coroutines class since 1.3
|
||||||
experimental.coroutines.usages.are.obsolete.since.1.3=Experimental coroutines usages are obsolete since 1.3
|
experimental.coroutines.usages.are.obsolete.since.1.3=Experimental coroutines usages are obsolete since 1.3
|
||||||
|
kotlin.browser.usages.are.obsolete.since.1.3='kotlin.browser' package usages are obsolete since 1.4
|
||||||
|
kotlin.dom.usages.are.obsolete.since.1.3='kotlin.dom' package usages are obsolete since 1.4
|
||||||
replace.substring.call.with.droplast.call=Replace 'substring' call with 'dropLast' call
|
replace.substring.call.with.droplast.call=Replace 'substring' call with 'dropLast' call
|
||||||
replace.substring.call.with.indexing.operation.call=Replace 'substring' call with indexing operation call
|
replace.substring.call.with.indexing.operation.call=Replace 'substring' call with indexing operation call
|
||||||
replace.substring.call.with.substringbefore.call=Replace 'substring' call with 'substringBefore' call
|
replace.substring.call.with.substringbefore.call=Replace 'substring' call with 'substringBefore' call
|
||||||
@@ -2028,6 +2033,7 @@ inspection.suspicious.as.dynamic.display.name=Suspicious 'asDynamic' member invo
|
|||||||
inspection.convert.call.chain.into.sequence.display.name=Call chain on collection could be converted into 'Sequence' to improve performance
|
inspection.convert.call.chain.into.sequence.display.name=Call chain on collection could be converted into 'Sequence' to improve performance
|
||||||
inspection.redundant.with.display.name=Redundant 'with' call
|
inspection.redundant.with.display.name=Redundant 'with' call
|
||||||
inspection.obsolete.experimental.coroutines.display.name=Experimental coroutines usages are deprecated since 1.3
|
inspection.obsolete.experimental.coroutines.display.name=Experimental coroutines usages are deprecated since 1.3
|
||||||
|
inspection.obsolete.kotlin.js.packages.display.name='kotlin.browser' and 'kotlin.dom' packages are deprecated since 1.4
|
||||||
inspection.warning.on.main.unused.parameter.migration.display.name=Unused `args` on `main` since 1.4
|
inspection.warning.on.main.unused.parameter.migration.display.name=Unused `args` on `main` since 1.4
|
||||||
inspection.prohibit.repeated.use.site.target.annotations.migration.display.name=Repeatable annotation without `@Repeatable` are not allowed since 1.4
|
inspection.prohibit.repeated.use.site.target.annotations.migration.display.name=Repeatable annotation without `@Repeatable` are not allowed since 1.4
|
||||||
inspection.prohibit.use.site.target.annotations.on.super.types.migration.display.name=Annotations on superclass are meaningless since 1.4
|
inspection.prohibit.use.site.target.annotations.on.super.types.migration.display.name=Annotations on superclass are meaningless since 1.4
|
||||||
|
|||||||
@@ -2162,6 +2162,15 @@
|
|||||||
language="kotlin"
|
language="kotlin"
|
||||||
key="inspection.obsolete.experimental.coroutines.display.name" bundle="messages.KotlinBundle"/>
|
key="inspection.obsolete.experimental.coroutines.display.name" bundle="messages.KotlinBundle"/>
|
||||||
|
|
||||||
|
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.migration.ObsoleteKotlinJsPackagesInspection"
|
||||||
|
groupPath="Kotlin"
|
||||||
|
groupName="Migration"
|
||||||
|
enabledByDefault="true"
|
||||||
|
cleanupTool="true"
|
||||||
|
level="ERROR"
|
||||||
|
language="kotlin"
|
||||||
|
key="inspection.obsolete.kotlin.js.packages.display.name" bundle="messages.KotlinBundle"/>
|
||||||
|
|
||||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.RedundantWithInspection"
|
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.RedundantWithInspection"
|
||||||
groupPath="Kotlin"
|
groupPath="Kotlin"
|
||||||
groupName="Redundant constructs"
|
groupName="Redundant constructs"
|
||||||
|
|||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.inspections.migration
|
||||||
|
|
||||||
|
import com.intellij.codeInspection.*
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersion
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
|
|
||||||
|
internal class ObsoleteKotlinJsPackagesInspection : ObsoleteCodeMigrationInspection() {
|
||||||
|
override val fromVersion: LanguageVersion = LanguageVersion.KOTLIN_1_3
|
||||||
|
override val toVersion: LanguageVersion = LanguageVersion.KOTLIN_1_4
|
||||||
|
|
||||||
|
override val problems: List<ObsoleteCodeMigrationProblem> = listOf(
|
||||||
|
KotlinBrowserImportUsageProblem,
|
||||||
|
KotlinDomImportUsageProblem
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private object ObsoleteKotlinJsPackagesUsagesInWholeProjectFix : ObsoleteCodeInWholeProjectFix() {
|
||||||
|
override val inspectionName: String = ObsoleteKotlinJsPackagesInspection().shortName
|
||||||
|
override fun getFamilyName(): String = KotlinBundle.message("obsolete.kotlin.js.packages.usage.in.whole.fix.family.name")
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ObsoleteKotlinBrowserUsageFix(delegate: ObsoleteCodeFix) : ObsoleteCodeFixDelegateQuickFix(delegate) {
|
||||||
|
override fun getFamilyName(): String = KotlinBundle.message("obsolete.kotlin.browser.usage.fix.family.name")
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ObsoleteKotlinDomUsageFix(delegate: ObsoleteCodeFix) : ObsoleteCodeFixDelegateQuickFix(delegate) {
|
||||||
|
override fun getFamilyName(): String = KotlinBundle.message("obsolete.kotlin.dom.usage.fix.family.name")
|
||||||
|
}
|
||||||
|
|
||||||
|
private object KotlinBrowserImportUsageProblem : ObsoleteImportsUsage() {
|
||||||
|
override val textMarker: String = "browser"
|
||||||
|
override val packageBindings: Map<String, String> = mapOf("kotlin.browser" to "kotlinx.browser")
|
||||||
|
|
||||||
|
override val wholeProjectFix: LocalQuickFix = ObsoleteKotlinJsPackagesUsagesInWholeProjectFix
|
||||||
|
override fun problemMessage(): String = KotlinBundle.message("kotlin.browser.usages.are.obsolete.since.1.3")
|
||||||
|
|
||||||
|
override fun wrapFix(fix: ObsoleteCodeFix): LocalQuickFix = ObsoleteKotlinBrowserUsageFix(fix)
|
||||||
|
}
|
||||||
|
|
||||||
|
private object KotlinDomImportUsageProblem : ObsoleteImportsUsage() {
|
||||||
|
override val textMarker: String = "dom"
|
||||||
|
override val packageBindings: Map<String, String> = mapOf("kotlin.dom" to "kotlinx.dom")
|
||||||
|
|
||||||
|
override val wholeProjectFix: LocalQuickFix = ObsoleteKotlinJsPackagesUsagesInWholeProjectFix
|
||||||
|
override fun problemMessage(): String = KotlinBundle.message("kotlin.dom.usages.are.obsolete.since.1.3")
|
||||||
|
|
||||||
|
override fun wrapFix(fix: ObsoleteCodeFix): LocalQuickFix = ObsoleteKotlinDomUsageFix(fix)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.kotlin.idea.inspections.migration.ObsoleteKotlinJsPackagesInspection
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Fix 'kotlin.browser' package usage" "true"
|
||||||
|
// JS
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlin.<caret>browser.localStorage
|
||||||
|
import kotlin.dom.addClass
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Fix 'kotlin.browser' package usage" "true"
|
||||||
|
// JS
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.browser.localStorage
|
||||||
|
import kotlin.dom.addClass
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Fix 'kotlin.browser' package usage" "true"
|
||||||
|
// JS
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlin.<caret>browser.*
|
||||||
|
import kotlin.dom.*
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Fix 'kotlin.browser' package usage" "true"
|
||||||
|
// JS
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.browser.*
|
||||||
|
import kotlin.dom.*
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Fix 'kotlin.dom' package usage" "true"
|
||||||
|
// JS
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlin.browser.localStorage
|
||||||
|
import kotlin.<caret>dom.addClass
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Fix 'kotlin.dom' package usage" "true"
|
||||||
|
// JS
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlin.browser.localStorage
|
||||||
|
import kotlinx.dom.addClass
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Fix 'kotlin.dom' package usage" "true"
|
||||||
|
// JS
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlin.browser.*
|
||||||
|
import kotlin.<caret>dom.*
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Fix 'kotlin.dom' package usage" "true"
|
||||||
|
// JS
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlin.browser.*
|
||||||
|
import kotlinx.dom.*
|
||||||
+13
@@ -3531,6 +3531,19 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/obsoleteKotlinJsPackages")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class ObsoleteKotlinJsPackages extends AbstractQuickFixMultiFileTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTestWithExtraFile, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInObsoleteKotlinJsPackages() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/obsoleteKotlinJsPackages"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/optimizeImports")
|
@TestMetadata("idea/testData/quickfix/optimizeImports")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
@@ -9886,6 +9886,39 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/obsoleteKotlinJsPackages")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class ObsoleteKotlinJsPackages extends AbstractQuickFixTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInObsoleteKotlinJsPackages() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/obsoleteKotlinJsPackages"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlinBrowserPropertyImport.kt")
|
||||||
|
public void testKotlinBrowserPropertyImport() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserPropertyImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlinBrowserStarImport.kt")
|
||||||
|
public void testKotlinBrowserStarImport() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinBrowserStarImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlinDomPropertyImport.kt")
|
||||||
|
public void testKotlinDomPropertyImport() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomPropertyImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlinDomStarImport.kt")
|
||||||
|
public void testKotlinDomStarImport() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/obsoleteKotlinJsPackages/kotlinDomStarImport.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/optimizeImports")
|
@TestMetadata("idea/testData/quickfix/optimizeImports")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user