From 0c0dfc2ecc30eb9e7d727d8dbb49aadd8e9c2697 Mon Sep 17 00:00:00 2001 From: "Tim K." Date: Thu, 28 May 2026 02:37:23 +0700 Subject: [PATCH] Fix inspection shortName mismatch with plugin.xml ComposeGuardInspection.getShortName() returned "ComposeRules" while plugin.xml registers shortName="ComposeGuard". The mismatch makes InspectionToolWrapper.getTool() throw PluginException on every LocalInspectionsPass, so the inspection never runs and idea.log fills with stacktraces. Align the class return value with plugin.xml and add a test that parses plugin.xml to guard against future drift. --- .../inspection/ComposeGuardInspection.kt | 2 +- .../inspection/InspectionRegistrationTest.kt | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 compose-guard/src/test/kotlin/io/androidpoet/composeguard/inspection/InspectionRegistrationTest.kt diff --git a/compose-guard/src/main/kotlin/io/androidpoet/composeguard/inspection/ComposeGuardInspection.kt b/compose-guard/src/main/kotlin/io/androidpoet/composeguard/inspection/ComposeGuardInspection.kt index 945d438..3658767 100644 --- a/compose-guard/src/main/kotlin/io/androidpoet/composeguard/inspection/ComposeGuardInspection.kt +++ b/compose-guard/src/main/kotlin/io/androidpoet/composeguard/inspection/ComposeGuardInspection.kt @@ -132,7 +132,7 @@ public class ComposeGuardInspection : LocalInspectionTool() { override fun getGroupDisplayName(): String = "Compose" - override fun getShortName(): String = "ComposeRules" + override fun getShortName(): String = "ComposeGuard" override fun isEnabledByDefault(): Boolean = true } diff --git a/compose-guard/src/test/kotlin/io/androidpoet/composeguard/inspection/InspectionRegistrationTest.kt b/compose-guard/src/test/kotlin/io/androidpoet/composeguard/inspection/InspectionRegistrationTest.kt new file mode 100644 index 0000000..cd157fa --- /dev/null +++ b/compose-guard/src/test/kotlin/io/androidpoet/composeguard/inspection/InspectionRegistrationTest.kt @@ -0,0 +1,39 @@ +/* + * Designed and developed by 2025 androidpoet (Ranbir Singh) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.androidpoet.composeguard.inspection + +import org.xml.sax.InputSource +import javax.xml.parsers.DocumentBuilderFactory +import kotlin.test.Test +import kotlin.test.assertEquals + +class InspectionRegistrationTest { + + @Test + fun shortNameInPluginXmlMatchesInspectionClass() { + val implClass = ComposeGuardInspection::class.java.name + val stream = javaClass.classLoader.getResourceAsStream("META-INF/plugin.xml")!! + val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(stream)) + val nodes = doc.getElementsByTagName("localInspection") + + val xmlShortName = (0 until nodes.length) + .map { nodes.item(it) } + .first { it.attributes.getNamedItem("implementationClass")?.nodeValue == implClass } + .attributes.getNamedItem("shortName").nodeValue + + assertEquals(xmlShortName, ComposeGuardInspection().shortName) + } +}