diff --git a/save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt b/save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt index bc8221de..6f5a3688 100644 --- a/save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt +++ b/save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/WarnPlugin.kt @@ -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> @@ -267,43 +266,37 @@ class WarnPlugin( originalPaths: List, copyPaths: List, 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(" is not provided for expectedWarningsFormat=${warnPluginConfig.expectedWarningsFormat}") + } + return 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 } } - else -> - throw IllegalArgumentException(" cannot be provided for expectedWarningsFormat=${ExpectedWarningsFormat.IN_PLACE}") } - } - else -> { - require(warnPluginConfig.expectedWarningsFormat != ExpectedWarningsFormat.SARIF) { - " 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) + } + copyPaths.associate { copyPath -> + copyPath.name to warningsFromSarif.filter { it.fileName == copyPath.name } + } } - copyPaths.associate { copyPath -> + else -> copyPaths.associate { copyPath -> val warningsForCurrentPath = copyPath.collectExpectedWarningsWithLineNumbers( warnPluginConfig,