Skip to content

Commit cc10d62

Browse files
author
Vitaliy
authored
Merge pull request #504 from anzin/fix-bug-invalid-check-setup-version
Fixed bug invalid check setup_version
2 parents edcff33 + 07a3672 commit cc10d62

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).
1313
### Fixed
1414

1515
- Class completion doesn't display interfaces
16+
- Fixed invalid check 'setup_version' in the etc/module.xml
1617

1718
## 3.1.2
1819

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

+20-17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.codeInspection.ProblemHighlightType;
99
import com.intellij.codeInspection.ProblemsHolder;
1010
import com.intellij.codeInspection.XmlSuppressableInspectionTool;
11+
import com.intellij.patterns.XmlAttributeValuePattern;
1112
import com.intellij.psi.PsiDirectory;
1213
import com.intellij.psi.PsiElementVisitor;
1314
import com.intellij.psi.PsiFile;
@@ -54,24 +55,26 @@ public void visitXmlAttributeValue(final XmlAttributeValue value) {
5455
return;
5556
}
5657

57-
final String expectedName
58-
= GetEditableModuleNameByRootFileUtil.execute(etcDirectory);
59-
final String actualName = value.getValue();
60-
if (actualName.equals(expectedName)) {
61-
return;
58+
final String attributeName = XmlAttributeValuePattern.getLocalName(value);
59+
if (attributeName != null && attributeName.equals(ModuleXml.MODULE_ATTR_NAME)) {
60+
final String expectedName
61+
= GetEditableModuleNameByRootFileUtil.execute(etcDirectory);
62+
final String actualName = value.getValue();
63+
if (actualName.equals(expectedName)) {
64+
return;
65+
}
66+
final InspectionBundle inspectionBundle = new InspectionBundle();
67+
problemsHolder.registerProblem(
68+
value,
69+
inspectionBundle.message(
70+
"inspection.moduleDeclaration.warning.wrongModuleName",
71+
actualName,
72+
expectedName
73+
),
74+
ProblemHighlightType.ERROR,
75+
new XmlModuleNameQuickFix(expectedName)
76+
);
6277
}
63-
64-
final InspectionBundle inspectionBundle = new InspectionBundle();
65-
problemsHolder.registerProblem(
66-
value,
67-
inspectionBundle.message(
68-
"inspection.moduleDeclaration.warning.wrongModuleName",
69-
actualName,
70-
expectedName
71-
),
72-
ProblemHighlightType.ERROR,
73-
new XmlModuleNameQuickFix(expectedName)
74-
);
7578
}
7679
};
7780
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10+
<module name="Test_TestModule" setup_version="1.0.0" />
11+
</config>

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

+22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ModuleDeclarationInModuleXmlInspectionTest
1313
private static final String MESSAGE_ID =
1414
"inspection.moduleDeclaration.warning.wrongModuleName";
1515
private static final String WRONG_MODULE_NAME = "Wrong_ModuleName";
16+
private static final String SETUP_VERSION_ATTRIBUTE_VALUE = "1.0.0";
1617

1718
@Override
1819
public void setUp() throws Exception {
@@ -46,6 +47,27 @@ public void testWrongDeclarationInEditableModule() {
4647
assertHasHighlighting(errorMessage);
4748
}
4849

50+
/**
51+
* Inspection do not highlight wrong module name warning for setup version attribute.
52+
*/
53+
public void testSetupVersionNotErrorMessageInEditableModule() {
54+
final Settings settings = Settings.getInstance(myFixture.getProject());
55+
settings.magentoPath =
56+
"/src/xml/ModuleDeclarationInModuleXmlInspection/"
57+
+ "setupVersionNotErrorMessageInEditableModule";
58+
myFixture.configureByFile(
59+
getFixturePath("app/code/Test/TestModule/etc/" + ModuleXml.FILE_NAME)
60+
);
61+
62+
final String errorMessage = inspectionBundle.message(
63+
MESSAGE_ID,
64+
SETUP_VERSION_ATTRIBUTE_VALUE,
65+
"Test_TestModule"
66+
);
67+
68+
assertHasNoHighlighting(errorMessage);
69+
}
70+
4971
/**
5072
* Inspection skips sub tags.
5173
*/

0 commit comments

Comments
 (0)