Skip to content

Commit

Permalink
feat: filter issues by ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed Mar 18, 2024
1 parent 2b1c231 commit aaae141
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ class SnykLanguageClient : LanguageClient {
var includeIgnoredIssues = pluginSettings().ignoredIssuesEnabled
var includeOpenedIssues = pluginSettings().openIssuesEnabled

// TODO: check feature flag before filtering based on ignores
val map = snykScan.issues
// TODO: filter issues based on ignores
// TODO: check feature flag before filtering based on ignores
.filter { it.isVisible(includeOpenedIssues, includeIgnoredIssues) }
.groupBy { it.filePath }
.mapNotNull { (file, issues) -> SnykCodeFile(project, file.toVirtualFile()) to issues.sorted() }
.filter { it.second.isNotEmpty() }
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/snyk/common/lsp/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data class SnykScanParams(
val issues: List<ScanIssue> // Issues contain the scan results in the common issues model
)


// Define the ScanIssue data class
data class ScanIssue(
val id: String, // Unique key identifying an issue in the whole result set. Not the same as the Snyk issue ID.
Expand Down Expand Up @@ -89,6 +90,19 @@ data class ScanIssue(
}
}

fun isVisible(includeOpenedIssues: Boolean, includeIgnoredIssues: Boolean): Boolean {
if (includeIgnoredIssues && includeOpenedIssues){
return true
}
if (includeIgnoredIssues) {
return this.isIgnored == true
}
if (includeOpenedIssues){
return this.isIgnored != true
}
return false
}

override fun compareTo(other: ScanIssue): Int {
this.filePath.compareTo(other.filePath).let { if (it != 0) it else 0 }
this.range.start.line.compareTo(other.range.start.line).let { if (it != 0) it else 0 }
Expand Down

0 comments on commit aaae141

Please sign in to comment.