Skip to content

Commit

Permalink
#417 | Inspection rule: validate that lang column attribute value i…
Browse files Browse the repository at this point in the history
…s present in the `lang.packs`
  • Loading branch information
mlytvyn authored May 21, 2023
1 parent 48fa850 commit 863920e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions resources/META-INF/plugin-inspections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.cockpitng.CngContextParentIsNotValid"/>

<!-- Impex -->
<localInspection groupPath="SAP Commerce" shortName="ImpexLanguageIsNotSupportedInspection" displayName="[y] Language is not supported"
groupName="[y] Impex" level="ERROR" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexLanguageIsNotSupportedInspection"/>

<localInspection groupPath="SAP Commerce" shortName="ImpexNoUniqueValueInspection" displayName="[y] No unique value in column"
groupName="[y] Impex" level="WEAK WARNING" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexNoUniqueValueInspection"/>
Expand Down
1 change: 1 addition & 0 deletions resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<li><i>Feature:</i> <strong>Impex</strong> enhancements
<ul>
<li>Added code completion of all available languages for <code>lang</code> column attribute (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/416" target="_blank" rel="nofollow">#416</a>)</li>
<li>Inspection rule: validate that <code>lang</code> column attribute value is present in the <code>lang.packs</code> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/417" target="_blank" rel="nofollow">#417</a>)</li>
</ul>
</li>
<li><i>Feature:</i> Added Node.js version 18 to the CCv2 js-storefront manifest file (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/413" target="_blank" rel="nofollow">#413</a>)</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
~ This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
~ Copyright (C) 2019 EPAM Systems <[email protected]>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<html>
<body>
Only languages specified in the <code>lang.packs</code> can be used for localized attributes.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.intellij.idea.plugin.hybris.codeInspection.rule.impex

import com.intellij.codeHighlighting.HighlightDisplayLevel
import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils.message
import com.intellij.idea.plugin.hybris.impex.constants.modifier.AttributeModifier
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAnyAttributeName
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAnyAttributeValue
import com.intellij.idea.plugin.hybris.impex.psi.ImpexVisitor
import com.intellij.idea.plugin.hybris.properties.PropertiesService
import com.intellij.psi.util.PsiTreeUtil

class ImpexLanguageIsNotSupportedInspection : LocalInspectionTool() {

override fun getDefaultLevel(): HighlightDisplayLevel = HighlightDisplayLevel.ERROR
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = object : ImpexVisitor() {

override fun visitAnyAttributeValue(psi: ImpexAnyAttributeValue) {
PsiTreeUtil.getPrevSiblingOfType(psi, ImpexAnyAttributeName::class.java)
?.takeIf { AttributeModifier.LANG.modifierName == it.text }
?: return

val language = psi.text
val supportedLanguages = PropertiesService.getInstance(psi.project).getLanguages()

if (supportedLanguages.contains(language)) return

holder.registerProblem(
psi,
message(
"hybris.inspections.language.unsupported",
language,
supportedLanguages.joinToString()
)
)
}
}
}

0 comments on commit 863920e

Please sign in to comment.