Skip to content

Commit

Permalink
Use toUri to generate absolute ArtifactLocation paths
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Oct 8, 2023
1 parent c6fb152 commit d64d520
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private fun Location.toLocation(code: String?): io.github.detekt.sarif4k.Locatio
uriBaseID = SRCROOT
)
} else {
ArtifactLocation(uri = "file:///${filePath.absolutePath.invariantSeparatorsPathString}")
ArtifactLocation(uri = filePath.absolutePath.toUri().toString())
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.gitlab.arturbosch.detekt.api.UnstableApi
import io.gitlab.arturbosch.detekt.api.getOrNull
import io.gitlab.arturbosch.detekt.api.internal.whichDetekt
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.absolute
import kotlin.io.path.invariantSeparatorsPathString

Expand Down Expand Up @@ -62,7 +63,7 @@ class SarifOutputReport : OutputReport() {
)
),
originalURIBaseIDS = basePath?.let {
mapOf(SRCROOT to ArtifactLocation(uri = "file:///$basePath"))
mapOf(SRCROOT to ArtifactLocation(uri = Path(basePath!!).toUri().toString()))

Check failure

Code scanning / detekt

Unsafe calls on nullable types detected. These calls will throw a NullPointerException in case the nullable value is null. Error

Calling !! on a nullable type will throw a NullPointerException at runtime in case the value is null. It should be avoided.
},
results = toResults(detektion)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class SarifOutputReportSpec {
.apply { init(EmptySetupContext()) }
.render(result)

assertThat(report).isEqualToIgnoringWhitespace(readResourceContent("vanilla.sarif.json"))
val expectedReport = readResourceContent("vanilla.sarif.json")
.replace("<PREFIX>", Path(System.getProperty("user.dir")).toUri().toString())

assertThat(report).isEqualToIgnoringWhitespace(expectedReport)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"originalUriBaseIds": {
"%SRCROOT%": {
"uri": "file:///Users/tester/detekt/"
"uri": "file:///Users/tester/detekt"
}
},
"results": [
Expand Down
6 changes: 3 additions & 3 deletions detekt-report-sarif/src/test/resources/vanilla.sarif.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///TestFile.kt"
"uri": "<PREFIX>TestFile.kt"
},
"region": {
"startColumn": 1,
Expand All @@ -30,7 +30,7 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///TestFile.kt"
"uri": "<PREFIX>TestFile.kt"
},
"region": {
"startColumn": 1,
Expand All @@ -50,7 +50,7 @@
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///TestFile.kt"
"uri": "<PREFIX>TestFile.kt"
},
"region": {
"startColumn": 1,
Expand Down

0 comments on commit d64d520

Please sign in to comment.