Skip to content
This repository was archived by the owner on Oct 27, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions src/main/kotlin/com/bridgecrew/ui/CodeDiffPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ class CodeDiffPanel(val result: BaseCheckovResult, private val isErrorBubble: Bo
.inlineDiffByWord(true)
.build()

var oldCode = buildVulnerableLines()
var oldCode = buildCodeBlock()
var newCode = buildFixLines()
if(!isErrorBubble){
newCode=buildFix()
oldCode=buildCodeBlock()
}
val rows = generator.generateDiffRows(oldCode, newCode)
val firstDiffRow = rows.find { it.tag != DiffRow.Tag.EQUAL &&
Expand Down Expand Up @@ -75,23 +74,13 @@ class CodeDiffPanel(val result: BaseCheckovResult, private val isErrorBubble: Bo
return textArea
}

private fun buildVulnerableLines(): ArrayList<String> {
var vulnerableLines = arrayListOf<String>()
if (isErrorBubble) {
result.codeBlock.forEach { block ->
val rowNumber = (block[0] as Double).toInt().toString()
val code = block[1]
vulnerableLines += "$rowNumber\t$code".replace("\n", "")
}
}
return vulnerableLines
}

private fun buildCodeBlock(): ArrayList<String> {
var codeBlock = arrayListOf<String>()
result.codeBlock.forEach { block ->
var currentLine = (block[0] as Double).toInt()
val code = block[1]
codeBlock += "$code".replace("\n", "")
codeBlock += "$currentLine\t$code".replace("\n", "")
currentLine++
}

return codeBlock
Expand All @@ -102,7 +91,7 @@ class CodeDiffPanel(val result: BaseCheckovResult, private val isErrorBubble: Bo
if (result.codeBlock.isNotEmpty()) {
var currentLine = (result.codeBlock[0][0] as Double).toInt()
result.fixDefinition?.split("\n")?.forEach { codeRow ->
fixWithRowNumber += "$codeRow"
fixWithRowNumber += "$currentLine\t$codeRow"
currentLine++
}
}
Expand Down