Skip to content

Commit

Permalink
self review
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls committed Feb 27, 2024
1 parent 83f1ba4 commit 9c5fd57
Showing 1 changed file with 28 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import okio.FileSystem
import okio.Path

import kotlin.random.Random
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json

private typealias WarningMap = Map<String, List<Warning>>
Expand Down Expand Up @@ -267,43 +266,37 @@ class WarnPlugin(
originalPaths: List<Path>,
copyPaths: List<Path>,
workingDirectory: Path,
): WarningMap = when {
warnPluginConfig.expectedWarningsFileName != null -> {
val expectedWarningsFileName: String = warnPluginConfig.expectedWarningsFileName
when (warnPluginConfig.expectedWarningsFormat) {
ExpectedWarningsFormat.PLAIN -> {
val anchorTestFilePath = originalPaths.first()
val plainFile = fs.findFileInAncestorDir(anchorTestFilePath, expectedWarningsFileName) ?: throw PluginException(
"Could not find PLAIN file with expected warnings/fixes for file $anchorTestFilePath. " +
"Please check if correct `WarningsFormat`/`FixFormat` is set (should be PLAIN) and if the file is present and called `$expectedWarningsFileName`."
)
val warningsFromPlain = plainFile.collectExpectedWarningsWithLineNumbers(
warnPluginConfig,
generalConfig
)
copyPaths.associate { copyPath ->
copyPath.name to warningsFromPlain.filter { it.fileName == copyPath.name }
}
}
ExpectedWarningsFormat.SARIF -> {
val warningsFromSarif = try {
collectWarningsFromSarif(expectedWarningsFileName, originalPaths, fs, workingDirectory)
} catch (e: Exception) {
throw SarifParsingException("We failed to parse sarif. Check the your tool generation of sarif report, cause: ${e.message}", e.cause)
}
copyPaths.associate { copyPath ->
copyPath.name to warningsFromSarif.filter { it.fileName == copyPath.name }
}
): WarningMap {
val expectedWarningsFileName: String by lazy {
warnPluginConfig.expectedWarningsFileName
?: throw IllegalArgumentException("<expectedWarningsFileName> is not provided for expectedWarningsFormat=${warnPluginConfig.expectedWarningsFormat}")

Check warning on line 272 in save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt

View check run for this annotation

Codecov / codecov/patch

save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt#L272

Added line #L272 was not covered by tests
}
return when (warnPluginConfig.expectedWarningsFormat) {
ExpectedWarningsFormat.PLAIN -> {
val anchorTestFilePath = originalPaths.first()

Check warning on line 276 in save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt

View check run for this annotation

Codecov / codecov/patch

save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt#L276

Added line #L276 was not covered by tests
val plainFile = fs.findFileInAncestorDir(anchorTestFilePath, expectedWarningsFileName) ?: throw PluginException(
"Could not find PLAIN file with expected warnings/fixes for file $anchorTestFilePath. " +
"Please check if correct `WarningsFormat`/`FixFormat` is set (should be PLAIN) and if the file is present and called `$expectedWarningsFileName`."

Check warning on line 279 in save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt

View check run for this annotation

Codecov / codecov/patch

save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt#L278-L279

Added lines #L278 - L279 were not covered by tests
)
val warningsFromPlain = plainFile.collectExpectedWarningsWithLineNumbers(
warnPluginConfig,
generalConfig

Check warning on line 283 in save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt

View check run for this annotation

Codecov / codecov/patch

save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt#L281-L283

Added lines #L281 - L283 were not covered by tests
)
copyPaths.associate { copyPath ->
copyPath.name to warningsFromPlain.filter { it.fileName == copyPath.name }

Check warning on line 286 in save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt

View check run for this annotation

Codecov / codecov/patch

save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt#L285-L286

Added lines #L285 - L286 were not covered by tests
}
else ->
throw IllegalArgumentException("<expectedWarningsFileName> cannot be provided for expectedWarningsFormat=${ExpectedWarningsFormat.IN_PLACE}")
}
}
else -> {
require(warnPluginConfig.expectedWarningsFormat != ExpectedWarningsFormat.SARIF) {
"<expectedWarningsFileName> should be provided for expectedWarningsFormat=${ExpectedWarningsFormat.SARIF}"
ExpectedWarningsFormat.SARIF -> {
val warningsFromSarif = try {
collectWarningsFromSarif(expectedWarningsFileName, originalPaths, fs, workingDirectory)
} catch (e: Exception) {
throw SarifParsingException("We failed to parse sarif. Check the your tool generation of sarif report, cause: ${e.message}", e.cause)

Check warning on line 293 in save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt

View check run for this annotation

Codecov / codecov/patch

save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt#L290-L293

Added lines #L290 - L293 were not covered by tests
}
copyPaths.associate { copyPath ->
copyPath.name to warningsFromSarif.filter { it.fileName == copyPath.name }

Check warning on line 296 in save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt

View check run for this annotation

Codecov / codecov/patch

save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt#L295-L296

Added lines #L295 - L296 were not covered by tests
}
}
copyPaths.associate { copyPath ->
else -> copyPaths.associate { copyPath ->
val warningsForCurrentPath =
copyPath.collectExpectedWarningsWithLineNumbers(
warnPluginConfig,
Expand Down

0 comments on commit 9c5fd57

Please sign in to comment.