Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspection warning for disabling of an invalid plugin #382

Merged
merged 6 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/magento2/inspection.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ public void visitFile(final PsiFile file) {

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

for (final XmlTag pluginXmlTag: xmlTags) {
final HashMap<String, XmlTag> pluginProblems = new HashMap<>();
pluginProblems.clear();
if (!pluginXmlTag.getName().equals(ModuleDiXml.TYPE_TAG)) {
continue;
}
Expand All @@ -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;
}

Expand All @@ -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<String, String> moduleEntry: modulesWithSamePluginName) {
final String scope = moduleEntry.getFirst();
final String moduleName = moduleEntry.getSecond();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config>
<type name="Magento\CatalogSearch\Helper\Data">
<plugin name=<warning descr="This plugin does not exist to be disabled.">"plugin_which_does_not_exist"</warning> disabled="true" />
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down