From 8ef855816eecd2c1542cbfba482e11699edd3798 Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Tue, 31 Aug 2021 18:58:10 +0300 Subject: [PATCH] Support inline fixers for fix and warn plugin What's done: * Added support inline fixers for fix and warn plugin Closes #221 --- .../cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt | 12 ++++++++---- .../plugins/fixandwarn/FixAndWarnPluginConfig.kt | 9 ++++++--- .../save/plugins/fixandwarn/FixAndWarnPluginTest.kt | 3 ++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt b/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt index 44143b341..22c7dc633 100644 --- a/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt +++ b/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt @@ -34,12 +34,12 @@ class FixAndWarnPlugin( fileSystem, useInternalRedirections, redirectTo) { - private val fixPluginConfig: FixPluginConfig = - testConfig.pluginConfigs.filterIsInstance().single().fix - private val warnPluginConfig: WarnPluginConfig = - testConfig.pluginConfigs.filterIsInstance().single().warn + private val fixAndWarnPluginConfig: FixAndWarnPluginConfig = testConfig.pluginConfigs.filterIsInstance().single() + private val fixPluginConfig: FixPluginConfig = fixAndWarnPluginConfig.fix + private val warnPluginConfig: WarnPluginConfig = fixAndWarnPluginConfig.warn private val generalConfig: GeneralConfig = testConfig.pluginConfigs.filterIsInstance().single() + private val inlineFixer = fixAndWarnPluginConfig.inlineFixer private lateinit var fixPlugin: FixPlugin private lateinit var warnPlugin: WarnPlugin @@ -96,6 +96,10 @@ class FixAndWarnPlugin( } } + if (inlineFixer == true) { + 1 == 1 + } + // TODO: If we receive just one command for execution, and want to avoid extra executions // TODO: then warn plugin should look at the fix plugin output for actual warnings, and not execute command one more time. // TODO: However it's required changes in warn plugin logic (it's should be able to compare expected and actual warnings from different places), diff --git a/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPluginConfig.kt b/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPluginConfig.kt index 406696d9e..49a8e33b2 100644 --- a/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPluginConfig.kt +++ b/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPluginConfig.kt @@ -18,7 +18,8 @@ import kotlinx.serialization.Transient @Serializable data class FixAndWarnPluginConfig( val fix: FixPluginConfig, - val warn: WarnPluginConfig + val warn: WarnPluginConfig, + val inlineFixer: Boolean? = null, ) : PluginConfig { override val type = TestConfigSections.`FIX AND WARN` @@ -31,7 +32,8 @@ data class FixAndWarnPluginConfig( val mergedWarnPluginConfig = warn.mergeWith(other.warn) return FixAndWarnPluginConfig( mergedFixPluginConfig as FixPluginConfig, - mergedWarnPluginConfig as WarnPluginConfig + mergedWarnPluginConfig as WarnPluginConfig, + this.inlineFixer ?: otherConfig.inlineFixer ) } @@ -45,7 +47,8 @@ data class FixAndWarnPluginConfig( } return FixAndWarnPluginConfig( fix.validateAndSetDefaults(), - warn.validateAndSetDefaults() + warn.validateAndSetDefaults(), + inlineFixer ?: false, ) } } diff --git a/save-plugins/fix-and-warn-plugin/src/commonNonJsTest/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPluginTest.kt b/save-plugins/fix-and-warn-plugin/src/commonNonJsTest/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPluginTest.kt index 7783618c9..cc8a211d9 100644 --- a/save-plugins/fix-and-warn-plugin/src/commonNonJsTest/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPluginTest.kt +++ b/save-plugins/fix-and-warn-plugin/src/commonNonJsTest/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPluginTest.kt @@ -81,7 +81,8 @@ class FixAndWarnPluginTest { WarnPluginConfig(warnExecutionCmd, Regex("(.+):(\\d+):(\\d+): (.+)"), true, true, 1, ", ", 1, 2, 3, 1, 2, 3, 4 - ) + ), + false, ), GeneralConfig("", listOf(""), "", "", expectedWarningsPattern = Regex("// ;warn:(\\d+):(\\d+): (.*)")) ),