Skip to content

Commit 78bd0c6

Browse files
fix: ignore counts in info tree node [IDE-413] (#551) (#555)
* fix: ignore counts in info tree node * refactor: improve readibility of code
1 parent 17bc61c commit 78bd0c6

File tree

4 files changed

+92
-44
lines changed

4 files changed

+92
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [2.8.7]
44
### Fixes
55
- fix issue counts when there are ignores and add some warnings about the Issue View Options
6+
- fix AI fix counts when there are ignores
67

78
## [2.8.6]
89
### Fixed

src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykScanListenerLS.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ class SnykToolWindowSnykScanListenerLS(
167167
rootNodePostFix = buildSeveritiesPostfixForFileNode(snykResults)
168168

169169
if (filterTree) {
170-
addInfoTreeNodes(rootNode, snykResults.values.flatten().distinct(), fixableIssuesCount)
170+
addInfoTreeNodes(
171+
rootNode = rootNode,
172+
issues = snykResults.values.flatten().distinct(),
173+
securityIssuesCount = securityIssuesCount,
174+
fixableIssuesCount = fixableIssuesCount,
175+
)
171176

172177
var includeIgnoredIssues = true
173178
var includeOpenedIssues = true

src/main/kotlin/snyk/common/lsp/Types.kt

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import io.snyk.plugin.Severity
1010
import io.snyk.plugin.getDocument
1111
import io.snyk.plugin.pluginSettings
1212
import io.snyk.plugin.toVirtualFile
13+
import io.snyk.plugin.ui.PackageManagerIconProvider.Companion.getIcon
1314
import org.eclipse.lsp4j.Range
1415
import snyk.analytics.IssueInTreeIsClicked.IssueType
1516
import snyk.common.ProductType
1617
import java.util.Date
17-
import io.snyk.plugin.ui.PackageManagerIconProvider.Companion.getIcon
18-
import javax.swing.Icon
1918
import java.util.Locale
19+
import javax.swing.Icon
2020

2121
// Define the SnykScanParams data class
2222
data class SnykScanParams(
2323
val status: String, // Status can be either Initial, InProgress or Success
2424
val product: String, // Product under scan (Snyk Code, Snyk Open Source, etc...)
2525
val folderPath: String, // FolderPath is the root-folder of the current scan
26-
val issues: List<ScanIssue> // Issues contain the scan results in the common issues model
26+
val issues: List<ScanIssue>, // Issues contain the scan results in the common issues model
2727
)
2828

2929
// Define the ScanIssue data class
@@ -51,31 +51,39 @@ data class ScanIssue(
5151
return if (field == null) {
5252
field = filePath.toVirtualFile()
5353
field
54-
} else field
54+
} else {
55+
field
56+
}
5557
}
5658

5759
private var document: Document?
5860
get() {
5961
return if (field == null) {
6062
field = virtualFile?.getDocument()
6163
field
62-
} else field
64+
} else {
65+
field
66+
}
6367
}
6468

6569
private var startOffset: Int?
6670
get() {
6771
return if (field == null) {
6872
field = document?.getLineStartOffset(range.start.line)?.plus(range.start.character)
6973
field
70-
} else field
74+
} else {
75+
field
76+
}
7177
}
7278

7379
private var endOffset: Int?
7480
get() {
7581
return if (field == null) {
7682
field = document?.getLineStartOffset(range.end.line)?.plus(range.end.character)
7783
field
78-
} else field
84+
} else {
85+
field
86+
}
7987
}
8088

8189
init {
@@ -94,6 +102,7 @@ data class ScanIssue(
94102
IssueType.OPEN_SOURCE_VULNERABILITY
95103
}
96104
}
105+
97106
ProductType.IAC -> IssueType.INFRASTRUCTURE_AS_CODE_ISSUE
98107
ProductType.CONTAINER -> IssueType.CONTAINER_VULNERABILITY
99108
ProductType.CODE_SECURITY -> IssueType.CODE_SECURITY_VULNERABILITY
@@ -108,9 +117,11 @@ data class ScanIssue(
108117
ProductType.CODE_QUALITY -> {
109118
this.additionalData.message.split('.').firstOrNull() ?: "Unknown issue"
110119
}
120+
111121
ProductType.CODE_SECURITY -> {
112122
this.title.split(":").firstOrNull() ?: "Unknown issue"
113123
}
124+
114125
else -> TODO()
115126
}
116127
}
@@ -120,28 +131,32 @@ data class ScanIssue(
120131
ProductType.OSS -> {
121132
"${this.additionalData.packageName}@${this.additionalData.version}: ${this.title()}"
122133
}
134+
123135
ProductType.CODE_QUALITY, ProductType.CODE_SECURITY -> {
124136
return "${this.title()} [${this.range.start.line + 1},${this.range.start.character}]"
125137
}
138+
126139
else -> TODO()
127140
}
128141
}
129142

