From 357766bf51e8938298a69b422e7e67989b451252 Mon Sep 17 00:00:00 2001 From: Nicolas QUINQUENEL Date: Tue, 24 Sep 2024 13:59:49 +0200 Subject: [PATCH 1/2] SLI-1617 Add INFO and BLOCKER impact severity levels --- gradle/libs.versions.toml | 2 +- .../org/sonarlint/intellij/SonarLintIcons.kt | 28 ++++++++++++----- .../config/SonarLintColorSettingsPage.java | 31 ++++++++++--------- .../config/SonarLintTextAttributes.java | 4 +++ .../editor/SonarExternalAnnotator.java | 8 +++-- .../ui/ruledescription/RuleHeaderPanel.kt | 5 ++- .../ui/tree/IssueTreeModelBuilder.java | 2 +- .../util/RoundedPanelWithBackgroundColor.kt | 22 +++++++------ .../intellij/util/SonarLintSeverity.java | 8 +++-- src/main/resources/images/impact/blocker.svg | 3 ++ src/main/resources/images/impact/high.svg | 24 +------------- src/main/resources/images/impact/info.svg | 3 ++ src/main/resources/images/impact/low.svg | 24 +------------- src/main/resources/images/impact/medium.svg | 24 +------------- .../sonarlint/intellij/SonarLintIconsTest.kt | 8 +++++ .../SonarLintColorSettingsPageTests.java | 8 +++-- .../editor/SonarExternalAnnotatorTests.java | 12 ++++--- .../ui/tree/IssueTreeModelBuilderTests.java | 6 +++- 18 files changed, 107 insertions(+), 115 deletions(-) create mode 100644 src/main/resources/images/impact/blocker.svg create mode 100644 src/main/resources/images/impact/info.svg diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 35dcaa1458..71bce2ddc6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -sonarlint-core = "10.6.0.79030" +sonarlint-core = "10.6.0.79033" sonar-java = "8.1.0.36477" sonar-javascript = "10.15.0.27423" diff --git a/src/main/java/org/sonarlint/intellij/SonarLintIcons.kt b/src/main/java/org/sonarlint/intellij/SonarLintIcons.kt index 0d9692caef..9e2a4fb541 100644 --- a/src/main/java/org/sonarlint/intellij/SonarLintIcons.kt +++ b/src/main/java/org/sonarlint/intellij/SonarLintIcons.kt @@ -91,9 +91,11 @@ object SonarLintIcons { ) private val IMPACT_ICONS = mapOf( + ImpactSeverity.BLOCKER to getIcon("/images/impact/blocker.svg"), ImpactSeverity.HIGH to getIcon("/images/impact/high.svg"), ImpactSeverity.MEDIUM to getIcon("/images/impact/medium.svg"), - ImpactSeverity.LOW to getIcon("/images/impact/low.svg") + ImpactSeverity.LOW to getIcon("/images/impact/low.svg"), + ImpactSeverity.INFO to getIcon("/images/impact/info.svg") ) private val TYPE_ICONS = mapOf( @@ -110,15 +112,27 @@ object SonarLintIcons { ) val backgroundColorsByImpact = mapOf( - ImpactSeverity.HIGH to JBColor(Color(180, 35, 24, 20), Color(180, 35, 24, 60)), - ImpactSeverity.MEDIUM to JBColor(Color(174, 122, 41, 20), Color(174, 122, 41, 60)), - ImpactSeverity.LOW to JBColor(Color(49, 108, 146, 20), Color(49, 108, 146, 60)) + ImpactSeverity.BLOCKER to JBColor(Color(254, 228, 226), Color(128, 27, 20, 20)), + ImpactSeverity.HIGH to JBColor(Color(254, 243, 242), Color(253, 162, 155, 20)), + ImpactSeverity.MEDIUM to JBColor(Color(255, 240, 235), Color(254, 150, 75, 20)), + ImpactSeverity.LOW to JBColor(Color(252, 245, 228), Color(250, 220, 121, 20)), + ImpactSeverity.INFO to JBColor(Color(245, 251, 255), Color(143, 202, 234, 20)) ) val fontColorsByImpact = mapOf( - ImpactSeverity.HIGH to JBColor(Color(128, 27, 20), Color.LIGHT_GRAY), - ImpactSeverity.MEDIUM to JBColor(Color(140, 94, 30), Color.LIGHT_GRAY), - ImpactSeverity.LOW to JBColor(Color(49, 108, 146), Color.LIGHT_GRAY) + ImpactSeverity.BLOCKER to JBColor(Color(128, 27, 20), Color(249, 112, 102)), + ImpactSeverity.HIGH to JBColor(Color(180, 35, 24), Color(253, 162, 155)), + ImpactSeverity.MEDIUM to JBColor(Color(147, 55, 13), Color(254, 150, 75)), + ImpactSeverity.LOW to JBColor(Color(140, 94, 30), Color(250, 220, 121)), + ImpactSeverity.INFO to JBColor(Color(49, 107, 146), Color(143, 202, 234)) + ) + + val borderColorsByImpact = mapOf( + ImpactSeverity.BLOCKER to JBColor(Color(128, 27, 20), Color(249, 112, 102)), + ImpactSeverity.HIGH to JBColor(Color(217, 44, 32), Color(253, 162, 155)), + ImpactSeverity.MEDIUM to JBColor(Color(254, 150, 75), Color(254, 150, 75)), + ImpactSeverity.LOW to JBColor(Color(250, 220, 121), Color(250, 220, 121)), + ImpactSeverity.INFO to JBColor(Color(143, 202, 234), Color(143, 202, 234)) ) private fun getIcon(path: String): Icon { diff --git a/src/main/java/org/sonarlint/intellij/config/SonarLintColorSettingsPage.java b/src/main/java/org/sonarlint/intellij/config/SonarLintColorSettingsPage.java index dc54b2b4fc..6796ec9f10 100644 --- a/src/main/java/org/sonarlint/intellij/config/SonarLintColorSettingsPage.java +++ b/src/main/java/org/sonarlint/intellij/config/SonarLintColorSettingsPage.java @@ -25,7 +25,6 @@ import com.intellij.openapi.options.colors.AttributesDescriptor; import com.intellij.openapi.options.colors.ColorDescriptor; import com.intellij.openapi.options.colors.ColorSettingsPage; -import org.sonarlint.intellij.SonarLintIcons; import java.util.Arrays; import java.util.Comparator; import java.util.Map; @@ -33,12 +32,15 @@ import javax.annotation.Nullable; import javax.swing.Icon; import org.jetbrains.annotations.NotNull; +import org.sonarlint.intellij.SonarLintIcons; public class SonarLintColorSettingsPage implements ColorSettingsPage { private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] { + new AttributesDescriptor("Blocker issue", SonarLintTextAttributes.BLOCKER), new AttributesDescriptor("High impact issue", SonarLintTextAttributes.HIGH), new AttributesDescriptor("Medium impact issue", SonarLintTextAttributes.MEDIUM), new AttributesDescriptor("Low impact issue", SonarLintTextAttributes.LOW), + new AttributesDescriptor("Info issue", SonarLintTextAttributes.INFO), new AttributesDescriptor("Old issue", SonarLintTextAttributes.OLD_CODE), new AttributesDescriptor("Selected issue", SonarLintTextAttributes.SELECTED) }; @@ -49,17 +51,7 @@ private static class DescriptorComparator implements Comparator ADDITIONAL_HIGHLIGHT_DESCRIPTORS; - - static { - Arrays.sort(DESCRIPTORS, new DescriptorComparator()); - // sort alphabetically by key - ADDITIONAL_HIGHLIGHT_DESCRIPTORS = new TreeMap<>(); - - for (AttributesDescriptor desc : DESCRIPTORS) { - ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put(desc.getDisplayName(), desc.getKey()); - } - } + private static final Map ADDITIONAL_HIGHLIGHT_DESCRIPTORS = new TreeMap<>(); @Nullable @Override public Icon getIcon() { return SonarLintIcons.SONARLINT; @@ -88,14 +80,25 @@ private static class DescriptorComparator implements Comparator getAdditionalHighlightingTagToDescriptorMap() { + if (ADDITIONAL_HIGHLIGHT_DESCRIPTORS.isEmpty()) { + // sort alphabetically by key + Arrays.sort(DESCRIPTORS, new DescriptorComparator()); + for (AttributesDescriptor desc : DESCRIPTORS) { + ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put(desc.getDisplayName(), desc.getKey()); + } + } return ADDITIONAL_HIGHLIGHT_DESCRIPTORS; } - @NotNull @Override public AttributesDescriptor[] getAttributeDescriptors() { + @NotNull + @Override + public AttributesDescriptor @NotNull [] getAttributeDescriptors() { return DESCRIPTORS; } - @NotNull @Override public ColorDescriptor[] getColorDescriptors() { + @NotNull + @Override + public ColorDescriptor @NotNull [] getColorDescriptors() { return ColorDescriptor.EMPTY_ARRAY; } diff --git a/src/main/java/org/sonarlint/intellij/config/SonarLintTextAttributes.java b/src/main/java/org/sonarlint/intellij/config/SonarLintTextAttributes.java index b342014e1c..9c1d110cc0 100644 --- a/src/main/java/org/sonarlint/intellij/config/SonarLintTextAttributes.java +++ b/src/main/java/org/sonarlint/intellij/config/SonarLintTextAttributes.java @@ -26,9 +26,11 @@ import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; public class SonarLintTextAttributes { + public static final TextAttributesKey BLOCKER; public static final TextAttributesKey HIGH; public static final TextAttributesKey MEDIUM; public static final TextAttributesKey LOW; + public static final TextAttributesKey INFO; public static final TextAttributesKey OLD_CODE; public static final TextAttributesKey SELECTED; @@ -39,9 +41,11 @@ public class SonarLintTextAttributes { /* * Defaults should be consistent with SonarLintSeverity */ + BLOCKER = createTextAttributesKey("SONARLINT_BLOCKER", SonarLintSeverity.BLOCKER.defaultTextAttributes()); HIGH = createTextAttributesKey("SONARLINT_HIGH", SonarLintSeverity.HIGH.defaultTextAttributes()); MEDIUM = createTextAttributesKey("SONARLINT_MEDIUM", SonarLintSeverity.MEDIUM.defaultTextAttributes()); LOW = createTextAttributesKey("SONARLINT_LOW", SonarLintSeverity.LOW.defaultTextAttributes()); + INFO = createTextAttributesKey("SONARLINT_INFO", SonarLintSeverity.INFO.defaultTextAttributes()); OLD_CODE = createTextAttributesKey("SONARLINT_OLD_CODE", SonarLintSeverity.OLD_CODE.defaultTextAttributes()); SELECTED = createTextAttributesKey("SONARLINT_SELECTED"); DIFF_ADDITION = createTextAttributesKey("SONARLINT_DIFF_ADDITION", DiffColors.DIFF_INSERTED); diff --git a/src/main/java/org/sonarlint/intellij/editor/SonarExternalAnnotator.java b/src/main/java/org/sonarlint/intellij/editor/SonarExternalAnnotator.java index 1673aa52c9..707ad3c9f4 100644 --- a/src/main/java/org/sonarlint/intellij/editor/SonarExternalAnnotator.java +++ b/src/main/java/org/sonarlint/intellij/editor/SonarExternalAnnotator.java @@ -192,16 +192,20 @@ static TextAttributesKey getTextAttrsKey(Project project, @Nullable ImpactSeveri if (impact != null) { return switch (impact) { + case BLOCKER -> SonarLintTextAttributes.BLOCKER; case HIGH -> SonarLintTextAttributes.HIGH; case LOW -> SonarLintTextAttributes.LOW; + case INFO -> SonarLintTextAttributes.INFO; default -> SonarLintTextAttributes.MEDIUM; }; } if (severity != null) { return switch (severity) { - case CRITICAL, BLOCKER -> SonarLintTextAttributes.HIGH; - case MINOR, INFO -> SonarLintTextAttributes.LOW; + case BLOCKER -> SonarLintTextAttributes.BLOCKER; + case CRITICAL -> SonarLintTextAttributes.HIGH; + case MINOR -> SonarLintTextAttributes.LOW; + case INFO -> SonarLintTextAttributes.INFO; default -> SonarLintTextAttributes.MEDIUM; }; } diff --git a/src/main/java/org/sonarlint/intellij/ui/ruledescription/RuleHeaderPanel.kt b/src/main/java/org/sonarlint/intellij/ui/ruledescription/RuleHeaderPanel.kt index f3b7065041..f8bbf44e5b 100644 --- a/src/main/java/org/sonarlint/intellij/ui/ruledescription/RuleHeaderPanel.kt +++ b/src/main/java/org/sonarlint/intellij/ui/ruledescription/RuleHeaderPanel.kt @@ -43,6 +43,8 @@ import javax.swing.JButton import javax.swing.JPanel import javax.swing.SwingConstants import org.sonarlint.intellij.SonarLintIcons +import org.sonarlint.intellij.SonarLintIcons.backgroundColorsByImpact +import org.sonarlint.intellij.SonarLintIcons.borderColorsByImpact import org.sonarlint.intellij.actions.MarkAsResolvedAction.Companion.canBeMarkedAsResolved import org.sonarlint.intellij.actions.MarkAsResolvedAction.Companion.openMarkAsResolvedDialogAsync import org.sonarlint.intellij.actions.ReopenIssueAction.Companion.canBeReopened @@ -211,7 +213,8 @@ class RuleHeaderPanel(private val parent: Disposable) : JBPanel qualities.entries.forEach { val cleanImpact = cleanCapitalized(it.value.label) val cleanQuality = cleanCapitalized(it.key.label) - val qualityPanel = RoundedPanelWithBackgroundColor(SonarLintIcons.backgroundColorsByImpact[it.value]).apply { + val qualityPanel = + RoundedPanelWithBackgroundColor(backgroundColorsByImpact[it.value], borderColorsByImpact[it.value]).apply { toolTipText = "Issues found for this rule will have a $cleanImpact impact on the $cleanQuality of your software." } qualityPanel.add(JBLabel(cleanCapitalized(it.key.toString())).apply { diff --git a/src/main/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilder.java b/src/main/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilder.java index 8c2b769490..7ddcdbe97a 100644 --- a/src/main/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilder.java +++ b/src/main/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilder.java @@ -63,7 +63,7 @@ */ public class IssueTreeModelBuilder implements FindingTreeModelBuilder { private static final List SEVERITY_ORDER = List.of(BLOCKER, CRITICAL, MAJOR, MINOR, INFO); - private static final List IMPACT_ORDER = List.of(HIGH, MEDIUM, LOW); + private static final List IMPACT_ORDER = List.of(ImpactSeverity.BLOCKER, HIGH, MEDIUM, LOW, ImpactSeverity.INFO); private static final Comparator ISSUE_COMPARATOR = new IssueComparator(); private final FindingTreeIndex index; diff --git a/src/main/java/org/sonarlint/intellij/util/RoundedPanelWithBackgroundColor.kt b/src/main/java/org/sonarlint/intellij/util/RoundedPanelWithBackgroundColor.kt index d21f81f65b..79b7ab5c80 100644 --- a/src/main/java/org/sonarlint/intellij/util/RoundedPanelWithBackgroundColor.kt +++ b/src/main/java/org/sonarlint/intellij/util/RoundedPanelWithBackgroundColor.kt @@ -19,6 +19,7 @@ */ package org.sonarlint.intellij.util +import com.intellij.ui.IdeBorderFactory import com.intellij.ui.JBColor import com.intellij.util.ui.GraphicsUtil import com.intellij.util.ui.JBInsets @@ -29,21 +30,22 @@ import java.awt.Rectangle import java.awt.geom.RoundRectangle2D import javax.swing.JPanel -open class RoundedPanelWithBackgroundColor(private val color: JBColor? = null, private val cornerAngle: Float = 20f) : JPanel() { +open class RoundedPanelWithBackgroundColor( + backgroundColor: JBColor? = null, + borderColor: JBColor? = null, + private val cornerAngle: Float = 20f +) : JPanel() { init { isOpaque = false cursor = Cursor.getDefaultCursor() - updateColors() - } - - override fun updateUI() { super.updateUI() - updateColors() - } - - private fun updateColors() { - background = color + background = backgroundColor + borderColor?.let { + val customBorder = IdeBorderFactory.createRoundedBorder(cornerAngle.toInt(), 1) + customBorder.setColor(borderColor) + border = customBorder + } } override fun paintComponent(g: Graphics) { diff --git a/src/main/java/org/sonarlint/intellij/util/SonarLintSeverity.java b/src/main/java/org/sonarlint/intellij/util/SonarLintSeverity.java index 6394b05b94..0702c2cbca 100644 --- a/src/main/java/org/sonarlint/intellij/util/SonarLintSeverity.java +++ b/src/main/java/org/sonarlint/intellij/util/SonarLintSeverity.java @@ -32,9 +32,11 @@ import org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity; public enum SonarLintSeverity { + BLOCKER(CodeInsightColors.WARNINGS_ATTRIBUTES, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, HighlightSeverity.WARNING), HIGH(CodeInsightColors.WARNINGS_ATTRIBUTES, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, HighlightSeverity.WARNING), MEDIUM(CodeInsightColors.WARNINGS_ATTRIBUTES, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, HighlightSeverity.WARNING), LOW(CodeInsightColors.WARNINGS_ATTRIBUTES, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, HighlightSeverity.WEAK_WARNING), + INFO(CodeInsightColors.WARNINGS_ATTRIBUTES, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, HighlightSeverity.WEAK_WARNING), OLD_CODE(CodeInsightColors.WEAK_WARNING_ATTRIBUTES, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, HighlightSeverity.WEAK_WARNING); private static final Map cache = Stream.of(values()).collect(Collectors.toMap(Enum::toString, Function.identity())); @@ -66,8 +68,10 @@ public static SonarLintSeverity fromCoreSeverity(@Nullable ImpactSeverity impact return cache.get(impact.toString()); } return switch (severity) { - case BLOCKER, CRITICAL -> cache.get(ImpactSeverity.HIGH.toString()); - case MINOR, INFO -> cache.get(ImpactSeverity.LOW.toString()); + case BLOCKER -> cache.get(ImpactSeverity.BLOCKER.toString()); + case CRITICAL -> cache.get(ImpactSeverity.HIGH.toString()); + case MINOR -> cache.get(ImpactSeverity.LOW.toString()); + case INFO -> cache.get(ImpactSeverity.INFO.toString()); default -> cache.get(ImpactSeverity.MEDIUM.toString()); }; } diff --git a/src/main/resources/images/impact/blocker.svg b/src/main/resources/images/impact/blocker.svg new file mode 100644 index 0000000000..3ce6157afa --- /dev/null +++ b/src/main/resources/images/impact/blocker.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/main/resources/images/impact/high.svg b/src/main/resources/images/impact/high.svg index 592fe81874..e9c3507076 100644 --- a/src/main/resources/images/impact/high.svg +++ b/src/main/resources/images/impact/high.svg @@ -1,25 +1,3 @@ - - - + diff --git a/src/main/resources/images/impact/info.svg b/src/main/resources/images/impact/info.svg new file mode 100644 index 0000000000..74658812f4 --- /dev/null +++ b/src/main/resources/images/impact/info.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/main/resources/images/impact/low.svg b/src/main/resources/images/impact/low.svg index 8f983ea9cb..7084b9b90b 100644 --- a/src/main/resources/images/impact/low.svg +++ b/src/main/resources/images/impact/low.svg @@ -1,25 +1,3 @@ - - - + diff --git a/src/main/resources/images/impact/medium.svg b/src/main/resources/images/impact/medium.svg index 0094df0af6..78deda2bb9 100644 --- a/src/main/resources/images/impact/medium.svg +++ b/src/main/resources/images/impact/medium.svg @@ -1,25 +1,3 @@ - - - + diff --git a/src/test/java/org/sonarlint/intellij/SonarLintIconsTest.kt b/src/test/java/org/sonarlint/intellij/SonarLintIconsTest.kt index 69afc299eb..13ea4e5032 100644 --- a/src/test/java/org/sonarlint/intellij/SonarLintIconsTest.kt +++ b/src/test/java/org/sonarlint/intellij/SonarLintIconsTest.kt @@ -22,6 +22,7 @@ package org.sonarlint.intellij import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.sonarlint.intellij.SonarLintIcons.hotspotTypeWithProbability +import org.sonarlint.intellij.SonarLintIcons.impact import org.sonarlint.intellij.SonarLintIcons.severity import org.sonarlint.intellij.SonarLintIcons.toDisabled import org.sonarlint.intellij.SonarLintIcons.type @@ -37,6 +38,13 @@ class SonarLintIconsTest { } } + @Test + fun testImpacts() { + for (value in org.sonarsource.sonarlint.core.client.utils.ImpactSeverity.values()) { + assertThat(impact(value)).isNotNull + } + } + @Test fun testTypes() { for (value in RuleType.values()) { diff --git a/src/test/java/org/sonarlint/intellij/config/SonarLintColorSettingsPageTests.java b/src/test/java/org/sonarlint/intellij/config/SonarLintColorSettingsPageTests.java index 8f412c314f..45248c1c91 100644 --- a/src/test/java/org/sonarlint/intellij/config/SonarLintColorSettingsPageTests.java +++ b/src/test/java/org/sonarlint/intellij/config/SonarLintColorSettingsPageTests.java @@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; class SonarLintColorSettingsPageTests { - private final static String[] SEVERITIES = {"LOW", "MEDIUM", "HIGH", "OLD", "SELECTED"}; + private static final String[] SEVERITIES = {"LOW", "MEDIUM", "HIGH", "OLD", "SELECTED"}; private SonarLintColorSettingsPage colorSettingsPage; @BeforeEach @@ -45,15 +45,17 @@ void testGetters() { @Test void testDescriptors() { assertThat(colorSettingsPage.getAdditionalHighlightingTagToDescriptorMap()).containsValues( + SonarLintTextAttributes.BLOCKER, SonarLintTextAttributes.HIGH, SonarLintTextAttributes.MEDIUM, - SonarLintTextAttributes.LOW); + SonarLintTextAttributes.LOW, + SonarLintTextAttributes.INFO); } @Test void testAttributeDescriptors() { // one per severity + selected - assertThat(colorSettingsPage.getAttributeDescriptors()).hasSize(5); + assertThat(colorSettingsPage.getAttributeDescriptors()).hasSize(7); } @Test diff --git a/src/test/java/org/sonarlint/intellij/editor/SonarExternalAnnotatorTests.java b/src/test/java/org/sonarlint/intellij/editor/SonarExternalAnnotatorTests.java index abba481dea..6f549e1bb5 100644 --- a/src/test/java/org/sonarlint/intellij/editor/SonarExternalAnnotatorTests.java +++ b/src/test/java/org/sonarlint/intellij/editor/SonarExternalAnnotatorTests.java @@ -55,9 +55,9 @@ void testSeverityMapping() { assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, null, false)).isEqualTo(SonarLintTextAttributes.MEDIUM); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.MAJOR, false)).isEqualTo(SonarLintTextAttributes.MEDIUM); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.MINOR, false)).isEqualTo(SonarLintTextAttributes.LOW); - assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.BLOCKER, false)).isEqualTo(SonarLintTextAttributes.HIGH); + assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.BLOCKER, false)).isEqualTo(SonarLintTextAttributes.BLOCKER); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.CRITICAL, false)).isEqualTo(SonarLintTextAttributes.HIGH); - assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.INFO, false)).isEqualTo(SonarLintTextAttributes.LOW); + assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.INFO, false)).isEqualTo(SonarLintTextAttributes.INFO); Settings.getGlobalSettings().setFocusOnNewCode(true); connectProjectTo(ServerConnection.newBuilder().setName("connection").build(), "projectKey"); @@ -70,9 +70,9 @@ void testSeverityMapping() { assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.MAJOR, true)).isEqualTo(SonarLintTextAttributes.MEDIUM); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.MINOR, true)).isEqualTo(SonarLintTextAttributes.LOW); - assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.BLOCKER, true)).isEqualTo(SonarLintTextAttributes.HIGH); + assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.BLOCKER, true)).isEqualTo(SonarLintTextAttributes.BLOCKER); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.CRITICAL, true)).isEqualTo(SonarLintTextAttributes.HIGH); - assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.INFO, true)).isEqualTo(SonarLintTextAttributes.LOW); + assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), null, IssueSeverity.INFO, true)).isEqualTo(SonarLintTextAttributes.INFO); } @Test @@ -83,6 +83,8 @@ void testImpactMapping() { assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.HIGH, IssueSeverity.BLOCKER, false)).isEqualTo(SonarLintTextAttributes.HIGH); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.HIGH, IssueSeverity.CRITICAL, false)).isEqualTo(SonarLintTextAttributes.HIGH); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.LOW, IssueSeverity.INFO, false)).isEqualTo(SonarLintTextAttributes.LOW); + assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.BLOCKER, IssueSeverity.MAJOR, false)).isEqualTo(SonarLintTextAttributes.BLOCKER); + assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.INFO, IssueSeverity.MAJOR, false)).isEqualTo(SonarLintTextAttributes.INFO); Settings.getGlobalSettings().setFocusOnNewCode(true); connectProjectTo(ServerConnection.newBuilder().setName("connection").build(), "projectKey"); @@ -98,5 +100,7 @@ void testImpactMapping() { assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.HIGH, IssueSeverity.BLOCKER, true)).isEqualTo(SonarLintTextAttributes.HIGH); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.HIGH, IssueSeverity.CRITICAL, true)).isEqualTo(SonarLintTextAttributes.HIGH); assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.LOW, IssueSeverity.INFO, true)).isEqualTo(SonarLintTextAttributes.LOW); + assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.BLOCKER, IssueSeverity.INFO, true)).isEqualTo(SonarLintTextAttributes.BLOCKER); + assertThat(SonarExternalAnnotator.getTextAttrsKey(getProject(), ImpactSeverity.INFO, IssueSeverity.INFO, true)).isEqualTo(SonarLintTextAttributes.INFO); } } diff --git a/src/test/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilderTests.java b/src/test/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilderTests.java index 07b3fd9bf4..ae19b73857 100644 --- a/src/test/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilderTests.java +++ b/src/test/java/org/sonarlint/intellij/ui/tree/IssueTreeModelBuilderTests.java @@ -45,7 +45,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.sonarsource.sonarlint.core.rpc.protocol.common.ImpactSeverity.BLOCKER; import static org.sonarsource.sonarlint.core.rpc.protocol.common.ImpactSeverity.HIGH; +import static org.sonarsource.sonarlint.core.rpc.protocol.common.ImpactSeverity.INFO; import static org.sonarsource.sonarlint.core.rpc.protocol.common.ImpactSeverity.LOW; import static org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity.MAJOR; import static org.sonarsource.sonarlint.core.rpc.protocol.common.IssueSeverity.MINOR; @@ -117,12 +119,14 @@ void testIssueComparatorNewCct() { list.add(mockIssuePointer(100, "rule3", List.of(new ImpactDto(MAINTAINABILITY, LOW)), Instant.now().minusSeconds(20))); list.add(mockIssuePointer(50, "rule4", List.of(new ImpactDto(MAINTAINABILITY, LOW)), null)); list.add(mockIssuePointer(100, "rule5", List.of(new ImpactDto(MAINTAINABILITY, HIGH)), null)); + list.add(mockIssuePointer(100, "rule6", List.of(new ImpactDto(MAINTAINABILITY, INFO)), null)); + list.add(mockIssuePointer(100, "rule7", List.of(new ImpactDto(MAINTAINABILITY, BLOCKER)), null)); var sorted = new ArrayList<>(list); sorted.sort(new IssueTreeModelBuilder.IssueComparator()); // criteria: creation date (most recent, nulls last), getImpact (highest first), rule alphabetically - assertThat(sorted).containsExactly(list.get(2), list.get(1), list.get(0), list.get(4), list.get(3)); + assertThat(sorted).containsExactly(list.get(2), list.get(1), list.get(6), list.get(0), list.get(4), list.get(3), list.get(5)); } private void addFile(Map> data, String fileName, int numIssues) { From c91027842d3d6454e5ba3fa44946024f68fc7dd7 Mon Sep 17 00:00:00 2001 From: Nicolas Quinquenel Date: Tue, 24 Sep 2024 14:17:24 +0200 Subject: [PATCH 2/2] Update licenses --- src/main/resources/images/impact/blocker.svg | 21 ++++++++++++++++++++ src/main/resources/images/impact/high.svg | 21 ++++++++++++++++++++ src/main/resources/images/impact/info.svg | 21 ++++++++++++++++++++ src/main/resources/images/impact/low.svg | 21 ++++++++++++++++++++ src/main/resources/images/impact/medium.svg | 21 ++++++++++++++++++++ 5 files changed, 105 insertions(+) diff --git a/src/main/resources/images/impact/blocker.svg b/src/main/resources/images/impact/blocker.svg index 3ce6157afa..f84947fcbb 100644 --- a/src/main/resources/images/impact/blocker.svg +++ b/src/main/resources/images/impact/blocker.svg @@ -1,3 +1,24 @@ + diff --git a/src/main/resources/images/impact/high.svg b/src/main/resources/images/impact/high.svg index e9c3507076..f62c7da1d5 100644 --- a/src/main/resources/images/impact/high.svg +++ b/src/main/resources/images/impact/high.svg @@ -1,3 +1,24 @@ + diff --git a/src/main/resources/images/impact/info.svg b/src/main/resources/images/impact/info.svg index 74658812f4..fdd2f6789e 100644 --- a/src/main/resources/images/impact/info.svg +++ b/src/main/resources/images/impact/info.svg @@ -1,3 +1,24 @@ + diff --git a/src/main/resources/images/impact/low.svg b/src/main/resources/images/impact/low.svg index 7084b9b90b..f3851caf8e 100644 --- a/src/main/resources/images/impact/low.svg +++ b/src/main/resources/images/impact/low.svg @@ -1,3 +1,24 @@ + diff --git a/src/main/resources/images/impact/medium.svg b/src/main/resources/images/impact/medium.svg index 78deda2bb9..cdc0692e5a 100644 --- a/src/main/resources/images/impact/medium.svg +++ b/src/main/resources/images/impact/medium.svg @@ -1,3 +1,24 @@ +