Skip to content

Commit 71bbf42

Browse files
authored
Merge pull request #382 from drpayyne/issue-147
Inspection warning for disabling of an invalid plugin
2 parents a881357 + 3ab0e52 commit 71bbf42

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

resources/magento2/inspection.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
22
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.
3+
inspection.plugin.disabledPluginDoesNotExist=This plugin does not exist to be disabled.
34
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
45
inspection.graphql.resolver.notExist=Resolver class do not exist
56
inspection.graphql.resolver.fix.family=Implement Resolver interface

src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ public void visitFile(final PsiFile file) {
6161

6262
final HashMap<String, XmlTag> targetPluginHash = new HashMap<>();
6363
final PluginIndex pluginIndex = PluginIndex.getInstance(file.getProject());
64+
final HashMap<String, XmlTag> pluginProblems = new HashMap<>();
6465

6566
for (final XmlTag pluginXmlTag: xmlTags) {
66-
final HashMap<String, XmlTag> pluginProblems = new HashMap<>();
67+
pluginProblems.clear();
6768
if (!pluginXmlTag.getName().equals(ModuleDiXml.TYPE_TAG)) {
6869
continue;
6970
}
@@ -84,13 +85,7 @@ public void visitFile(final PsiFile file) {
8485
final XmlAttribute pluginTypeDisabledAttribute
8586
= pluginTypeXmlTag.getAttribute(ModuleDiXml.DISABLED_ATTR_NAME);
8687

87-
if (pluginTypeNameAttribute == null
88-
|| (
89-
pluginTypeDisabledAttribute != null //NOPMD
90-
&& pluginTypeDisabledAttribute.getValue() != null
91-
&& pluginTypeDisabledAttribute.getValue().equals("true")
92-
)
93-
) {
88+
if (pluginTypeNameAttribute == null) {
9489
continue;
9590
}
9691

@@ -116,6 +111,21 @@ public void visitFile(final PsiFile file) {
116111
pluginIndex,
117112
file
118113
);
114+
115+
if (pluginTypeDisabledAttribute != null
116+
&& pluginTypeDisabledAttribute.getValue() != null
117+
&& pluginTypeDisabledAttribute.getValue().equals("true")
118+
&& modulesWithSamePluginName.isEmpty()
119+
) {
120+
problemsHolder.registerProblem(
121+
pluginTypeNameAttribute.getValueElement(),
122+
inspectionBundle.message(
123+
"inspection.plugin.disabledPluginDoesNotExist"
124+
),
125+
errorSeverity
126+
);
127+
}
128+
119129
for (final Pair<String, String> moduleEntry: modulesWithSamePluginName) {
120130
final String scope = moduleEntry.getFirst();
121131
final String moduleName = moduleEntry.getSecond();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config>
9+
<type name="Magento\CatalogSearch\Helper\Data">
10+
<plugin name=<warning descr="This plugin does not exist to be disabled.">"plugin_which_does_not_exist"</warning> disabled="true" />
11+
</type>
12+
</config>

tests/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspectionTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public void testPluginNameDuplicationWarningWontShow() {
3535
myFixture.testHighlighting(true, false, false);
3636
}
3737

38+
/**
39+
* Tests warning for disabling of non-existing plugin.
40+
*/
41+
public void testDisabledNonExistingPlugin() {
42+
myFixture.configureByFile(getFixturePath(ModuleDiXml.FILE_NAME));
43+
myFixture.testHighlighting(true, false, false);
44+
}
45+
3846
/**
3947
* Tests whenever the duplication warning shows when the plugin name already
4048
* defined in the same di.xml file

0 commit comments

Comments
 (0)