diff --git a/resources/magento2/inspection.properties b/resources/magento2/inspection.properties index 15d190ce3..ede358bac 100644 --- a/resources/magento2/inspection.properties +++ b/resources/magento2/inspection.properties @@ -1,5 +1,6 @@ inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description. inspection.plugin.duplicateInOtherPlaces=The plugin name "{0}" for targeted "{1}" class is already used in the module "{2}" ({3} scope). For more details see Inspection Description. +inspection.plugin.disabledPluginDoesNotExist=This plugin does not exist to be disabled. inspection.graphql.resolver.mustImplement=Class must implements any of the following interfaces: \\Magento\\Framework\\GraphQl\\Query\\ResolverInterface, \\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchResolverInterface, \\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchServiceContractResolverInterface inspection.graphql.resolver.notExist=Resolver class do not exist inspection.graphql.resolver.fix.family=Implement Resolver interface diff --git a/src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java b/src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java index 18ae95d96..6fe323cdc 100644 --- a/src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java +++ b/src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java @@ -61,9 +61,10 @@ public void visitFile(final PsiFile file) { final HashMap targetPluginHash = new HashMap<>(); final PluginIndex pluginIndex = PluginIndex.getInstance(file.getProject()); + final HashMap pluginProblems = new HashMap<>(); for (final XmlTag pluginXmlTag: xmlTags) { - final HashMap pluginProblems = new HashMap<>(); + pluginProblems.clear(); if (!pluginXmlTag.getName().equals(ModuleDiXml.TYPE_TAG)) { continue; } @@ -84,13 +85,7 @@ public void visitFile(final PsiFile file) { final XmlAttribute pluginTypeDisabledAttribute = pluginTypeXmlTag.getAttribute(ModuleDiXml.DISABLED_ATTR_NAME); - if (pluginTypeNameAttribute == null - || ( - pluginTypeDisabledAttribute != null //NOPMD - && pluginTypeDisabledAttribute.getValue() != null - && pluginTypeDisabledAttribute.getValue().equals("true") - ) - ) { + if (pluginTypeNameAttribute == null) { continue; } @@ -116,6 +111,21 @@ public void visitFile(final PsiFile file) { pluginIndex, file ); + + if (pluginTypeDisabledAttribute != null + && pluginTypeDisabledAttribute.getValue() != null + && pluginTypeDisabledAttribute.getValue().equals("true") + && modulesWithSamePluginName.isEmpty() + ) { + problemsHolder.registerProblem( + pluginTypeNameAttribute.getValueElement(), + inspectionBundle.message( + "inspection.plugin.disabledPluginDoesNotExist" + ), + errorSeverity + ); + } + for (final Pair moduleEntry: modulesWithSamePluginName) { final String scope = moduleEntry.getFirst(); final String moduleName = moduleEntry.getSecond(); diff --git a/testData/inspections/xml/PluginDeclarationInspection/disabledNonExistingPlugin/di.xml b/testData/inspections/xml/PluginDeclarationInspection/disabledNonExistingPlugin/di.xml new file mode 100644 index 000000000..d5f9e4199 --- /dev/null +++ b/testData/inspections/xml/PluginDeclarationInspection/disabledNonExistingPlugin/di.xml @@ -0,0 +1,12 @@ + + + + + "plugin_which_does_not_exist" disabled="true" /> + + diff --git a/tests/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspectionTest.java b/tests/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspectionTest.java index f4f006d89..52ba9d8c8 100644 --- a/tests/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspectionTest.java +++ b/tests/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspectionTest.java @@ -35,6 +35,14 @@ public void testPluginNameDuplicationWarningWontShow() { myFixture.testHighlighting(true, false, false); } + /** + * Tests warning for disabling of non-existing plugin. + */ + public void testDisabledNonExistingPlugin() { + myFixture.configureByFile(getFixturePath(ModuleDiXml.FILE_NAME)); + myFixture.testHighlighting(true, false, false); + } + /** * Tests whenever the duplication warning shows when the plugin name already * defined in the same di.xml file