Skip to content

Commit

Permalink
fix: issue title in description panel (LS source)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Feb 12, 2024
1 parent 8c51d84 commit 25bd6be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class SnykTreeCellRenderer : ColoredTreeCellRenderer() {
val issue = value.userObject as ScanIssue
nodeIcon = SnykIcons.getSeverityIcon(issue.getSeverityAsEnum())
val range = issue.range
text = "line ${range.start.line}: ${
text = "line ${range.start.line + 1}: ${
if (issue.additionalData.isSecurityType) {
issue.title.split(":")[0]
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ import javax.swing.ScrollPaneConstants
import javax.swing.event.HyperlinkEvent
import kotlin.math.max

class SuggestionDescriptionPanelFromLS (
class SuggestionDescriptionPanelFromLS(
private val snykCodeFile: SnykCodeFile,
private val issue: ScanIssue
) : IssueDescriptionPanelBase(title = issue.title, severity = issue.getSeverityAsEnum()) {
) : IssueDescriptionPanelBase(title = getIssueTitle(issue), severity = issue.getSeverityAsEnum()) {
val project = snykCodeFile.project

init {
createUI()
}

override fun secondRowTitlePanel(): DescriptionHeaderPanel = descriptionHeaderPanel(
issueNaming = if (issue.additionalData.isSecurityType) "Vulnerability" else "Code Issue",
issueNaming = if (issue.additionalData.isSecurityType) "Vulnerability" else "Quality Issue",
cwes = issue.additionalData.cwe ?: emptyList()
)

Expand Down Expand Up @@ -239,8 +239,11 @@ class SuggestionDescriptionPanelFromLS (
)

val labelText =
if (examplesCount == 0) "No example fixes available."
else "This issue was fixed by ${issue.additionalData.repoDatasetSize} projects. Here are $examplesCount example fixes."
if (examplesCount == 0) {
"No example fixes available."
} else {
"This issue was fixed by ${issue.additionalData.repoDatasetSize} projects. Here are $examplesCount example fixes."

Check warning

Code scanning / detekt

Reports lines with exceeded length Warning

Exceeded max line length (120)

Check warning

Code scanning / detekt

Line detected, which is longer than the defined maximum line length in the code style. Warning

Line detected, which is longer than the defined maximum line length in the code style.
}
panel.add(
defaultFontLabel(labelText),
baseGridConstraintsAnchorWest(1)
Expand All @@ -249,7 +252,7 @@ class SuggestionDescriptionPanelFromLS (
if (examplesCount == 0) return panel

val tabbedPane = JBTabbedPane()
//tabbedPane.tabLayoutPolicy = JTabbedPane.SCROLL_TAB_LAYOUT // tabs in one row
// tabbedPane.tabLayoutPolicy = JTabbedPane.SCROLL_TAB_LAYOUT // tabs in one row
tabbedPane.tabComponentInsets = JBInsets.create(0, 0) // no inner borders for tab content
tabbedPane.font = io.snyk.plugin.ui.getFont(-1, 14, tabbedPane.font)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.

Expand Down Expand Up @@ -283,7 +286,6 @@ class SuggestionDescriptionPanelFromLS (
}

private fun diffPanel(exampleCommitFix: snyk.common.lsp.ExampleCommitFix, rowCount: Int): JComponent {

Check warning

Code scanning / detekt

One method should have one responsibility. Long methods tend to handle many things at once. Prefer smaller methods to make them easier to understand. Warning

The function diffPanel is too long (62). The maximum length is 60.

fun shift(colorComponent: Int, d: Double): Int {
val n = (colorComponent * d).toInt()
return n.coerceIn(0, 255)

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
Expand Down Expand Up @@ -422,3 +424,10 @@ class SuggestionDescriptionPanelFromLS (
.toSet()
}
}

private fun getIssueTitle(issue: ScanIssue) =
if (issue.additionalData.isSecurityType) {
issue.title.split(":").firstOrNull() ?: "Unknown issue"
} else {
issue.additionalData.message.split(".").firstOrNull() ?: "Unknown issue"
}

0 comments on commit 25bd6be

Please sign in to comment.