Skip to content

Fixed bug invalid check setup_version #504

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

Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).
### Fixed

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

## 3.1.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.XmlSuppressableInspectionTool;
import com.intellij.patterns.XmlAttributeValuePattern;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -54,24 +55,26 @@ public void visitXmlAttributeValue(final XmlAttributeValue value) {
return;
}

final String expectedName
= GetEditableModuleNameByRootFileUtil.execute(etcDirectory);
final String actualName = value.getValue();
if (actualName.equals(expectedName)) {
return;
final String attributeName = XmlAttributeValuePattern.getLocalName(value);
if (attributeName != null && attributeName.equals(ModuleXml.MODULE_ATTR_NAME)) {
final String expectedName
= GetEditableModuleNameByRootFileUtil.execute(etcDirectory);
final String actualName = value.getValue();
if (actualName.equals(expectedName)) {
return;
}
final InspectionBundle inspectionBundle = new InspectionBundle();
problemsHolder.registerProblem(
value,
inspectionBundle.message(
"inspection.moduleDeclaration.warning.wrongModuleName",
actualName,
expectedName
),
ProblemHighlightType.ERROR,
new XmlModuleNameQuickFix(expectedName)
);
}

final InspectionBundle inspectionBundle = new InspectionBundle();
problemsHolder.registerProblem(
value,
inspectionBundle.message(
"inspection.moduleDeclaration.warning.wrongModuleName",
actualName,
expectedName
),
ProblemHighlightType.ERROR,
new XmlModuleNameQuickFix(expectedName)
);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Test_TestModule" setup_version="1.0.0" />
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ModuleDeclarationInModuleXmlInspectionTest
private static final String MESSAGE_ID =
"inspection.moduleDeclaration.warning.wrongModuleName";
private static final String WRONG_MODULE_NAME = "Wrong_ModuleName";
private static final String SETUP_VERSION_ATTRIBUTE_VALUE = "1.0.0";

@Override
public void setUp() throws Exception {
Expand Down Expand Up @@ -46,6 +47,27 @@ public void testWrongDeclarationInEditableModule() {
assertHasHighlighting(errorMessage);
}

/**
* Inspection do not highlight wrong module name warning for setup version attribute.
*/
public void testSetupVersionNotErrorMessageInEditableModule() {
final Settings settings = Settings.getInstance(myFixture.getProject());
settings.magentoPath =
"/src/xml/ModuleDeclarationInModuleXmlInspection/"
+ "setupVersionNotErrorMessageInEditableModule";
myFixture.configureByFile(
getFixturePath("app/code/Test/TestModule/etc/" + ModuleXml.FILE_NAME)
);

final String errorMessage = inspectionBundle.message(
MESSAGE_ID,
SETUP_VERSION_ATTRIBUTE_VALUE,
"Test_TestModule"
);

assertHasNoHighlighting(errorMessage);
}

/**
* Inspection skips sub tags.
*/
Expand Down