130143
fun priority(): Int {
131144
return when (this.additionalData.getProductType()) {
132145
ProductType.OSS -> {
133-
return when(this.getSeverityAsEnum()) {
146+
return when (this.getSeverityAsEnum()) {
134147
Severity.CRITICAL -> 4
135148
Severity.HIGH -> 3
136149
Severity.MEDIUM -> 2
137150
Severity.LOW -> 1
138151
Severity.UNKNOWN -> 0
139152
}
140153
}
154+
141155
ProductType.CODE_SECURITY, ProductType.CODE_QUALITY -> this.additionalData.priorityScore
142156
else -> TODO()
143157
}
144158
}
159+
145160
fun issueNaming(): String {
146161
return when (this.additionalData.getProductType()) {
147162
ProductType.OSS -> {
@@ -151,30 +166,33 @@ data class ScanIssue(
151166
"Vulnerability"
152167
}
153168
}
169+
154170
ProductType.CODE_SECURITY -> "Vulnerability"
155171
ProductType.CODE_QUALITY -> "Quality Issue"
156172
else -> TODO()
157173
}
158174
}
159175

160-
161176
fun cwes(): List<String> {
162177
return when (this.additionalData.getProductType()) {
163178
ProductType.OSS -> {
164179
this.additionalData.identifiers?.CWE ?: emptyList()
165180
}
181+
166182
ProductType.CODE_SECURITY, ProductType.CODE_QUALITY -> {
167183
this.additionalData.cwe ?: emptyList()
168184
}
185+
169186
else -> TODO()
170187
}
171188
}
172189

173190
fun cves(): List<String> {
174191
return when (this.additionalData.getProductType()) {
175192
ProductType.OSS -> {
176-
this.additionalData.identifiers?.CVE ?: emptyList()
193+
this.additionalData.identifiers?.CVE ?: emptyList()
177194
}
195+
178196
ProductType.CODE_SECURITY, ProductType.CODE_QUALITY -> emptyList()
179197
else -> TODO()
180198
}
@@ -204,7 +222,7 @@ data class ScanIssue(
204222
}
205223
}
206224

207-
fun ruleId(): String? {
225+
fun ruleId(): String {
208226
return when (this.additionalData.getProductType()) {
209227
ProductType.OSS, ProductType.CODE_SECURITY, ProductType.CODE_QUALITY -> this.additionalData.ruleId
210228
else -> TODO()
@@ -230,11 +248,13 @@ data class ScanIssue(
230248
fun annotationMessage(): String {
231249
return when (this.additionalData.getProductType()) {
232250
ProductType.OSS -> this.title
233-
ProductType.CODE_SECURITY, ProductType.CODE_QUALITY -> this.title.ifBlank {
234-
this.additionalData.message.let {
235-
if (it.length < 70) it else "${it.take(70)}..."
251+
ProductType.CODE_SECURITY, ProductType.CODE_QUALITY ->
252+
this.title.ifBlank {
253+
this.additionalData.message.let {
254+
if (it.length < 70) it else "${it.take(70)}..."
255+
}
236256
}
237-
}
257+
238258
else -> TODO()
239259
}
240260
}
@@ -251,11 +271,9 @@ data class ScanIssue(
251271
return when (this.additionalData.getProductType()) {
252272
ProductType.OSS -> false
253273
ProductType.CODE_SECURITY, ProductType.CODE_QUALITY -> {
254-
if (this.isIgnored()) {
255-
return false
256-
}
257274
return this.additionalData.hasAIFix
258275
}
276+
259277
else -> TODO()
260278
}
261279
}
@@ -274,14 +292,17 @@ data class ScanIssue(
274292
}
275293
}
276294

277-
fun isVisible(includeOpenedIssues: Boolean, includeIgnoredIssues: Boolean): Boolean {
278-
if (includeIgnoredIssues && includeOpenedIssues){
279-
return true
295+
fun isVisible(
296+
includeOpenedIssues: Boolean,
297+
includeIgnoredIssues: Boolean,
298+
): Boolean {
299+
if (includeIgnoredIssues && includeOpenedIssues) {
300+
return true
280301
}
281302
if (includeIgnoredIssues) {
282303
return this.isIgnored == true
283304
}
284-
if (includeOpenedIssues){
305+
if (includeOpenedIssues) {
285306
return this.isIgnored != true
286307
}
287308
return false
@@ -297,20 +318,20 @@ data class ScanIssue(
297318

298319
data class ExampleCommitFix(
299320
@SerializedName("commitURL") val commitURL: String,
300-
@SerializedName("lines") val lines: List<CommitChangeLine>
321+
@SerializedName("lines") val lines: List<CommitChangeLine>,
301322
)
302323

303324
data class CommitChangeLine(
304325
@SerializedName("line") val line: String,
305326
@SerializedName("lineNumber") val lineNumber: Int,
306-
@SerializedName("lineChange") val lineChange: String
327+
@SerializedName("lineChange") val lineChange: String,
307328
)
308329

309330
typealias Point = Array<Int>?
310331

311332
data class Marker(
312333
@SerializedName("msg") val msg: Point,
313-
@SerializedName("pos") val pos: List<MarkerPosition>
334+
@SerializedName("pos") val pos: List<MarkerPosition>,
314335
) {
315336
override fun equals(other: Any?): Boolean {
316337
if (this === other) return true
@@ -334,7 +355,7 @@ data class Marker(
334355
data class MarkerPosition(
335356
@SerializedName("cols") val cols: Point,
336357
@SerializedName("rows") val rows: Point,
337-
@SerializedName("file") val file: String
358+
@SerializedName("file") val file: String,
338359
) {
339360
override fun equals(other: Any?): Boolean {
340361
if (this === other) return true
@@ -345,11 +366,15 @@ data class MarkerPosition(
345366
if (cols != null) {
346367
if (other.cols == null) return false
347368
if (!cols.contentEquals(other.cols)) return false
348-
} else if (other.cols != null) return false
369+
} else if (other.cols != null) {
370+
return false
371+
}
349372
if (rows != null) {
350373
if (other.rows == null) return false
351374
if (!rows.contentEquals(other.rows)) return false
352-
} else if (other.rows != null) return false
375+
} else if (other.rows != null) {
376+
return false
377+
}
353378
if (file != other.file) return false
354379

355380
return true
@@ -367,7 +392,7 @@ data class DataFlow(
367392
@SerializedName("position") val position: Int,
368393
@SerializedName("filePath") val filePath: String,
369394
@SerializedName("flowRange") val flowRange: Range,
370-
@SerializedName("content") val content: String
395+
@SerializedName("content") val content: String,
371396
)
372397

373398
data class IssueData(
@@ -386,7 +411,6 @@ data class IssueData(
386411
@SerializedName("priorityScore") val priorityScore: Int,
387412
@SerializedName("hasAIFix") val hasAIFix: Boolean,
388413
@SerializedName("dataFlow") val dataFlow: List<DataFlow>,
389-
390414
// OSS
391415
@SerializedName("license") val license: String?,
392416
@SerializedName("identifiers") val identifiers: OssIdentifiers?,
@@ -408,12 +432,10 @@ data class IssueData(
408432
@SerializedName("displayTargetFile") val displayTargetFile: String?,
409433
@SerializedName("matchingIssues") val matchingIssues: List<IssueData>,
410434
@SerializedName("lesson") val lesson: String?,
411-
412435
// Code and OSS
413436
@SerializedName("ruleId") val ruleId: String,
414437
@SerializedName("details") val details: String?,
415438
) {
416-
417439
fun getProductType(): ProductType {
418440
// TODO: how else to differentiate?
419441
if (this.packageManager != null) {
@@ -474,11 +496,15 @@ data class IssueData(
474496
if (cols != null) {
475497
if (other.cols == null) return false
476498
if (!cols.contentEquals(other.cols)) return false
477-
} else if (other.cols != null) return false
499+
} else if (other.cols != null) {
500+
return false
501+
}
478502
if (rows != null) {
479503
if (other.rows == null) return false
480504
if (!rows.contentEquals(other.rows)) return false
481-
} else if (other.rows != null) return false
505+
} else if (other.rows != null) {
506+
return false
507+
}
482508
if (isSecurityType != other.isSecurityType) return false
483509
if (priorityScore != other.priorityScore) return false
484510
if (hasAIFix != other.hasAIFix) return false
@@ -509,7 +535,7 @@ data class IssueData(
509535
result = 31 * result + (isUpgradable?.hashCode() ?: 0)
510536
result = 31 * result + displayTargetFile.hashCode()
511537
result = 31 * result + (details?.hashCode() ?: 0)
512-
result = 31 * result +( matchingIssues?.hashCode() ?: 0)
538+
result = 31 * result + (matchingIssues?.hashCode() ?: 0)
513539
result = 31 * result + (lesson?.hashCode() ?: 0)
514540
return result
515541
}
@@ -534,9 +560,13 @@ data class IssueData(
534560
}
535561
}
536562

537-
data class HasAuthenticatedParam(@SerializedName("token") val token: String?)
563+
data class HasAuthenticatedParam(
564+
@SerializedName("token") val token: String?,
565+
)
538566

539-
data class SnykTrustedFoldersParams(@SerializedName("trustedFolders") val trustedFolders: List<String>)
567+
data class SnykTrustedFoldersParams(
568+
@SerializedName("trustedFolders") val trustedFolders: List<String>,
569+
)
540570

541571
data class IgnoreDetails(
542572
@SerializedName("category") val category: String,
@@ -549,8 +579,7 @@ data class IgnoreDetails(
549579
data class OssIdentifiers(
550580
@SerializedName("CWE") val CWE: List<String>?,
551581
@SerializedName("CVE") val CVE: List<String>?,
552-
){
553-
582+
) {
554583
override fun equals(other: Any?): Boolean {
555584
if (this === other) return true
556585
if (javaClass != other?.javaClass) return false
@@ -569,4 +598,3 @@ data class OssIdentifiers(
569598
return result
570599
}
571600
}
572-

0 commit comments

Comments
 (0)