Skip to content

Commit 0ddf362

Browse files
authored
fix: allow Inline Vulnerability Severity Alerts level change in Dockerfile (#235)
1 parent 3cd5213 commit 0ddf362

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

src/main/java/org/jboss/tools/intellij/image/DockerfileAnnotator.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.github.packageurl.MalformedPackageURLException;
1515
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
1616
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
17+
import com.intellij.codeHighlighting.HighlightDisplayLevel;
1718
import com.intellij.codeInspection.InspectionProfileEntry;
1819
import com.intellij.lang.annotation.AnnotationHolder;
1920
import com.intellij.lang.annotation.ExternalAnnotator;
@@ -234,6 +235,25 @@ static String getRecommendation(AnalysisReport report, ImageRef imageRef) {
234235
.orElse(null);
235236
}
236237

238+
@NotNull
239+
private static HighlightSeverity getHighlightSeverity(AnalysisReport report, String recommendation, boolean hasIssue, @NotNull PsiElement context) {
240+
// Get the configured severity from the inspection settings
241+
final InspectionProfileEntry inspection = getInspection(context);
242+
if (inspection != null) {
243+
final var profile = InspectionProjectProfileManager.getInstance(context.getProject()).getCurrentProfile();
244+
final HighlightDisplayKey key = HighlightDisplayKey.find(DockerfileInspection.SHORT_NAME);
245+
if (key != null) {
246+
HighlightDisplayLevel level = profile.getErrorLevel(key, context);
247+
return level.getSeverity();
248+
}
249+
}
250+
251+
// Fallback to original logic if inspection settings can't be determined
252+
return hasIssue || recommendation == null ?
253+
HighlightSeverity.ERROR :
254+
HighlightSeverity.WEAK_WARNING;
255+
}
256+
237257
@Override
238258
public @Nullable Info collectInformation(@NotNull PsiFile file) {
239259
// Only process our custom Dockerfile type
@@ -318,11 +338,8 @@ public void apply(@NotNull PsiFile file, Map<BaseImage, Result> annotationResult
318338
var message = generateMessage(key.getImageName(), report, recommendation);
319339
var tooltip = generateTooltip(key.getImageName(), report, recommendation);
320340

321-
var severity = hasIssue || recommendation == null ?
322-
HighlightSeverity.ERROR :
323-
HighlightSeverity.WEAK_WARNING;
324-
325341
elements.forEach(e -> {
342+
var severity = getHighlightSeverity(report, recommendation, hasIssue, e);
326343
if (e != null) {
327344
var builder = holder
328345
.newAnnotation(severity, message)

0 commit comments

Comments
 (0)