From 2fa85150a25ac96a835acd6bcb14ced13eb121ae Mon Sep 17 00:00:00 2001 From: Andrey Vorobev Date: Thu, 11 Jul 2024 16:14:53 +0000 Subject: [PATCH] WEB-67650 React JSX: false positive attribute className is not allowed here with the new type evaluation Merge-request: IJ-MR-139501 Merged-by: Andrey Vorobev GitOrigin-RevId: cb4528978aa1dfb163066334cdf8ab723565fb7c --- .../HtmlUnknownAttributeInspectionBase.java | 20 +++++++++++++------ ...UnknownBooleanAttributeInspectionBase.java | 3 ++- .../HtmlUnknownElementInspection.java | 3 ++- .../XmlUnknownAttributeQuickFixProvider.java | 10 +++++++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspectionBase.java b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspectionBase.java index b4c03a797259..b9cee0fc11be 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspectionBase.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownAttributeInspectionBase.java @@ -17,6 +17,7 @@ package com.intellij.codeInspection.htmlInspections; import com.intellij.codeInsight.daemon.impl.analysis.RemoveAttributeIntentionFix; import com.intellij.codeInspection.LocalQuickFix; +import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; @@ -90,13 +91,14 @@ public class HtmlUnknownAttributeInspectionBase extends HtmlUnknownElementInspec ((XmlAttributeDescriptorEx)attributeDescriptor).validateAttributeName(attribute, holder, isOnTheFly); } - addUnknownXmlAttributeQuickFixes(tag, name, quickfixes, holder, isFixRequired); + var highlightType = addUnknownXmlAttributeQuickFixes(tag, name, quickfixes, holder, isFixRequired); if (!quickfixes.isEmpty()) { registerProblemOnAttributeName( attribute, XmlAnalysisBundle.message("xml.inspections.attribute.is.not.allowed.here", name), holder, + highlightType, quickfixes.toArray(LocalQuickFix.EMPTY_ARRAY) ); } @@ -116,13 +118,19 @@ public class HtmlUnknownAttributeInspectionBase extends HtmlUnknownElementInspec } } - private static void addUnknownXmlAttributeQuickFixes(XmlTag tag, - String name, - ArrayList quickfixes, - ProblemsHolder holder, - boolean isFixRequired) { + private static ProblemHighlightType addUnknownXmlAttributeQuickFixes(XmlTag tag, + String name, + ArrayList quickfixes, + ProblemsHolder holder, + boolean isFixRequired) { + var highlightType = ProblemHighlightType.GENERIC_ERROR_OR_WARNING; for (XmlUnknownAttributeQuickFixProvider fixProvider : XmlUnknownAttributeQuickFixProvider.EP_NAME.getExtensionList()) { quickfixes.addAll(fixProvider.getOrRegisterAttributeFixes(tag, name, holder, isFixRequired)); + var providerHighlightType = fixProvider.getProblemHighlightType(tag); + if (providerHighlightType != ProblemHighlightType.GENERIC_ERROR_OR_WARNING) { + highlightType = providerHighlightType; + } } + return highlightType; } } diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownBooleanAttributeInspectionBase.java b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownBooleanAttributeInspectionBase.java index 1292467c3a9c..f7ad70dfcfcd 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownBooleanAttributeInspectionBase.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownBooleanAttributeInspectionBase.java @@ -17,6 +17,7 @@ package com.intellij.codeInspection.htmlInspections; import com.intellij.codeInsight.daemon.impl.analysis.RemoveAttributeIntentionFix; import com.intellij.codeInspection.LocalQuickFix; +import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.XmlQuickFixFactory; import com.intellij.openapi.diagnostic.Logger; @@ -96,7 +97,7 @@ public class HtmlUnknownBooleanAttributeInspectionBase extends HtmlUnknownElemen error = XmlAnalysisBundle.message("html.inspections.attribute.is.not.boolean", attribute.getName()); } if (error != null) { - registerProblemOnAttributeName(attribute, error, holder, quickFixes); + registerProblemOnAttributeName(attribute, error, holder, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickFixes); } } } diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownElementInspection.java b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownElementInspection.java index 4759b5103de0..33a2e8029d3a 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownElementInspection.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownElementInspection.java @@ -55,6 +55,7 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo protected static void registerProblemOnAttributeName(@NotNull XmlAttribute attribute, @InspectionMessage String message, @NotNull ProblemsHolder holder, + @NotNull ProblemHighlightType highlightType, @NotNull LocalQuickFix @NotNull ... quickfixes) { final ASTNode node = attribute.getNode(); assert node != null; @@ -62,7 +63,7 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo if (nameNode != null) { final PsiElement nameElement = nameNode.getPsi(); if (nameElement.getTextLength() > 0) { - holder.registerProblem(nameElement, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickfixes); + holder.registerProblem(nameElement, message, highlightType, quickfixes); } } } diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/XmlUnknownAttributeQuickFixProvider.java b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/XmlUnknownAttributeQuickFixProvider.java index 2cd113dc04f3..d350a0b31d65 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/XmlUnknownAttributeQuickFixProvider.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/XmlUnknownAttributeQuickFixProvider.java @@ -2,10 +2,14 @@ package com.intellij.codeInspection.htmlInspections; import com.intellij.codeInspection.LocalQuickFix; +import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.psi.PsiElement; +import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -20,8 +24,12 @@ public interface XmlUnknownAttributeQuickFixProvider { * * @param tag tag with unknown attribute * @param name name of unknown attribute - * @param isFixRequired true if no check required, see {@link HtmlUnknownAttributeInspectionBase#checkAttribute(com.intellij.psi.xml.XmlAttribute, ProblemsHolder, boolean)} + * @param isFixRequired true if no check required, see {@link HtmlUnknownAttributeInspectionBase#checkAttribute(XmlAttribute, ProblemsHolder, boolean)} * @return collection of quick fixes for unknown attribute */ @NotNull Collection<@NotNull LocalQuickFix> getOrRegisterAttributeFixes(@NotNull XmlTag tag, @NotNull String name, ProblemsHolder holder, boolean isFixRequired); + + default @Nullable ProblemHighlightType getProblemHighlightType(@NotNull PsiElement element) { + return ProblemHighlightType.GENERIC_ERROR_OR_WARNING; + } }