From c121c7db2efca39134270bfb298558e1fa3a2ffa Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Mon, 31 Oct 2022 09:13:35 +0000
Subject: [PATCH 1/9] Update dependency io.github.microutils:kotlin-logging-jvm
to v3
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b72f78aece..6ed8a75c5b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -196,7 +196,7 @@
io.github.microutils
kotlin-logging-jvm
- 2.1.23
+ 3.0.3
org.slf4j
From 80c405497a08fcf658cb14585397e91973b493df Mon Sep 17 00:00:00 2001
From: Nariman Abdullin
Date: Mon, 31 Oct 2022 14:18:58 +0300
Subject: [PATCH 2/9] removed slf4j
---
diktat-common/pom.xml | 14 --------------
.../config/reader/JsonResourceConfigReader.kt | 4 ++--
.../common/config/rules/RulesConfigReader.kt | 4 ++--
.../org/cqfn/diktat/common/utils/LoggingUtils.kt | 3 +--
diktat-rules/pom.xml | 14 --------------
diktat-ruleset/pom.xml | 10 ----------
diktat-test-framework/pom.xml | 8 --------
.../test/framework/common/StreamGobbler.java | 6 +++---
.../test/framework/common/LocalCommandExecutor.kt | 8 +++++---
.../test/framework/config/TestArgumentsReader.kt | 5 +++--
.../test/framework/processing/FileComparator.kt | 5 +++--
.../test/framework/processing/TestCheckWarn.kt | 7 ++++---
.../framework/processing/TestComparatorUnit.kt | 8 ++++----
.../test/framework/processing/TestCompare.kt | 7 ++++---
.../framework/processing/TestProcessingFactory.kt | 6 +++---
pom.xml | 14 ++------------
16 files changed, 36 insertions(+), 87 deletions(-)
diff --git a/diktat-common/pom.xml b/diktat-common/pom.xml
index 3d9c5f4c43..726d599346 100644
--- a/diktat-common/pom.xml
+++ b/diktat-common/pom.xml
@@ -38,20 +38,6 @@
com.pinterest.ktlint
ktlint-core
-
- org.slf4j
- slf4j-api
-
-
- org.apache.logging.log4j
- log4j-core
- test
-
-
- org.apache.logging.log4j
- log4j-slf4j-impl
- test
-
org.junit.jupiter
junit-jupiter
diff --git a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/JsonResourceConfigReader.kt b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/JsonResourceConfigReader.kt
index 6cd5dc0f64..a92415fe91 100644
--- a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/JsonResourceConfigReader.kt
+++ b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/JsonResourceConfigReader.kt
@@ -1,8 +1,8 @@
package org.cqfn.diktat.common.config.reader
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
+import mu.KLogger
import mu.KotlinLogging
-import org.slf4j.Logger
import java.io.BufferedReader
import java.io.IOException
@@ -61,6 +61,6 @@ abstract class JsonResourceConfigReader {
/**
* A [Logger] that can be used
*/
- val log: Logger = KotlinLogging.loggerWithKtlintConfig(JsonResourceConfigReader::class)
+ val log: KLogger = KotlinLogging.loggerWithKtlintConfig(JsonResourceConfigReader::class)
}
}
diff --git a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/rules/RulesConfigReader.kt b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/rules/RulesConfigReader.kt
index c5736eeb20..5605f89600 100644
--- a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/rules/RulesConfigReader.kt
+++ b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/rules/RulesConfigReader.kt
@@ -10,8 +10,8 @@ import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
+import mu.KLogger
import mu.KotlinLogging
-import org.slf4j.Logger
import java.io.BufferedReader
import java.io.File
@@ -111,7 +111,7 @@ open class RulesConfigReader(override val classLoader: ClassLoader) : JsonResour
/**
* A [Logger] that can be used
*/
- val log: Logger = KotlinLogging.loggerWithKtlintConfig(RulesConfigReader::class)
+ val log: KLogger = KotlinLogging.loggerWithKtlintConfig(RulesConfigReader::class)
}
}
diff --git a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/utils/LoggingUtils.kt b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/utils/LoggingUtils.kt
index 75feb2da40..71391e8923 100644
--- a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/utils/LoggingUtils.kt
+++ b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/utils/LoggingUtils.kt
@@ -6,7 +6,6 @@ package org.cqfn.diktat.common.utils
import com.pinterest.ktlint.core.initKtLintKLogger
import mu.KotlinLogging
-import org.slf4j.LoggerFactory
import kotlin.reflect.KClass
/**
@@ -25,4 +24,4 @@ fun KotlinLogging.loggerWithKtlintConfig(func: () -> Unit) =
* @return a logger
*/
fun KotlinLogging.loggerWithKtlintConfig(clazz: KClass<*>) =
- logger(LoggerFactory.getLogger(clazz.java)).initKtLintKLogger()
+ logger(clazz.java.name).initKtLintKLogger()
diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml
index f9a42ec34e..b3b839cb4a 100644
--- a/diktat-rules/pom.xml
+++ b/diktat-rules/pom.xml
@@ -49,20 +49,6 @@
io.github.microutils
kotlin-logging-jvm
-
- org.slf4j
- slf4j-api
-
-
- org.apache.logging.log4j
- log4j-core
- test
-
-
- org.apache.logging.log4j
- log4j-slf4j-impl
- test
-
org.junit.jupiter
junit-jupiter
diff --git a/diktat-ruleset/pom.xml b/diktat-ruleset/pom.xml
index 9edd86b9b9..1161e3e7b7 100644
--- a/diktat-ruleset/pom.xml
+++ b/diktat-ruleset/pom.xml
@@ -69,16 +69,6 @@
kotlin-compiler-embeddable
test
-
- org.apache.logging.log4j
- log4j-core
- test
-
-
- org.apache.logging.log4j
- log4j-slf4j-impl
- test
-
org.junit.jupiter
junit-jupiter
diff --git a/diktat-test-framework/pom.xml b/diktat-test-framework/pom.xml
index 1fbec323ee..f6f8b2d99f 100644
--- a/diktat-test-framework/pom.xml
+++ b/diktat-test-framework/pom.xml
@@ -30,14 +30,6 @@
commons-io
commons-io
-
- org.slf4j
- slf4j-api
-
-
- org.apache.logging.log4j
- log4j-core
-
org.apache.logging.log4j
log4j-slf4j-impl
diff --git a/diktat-test-framework/src/main/java/org/cqfn/diktat/test/framework/common/StreamGobbler.java b/diktat-test-framework/src/main/java/org/cqfn/diktat/test/framework/common/StreamGobbler.java
index 7484279135..e85be4490f 100644
--- a/diktat-test-framework/src/main/java/org/cqfn/diktat/test/framework/common/StreamGobbler.java
+++ b/diktat-test-framework/src/main/java/org/cqfn/diktat/test/framework/common/StreamGobbler.java
@@ -1,7 +1,7 @@
package org.cqfn.diktat.test.framework.common;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import mu.KLogger;
+import mu.KotlinLogging;
import java.io.BufferedReader;
import java.io.IOException;
@@ -12,7 +12,7 @@
import java.util.List;
public class StreamGobbler extends Thread {
- private static final Logger log = LoggerFactory.getLogger(StreamGobbler.class);
+ private static final KLogger log = KotlinLogging.INSTANCE.logger(StreamGobbler.class.getName());
private final InputStream inputStream;
private final String streamType;
private final ArrayList result;
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
index 10bb4949e6..17be30ab47 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
@@ -1,6 +1,8 @@
package org.cqfn.diktat.test.framework.common
-import org.slf4j.LoggerFactory
+import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
+import mu.KLogger
+import mu.KotlinLogging
import java.io.IOException
@@ -15,7 +17,7 @@ class LocalCommandExecutor internal constructor(private val command: String) {
*/
fun executeCommand(): ExecutionResult {
try {
- log.info("Executing command: {}", command)
+ log.info { "Executing command: $command" }
val process = Runtime.getRuntime().exec(command)
process.outputStream.close()
val inputStream = process.inputStream
@@ -32,6 +34,6 @@ class LocalCommandExecutor internal constructor(private val command: String) {
}
companion object {
- private val log = LoggerFactory.getLogger(LocalCommandExecutor::class.java)
+ private val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
index 58b615e67d..f30c188247 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
@@ -2,6 +2,8 @@ package org.cqfn.diktat.test.framework.config
import org.cqfn.diktat.common.cli.CliArgument
import org.cqfn.diktat.common.config.reader.JsonResourceConfigReader
+import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
+import mu.KotlinLogging
import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.CommandLineParser
@@ -9,7 +11,6 @@ import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.HelpFormatter
import org.apache.commons.cli.Options
import org.apache.commons.cli.ParseException
-import org.slf4j.LoggerFactory
import java.io.BufferedReader
import java.io.IOException
@@ -94,6 +95,6 @@ class TestArgumentsReader(
}
companion object {
- private val log = LoggerFactory.getLogger(TestArgumentsReader::class.java)
+ private val log = KotlinLogging.loggerWithKtlintConfig {}
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
index efe43d1c92..aba79a7d2f 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
@@ -1,9 +1,10 @@
package org.cqfn.diktat.test.framework.processing
+import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import io.github.petertrr.diffutils.diff
import io.github.petertrr.diffutils.patch.ChangeDelta
import io.github.petertrr.diffutils.text.DiffRowGenerator
-import org.slf4j.LoggerFactory
+import mu.KotlinLogging
import java.io.File
import java.io.IOException
@@ -96,7 +97,7 @@ class FileComparator(
}
companion object {
- private val log = LoggerFactory.getLogger(FileComparator::class.java)
+ private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
* @param file file where to write these list to, separated with newlines.
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCheckWarn.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCheckWarn.kt
index bc3fe6aabe..c803c460d1 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCheckWarn.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCheckWarn.kt
@@ -1,14 +1,15 @@
package org.cqfn.diktat.test.framework.processing
+import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import org.cqfn.diktat.test.framework.config.TestConfig
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
+import mu.KLogger
+import mu.KotlinLogging
/**
* [TestCompare] that uses stderr as tests output stream
*/
class TestCheckWarn : TestCompare() {
- @Suppress("MISSING_KDOC_CLASS_ELEMENTS") override val log: Logger = LoggerFactory.getLogger(TestCheckWarn::class.java)
+ @Suppress("MISSING_KDOC_CLASS_ELEMENTS") override val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
@Suppress(
"UnusedPrivateMember",
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
index 3d77f1419f..a62e9c6821 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
@@ -1,8 +1,8 @@
package org.cqfn.diktat.test.framework.processing
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-
+import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
+import mu.KLogger
+import mu.KotlinLogging
import java.io.IOException
import java.nio.file.Path
import java.nio.file.Paths
@@ -115,7 +115,7 @@ class TestComparatorUnit(
}
private companion object {
- private val log: Logger = LoggerFactory.getLogger(TestComparatorUnit::class.java)
+ private val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
/**
* @param file the file whose content is to be read.
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCompare.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCompare.kt
index e37ce0879d..036a6b61ed 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCompare.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCompare.kt
@@ -1,13 +1,14 @@
package org.cqfn.diktat.test.framework.processing
+import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import org.cqfn.diktat.test.framework.common.ExecutionResult
import org.cqfn.diktat.test.framework.common.TestBase
import org.cqfn.diktat.test.framework.config.TestConfig
import org.cqfn.diktat.test.framework.config.TestFrameworkProperties
+import mu.KLogger
+import mu.KotlinLogging
import org.apache.commons.io.FileUtils
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
import java.io.File
@@ -16,7 +17,7 @@ import java.io.File
*/
@Suppress("ForbiddenComment")
open class TestCompare : TestBase {
- @Suppress("MISSING_KDOC_CLASS_ELEMENTS") protected open val log: Logger = LoggerFactory.getLogger(TestCompare::class.java)
+ @Suppress("MISSING_KDOC_CLASS_ELEMENTS") protected open val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
private lateinit var expectedResult: File
// testResultFile will be used if and only if --in-place option will be used
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
index 6ed65a0c06..681356a07c 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
@@ -1,12 +1,12 @@
package org.cqfn.diktat.test.framework.processing
+import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import org.cqfn.diktat.test.framework.common.TestBase
import org.cqfn.diktat.test.framework.config.TestArgumentsReader
import org.cqfn.diktat.test.framework.config.TestConfig
import org.cqfn.diktat.test.framework.config.TestConfig.ExecutionType
import org.cqfn.diktat.test.framework.config.TestConfigReader
-
-import org.slf4j.LoggerFactory
+import mu.KotlinLogging
import java.io.File
import java.io.IOException
@@ -90,7 +90,7 @@ class TestProcessingFactory(private val argReader: TestArgumentsReader) {
}
companion object {
- private val log = LoggerFactory.getLogger(TestProcessingFactory::class.java)
+ private val log = KotlinLogging.loggerWithKtlintConfig {}
private const val STATUS_FIVE = 5
private const val STATUS_THREE = 3
}
diff --git a/pom.xml b/pom.xml
index 6ed8a75c5b..0586b771cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,7 +51,6 @@
1.9.1
1.1.0
31.1-jre
- 1.7.36
1.5.0
1.2.3
1.12.0
@@ -60,6 +59,7 @@
0.8.8
3.6.4
1.24
+ 3.0.3
2.19.0
@@ -196,17 +196,7 @@
io.github.microutils
kotlin-logging-jvm
- 3.0.3
-
-
- org.slf4j
- slf4j-api
- ${slf4j.version}
-
-
- org.apache.logging.log4j
- log4j-core
- ${log4j.version}
+ ${mu-logging.version}
org.apache.logging.log4j
From 64b10f924d5595082efa4d682836801351fb4214 Mon Sep 17 00:00:00 2001
From: Nariman Abdullin
Date: Mon, 31 Oct 2022 14:28:31 +0300
Subject: [PATCH 3/9] added suppressing
---
.../cqfn/diktat/test/framework/common/LocalCommandExecutor.kt | 4 ++--
.../cqfn/diktat/test/framework/config/TestArgumentsReader.kt | 1 +
.../cqfn/diktat/test/framework/processing/FileComparator.kt | 1 +
.../cqfn/diktat/test/framework/processing/TestCheckWarn.kt | 3 ++-
.../diktat/test/framework/processing/TestComparatorUnit.kt | 4 ++--
.../org/cqfn/diktat/test/framework/processing/TestCompare.kt | 3 ++-
.../diktat/test/framework/processing/TestProcessingFactory.kt | 1 +
7 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
index 17be30ab47..176286a23e 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
@@ -1,7 +1,6 @@
package org.cqfn.diktat.test.framework.common
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
-import mu.KLogger
import mu.KotlinLogging
import java.io.IOException
@@ -34,6 +33,7 @@ class LocalCommandExecutor internal constructor(private val command: String) {
}
companion object {
- private val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
+ private val log = KotlinLogging.loggerWithKtlintConfig {}
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
index f30c188247..72e8a420c5 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
@@ -95,6 +95,7 @@ class TestArgumentsReader(
}
companion object {
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
index aba79a7d2f..ca4fb600b0 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
@@ -97,6 +97,7 @@ class FileComparator(
}
companion object {
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCheckWarn.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCheckWarn.kt
index c803c460d1..8f26aa3fc0 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCheckWarn.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCheckWarn.kt
@@ -9,7 +9,8 @@ import mu.KotlinLogging
* [TestCompare] that uses stderr as tests output stream
*/
class TestCheckWarn : TestCompare() {
- @Suppress("MISSING_KDOC_CLASS_ELEMENTS") override val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR", "MISSING_KDOC_CLASS_ELEMENTS")
+ override val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
@Suppress(
"UnusedPrivateMember",
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
index a62e9c6821..b235e2d51a 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
@@ -1,7 +1,6 @@
package org.cqfn.diktat.test.framework.processing
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
-import mu.KLogger
import mu.KotlinLogging
import java.io.IOException
import java.nio.file.Path
@@ -115,7 +114,8 @@ class TestComparatorUnit(
}
private companion object {
- private val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
+ private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
* @param file the file whose content is to be read.
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCompare.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCompare.kt
index 036a6b61ed..30ae35cf16 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCompare.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestCompare.kt
@@ -17,7 +17,8 @@ import java.io.File
*/
@Suppress("ForbiddenComment")
open class TestCompare : TestBase {
- @Suppress("MISSING_KDOC_CLASS_ELEMENTS") protected open val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR", "MISSING_KDOC_CLASS_ELEMENTS")
+ protected open val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}
private lateinit var expectedResult: File
// testResultFile will be used if and only if --in-place option will be used
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
index 681356a07c..76b23cffd6 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
@@ -90,6 +90,7 @@ class TestProcessingFactory(private val argReader: TestArgumentsReader) {
}
companion object {
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
private const val STATUS_FIVE = 5
private const val STATUS_THREE = 3
From 101ea6fccde86612063fde25b30d3a514097d236 Mon Sep 17 00:00:00 2001
From: Nariman Abdullin
Date: Mon, 31 Oct 2022 15:07:13 +0300
Subject: [PATCH 4/9] added exclude to empty block rule for kotlin logging
---
.../ruleset/rules/chapter3/EmptyBlock.kt | 13 +++++++++++-
.../cqfn/diktat/ruleset/utils/KtlintUtils.kt | 1 -
.../diktat/ruleset/utils/StringCaseUtils.kt | 1 -
.../ruleset/chapter3/EmptyBlockWarnTest.kt | 15 ++++++++++++++
.../test/framework/common/StreamGobbler.java | 20 +++++++++++--------
.../framework/common/LocalCommandExecutor.kt | 9 ++++++---
.../framework/config/TestArgumentsReader.kt | 1 -
.../framework/processing/FileComparator.kt | 1 -
.../processing/TestComparatorUnit.kt | 1 -
.../processing/TestProcessingFactory.kt | 1 -
.../diktat/test/framework/util/TestUtils.kt | 1 -
11 files changed, 45 insertions(+), 19 deletions(-)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
index 46dbd1bbd0..13ce46cd3a 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
@@ -9,6 +9,7 @@ import org.cqfn.diktat.ruleset.utils.*
import com.pinterest.ktlint.core.ast.ElementType
import com.pinterest.ktlint.core.ast.ElementType.CALL_EXPRESSION
+import com.pinterest.ktlint.core.ast.ElementType.DOT_QUALIFIED_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.FUNCTION_LITERAL
import com.pinterest.ktlint.core.ast.ElementType.IDENTIFIER
import com.pinterest.ktlint.core.ast.ElementType.LAMBDA_EXPRESSION
@@ -46,7 +47,10 @@ class EmptyBlock(configRules: List) : DiktatRule(
@Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION")
private fun checkEmptyBlock(node: ASTNode, configuration: EmptyBlockStyleConfiguration) {
- if (node.treeParent.isOverridden() || isAnonymousSamClass(node) || isLambdaUsedAsFunction(node)) {
+ if (node.treeParent.isOverridden() ||
+ isAnonymousSamClass(node) ||
+ isLambdaUsedAsFunction(node) ||
+ isKotlinLogging(node)) {
return
}
if (node.isBlockEmpty()) {
@@ -118,6 +122,13 @@ class EmptyBlock(configRules: List) : DiktatRule(
}
}
+ private fun isKotlinLogging(node: ASTNode): Boolean = node.findParentNodeWithSpecificType(DOT_QUALIFIED_EXPRESSION)
+ ?.text
+ ?.replace(" ", "")
+ .let {
+ it == "KotlinLogging.logger{}"
+ }
+
/**
* [RuleConfiguration] for empty blocks formatting
*/
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt
index 6d773bd279..5a87647fd6 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt
@@ -13,7 +13,6 @@ import com.pinterest.ktlint.core.RuleSetProvider
import mu.KotlinLogging
import org.intellij.lang.annotations.Language
-@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
@Suppress("TYPE_ALIAS")
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt
index 61878af166..5bd2868fe7 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt
@@ -8,7 +8,6 @@ import mu.KotlinLogging
import java.util.Locale
-@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EmptyBlockWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EmptyBlockWarnTest.kt
index e846c948d2..7fe2f4dbae 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EmptyBlockWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EmptyBlockWarnTest.kt
@@ -238,4 +238,19 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) {
rulesConfigList = rulesConfigListEmptyBlockExist
)
}
+
+ @Test
+ @Tag(WarningNames.EMPTY_BLOCK_STRUCTURE_ERROR)
+ fun `should not trigger on KotlinLogging logger`() {
+ lintMethod(
+ """
+ |import mu.KotlinLogging
+ |
+ |fun some() {
+ | val log = KotlinLogging.logger {}
+ | log.info { "test" }
+ |}
+ """.trimMargin(),
+ )
+ }
}
diff --git a/diktat-test-framework/src/main/java/org/cqfn/diktat/test/framework/common/StreamGobbler.java b/diktat-test-framework/src/main/java/org/cqfn/diktat/test/framework/common/StreamGobbler.java
index e85be4490f..309c0c66f5 100644
--- a/diktat-test-framework/src/main/java/org/cqfn/diktat/test/framework/common/StreamGobbler.java
+++ b/diktat-test-framework/src/main/java/org/cqfn/diktat/test/framework/common/StreamGobbler.java
@@ -1,8 +1,5 @@
package org.cqfn.diktat.test.framework.common;
-import mu.KLogger;
-import mu.KotlinLogging;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -10,21 +7,28 @@
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.BiConsumer;
public class StreamGobbler extends Thread {
- private static final KLogger log = KotlinLogging.INSTANCE.logger(StreamGobbler.class.getName());
private final InputStream inputStream;
private final String streamType;
+ private final BiConsumer exceptionHandler;
private final ArrayList result;
private volatile boolean isStopped = false;
/**
* @param inputStream the InputStream to be consumed
- * @param streamType the stream type (should be OUTPUT or ERROR)
+ * @param streamType the stream type (should be OUTPUT or ERROR)
+ * @param exceptionHandler the exception handler
*/
- public StreamGobbler(final InputStream inputStream, final String streamType) {
+ public StreamGobbler(
+ final InputStream inputStream,
+ final String streamType,
+ final BiConsumer exceptionHandler
+ ) {
this.inputStream = inputStream;
this.streamType = streamType;
+ this.exceptionHandler = exceptionHandler;
this.result = new ArrayList<>();
}
@@ -43,7 +47,7 @@ synchronized public void run() {
this.result.add(line);
}
} catch (IOException ex) {
- log.error("Failed to consume and display the input stream of type " + streamType + ".", ex);
+ exceptionHandler.accept(ex, "Failed to consume and display the input stream of type " + streamType + ".");
} finally {
this.isStopped = true;
notify();
@@ -55,7 +59,7 @@ synchronized public List getContent() {
try {
wait();
} catch (InterruptedException e) {
- log.error("Cannot get content of output stream", e);
+ exceptionHandler.accept(e, "Cannot get content of output stream");
}
}
return this.result;
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
index 176286a23e..2c3594bec4 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
@@ -20,10 +20,14 @@ class LocalCommandExecutor internal constructor(private val command: String) {
val process = Runtime.getRuntime().exec(command)
process.outputStream.close()
val inputStream = process.inputStream
- val outputGobbler = StreamGobbler(inputStream, "OUTPUT")
+ val outputGobbler = StreamGobbler(inputStream, "OUTPUT") { msg, ex ->
+ log.error(ex, msg)
+ }
outputGobbler.start()
val errorStream = process.errorStream
- val errorGobbler = StreamGobbler(errorStream, "ERROR")
+ val errorGobbler = StreamGobbler(errorStream, "ERROR") { msg, ex ->
+ log.error(ex, msg)
+ }
errorGobbler.start()
return ExecutionResult(outputGobbler.content, errorGobbler.content)
} catch (ex: IOException) {
@@ -33,7 +37,6 @@ class LocalCommandExecutor internal constructor(private val command: String) {
}
companion object {
- @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
index 72e8a420c5..f30c188247 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
@@ -95,7 +95,6 @@ class TestArgumentsReader(
}
companion object {
- @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
index ca4fb600b0..aba79a7d2f 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
@@ -97,7 +97,6 @@ class FileComparator(
}
companion object {
- @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
index b235e2d51a..d1e64f1d3c 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
@@ -114,7 +114,6 @@ class TestComparatorUnit(
}
private companion object {
- @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
index 76b23cffd6..681356a07c 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
@@ -90,7 +90,6 @@ class TestProcessingFactory(private val argReader: TestArgumentsReader) {
}
companion object {
- @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
private const val STATUS_FIVE = 5
private const val STATUS_THREE = 3
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt
index 564297cf38..d513fa80a3 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt
@@ -21,7 +21,6 @@ import kotlin.io.path.absolute
import kotlin.io.path.deleteExisting
import kotlin.io.path.deleteIfExists
-@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
From 30e02235bb9ad02ed59216052be7fe236587a139 Mon Sep 17 00:00:00 2001
From: Nariman Abdullin
Date: Mon, 31 Oct 2022 14:28:31 +0300
Subject: [PATCH 5/9] added suppressing
---
.../diktat/common/config/reader/JsonResourceConfigReader.kt | 6 +-----
.../diktat/test/framework/common/LocalCommandExecutor.kt | 1 +
.../diktat/test/framework/config/TestArgumentsReader.kt | 1 +
.../cqfn/diktat/test/framework/processing/FileComparator.kt | 1 +
.../diktat/test/framework/processing/TestComparatorUnit.kt | 1 +
.../test/framework/processing/TestProcessingFactory.kt | 1 +
6 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/JsonResourceConfigReader.kt b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/JsonResourceConfigReader.kt
index a92415fe91..4d0d918091 100644
--- a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/JsonResourceConfigReader.kt
+++ b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/reader/JsonResourceConfigReader.kt
@@ -1,7 +1,6 @@
package org.cqfn.diktat.common.config.reader
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
-import mu.KLogger
import mu.KotlinLogging
import java.io.BufferedReader
@@ -58,9 +57,6 @@ abstract class JsonResourceConfigReader {
protected abstract fun parseResource(fileStream: BufferedReader): T
companion object {
- /**
- * A [Logger] that can be used
- */
- val log: KLogger = KotlinLogging.loggerWithKtlintConfig(JsonResourceConfigReader::class)
+ private val log = KotlinLogging.loggerWithKtlintConfig(JsonResourceConfigReader::class)
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
index 2c3594bec4..4a6ba5a6c9 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/common/LocalCommandExecutor.kt
@@ -37,6 +37,7 @@ class LocalCommandExecutor internal constructor(private val command: String) {
}
companion object {
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
index f30c188247..72e8a420c5 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt
@@ -95,6 +95,7 @@ class TestArgumentsReader(
}
companion object {
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
}
}
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
index aba79a7d2f..ca4fb600b0 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt
@@ -97,6 +97,7 @@ class FileComparator(
}
companion object {
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
index d1e64f1d3c..b235e2d51a 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt
@@ -114,6 +114,7 @@ class TestComparatorUnit(
}
private companion object {
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
index 681356a07c..76b23cffd6 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestProcessingFactory.kt
@@ -90,6 +90,7 @@ class TestProcessingFactory(private val argReader: TestArgumentsReader) {
}
companion object {
+ @Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
private const val STATUS_FIVE = 5
private const val STATUS_THREE = 3
From b8b5600d2fb3a34aaa6c990aedb2c4e015c11c0c Mon Sep 17 00:00:00 2001
From: Nariman Abdullin
Date: Mon, 31 Oct 2022 15:22:30 +0300
Subject: [PATCH 6/9] returned suppressing
---
.../src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt | 1 +
.../main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt | 1 +
.../main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt | 1 +
3 files changed, 3 insertions(+)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt
index 5a87647fd6..6d773bd279 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KtlintUtils.kt
@@ -13,6 +13,7 @@ import com.pinterest.ktlint.core.RuleSetProvider
import mu.KotlinLogging
import org.intellij.lang.annotations.Language
+@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
@Suppress("TYPE_ALIAS")
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt
index 5bd2868fe7..61878af166 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringCaseUtils.kt
@@ -8,6 +8,7 @@ import mu.KotlinLogging
import java.util.Locale
+@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt
index d513fa80a3..564297cf38 100644
--- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt
+++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/util/TestUtils.kt
@@ -21,6 +21,7 @@ import kotlin.io.path.absolute
import kotlin.io.path.deleteExisting
import kotlin.io.path.deleteIfExists
+@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}
/**
From 34583859707c9b4f8a55b7efca855e06dc894df7 Mon Sep 17 00:00:00 2001
From: Nariman Abdullin
Date: Mon, 31 Oct 2022 15:31:44 +0300
Subject: [PATCH 7/9] refactoring to resolve ComplexMethod
---
.../ruleset/rules/chapter3/EmptyBlock.kt | 71 +++++++++----------
1 file changed, 35 insertions(+), 36 deletions(-)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
index 13ce46cd3a..68bba81d38 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
@@ -39,54 +39,53 @@ class EmptyBlock(configRules: List) : DiktatRule(
private fun searchNode(node: ASTNode, configuration: EmptyBlockStyleConfiguration) {
val newNode = node.findLBrace()?.treeParent ?: return
- checkEmptyBlock(newNode, configuration)
+ if (!isAllowedEmptyBlock(node) && node.isBlockEmpty()) {
+ checkEmptyBlock(newNode, configuration)
+ }
}
private fun isNewLine(node: ASTNode) =
node.findChildByType(WHITE_SPACE)?.text?.contains("\n") ?: false
+ private fun isAllowedEmptyBlock(node: ASTNode) = node.treeParent.isOverridden() ||
+ isAnonymousSamClass(node) ||
+ isLambdaUsedAsFunction(node) ||
+ isKotlinLogging(node)
+
@Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION")
private fun checkEmptyBlock(node: ASTNode, configuration: EmptyBlockStyleConfiguration) {
- if (node.treeParent.isOverridden() ||
- isAnonymousSamClass(node) ||
- isLambdaUsedAsFunction(node) ||
- isKotlinLogging(node)) {
- return
- }
- if (node.isBlockEmpty()) {
- if (!configuration.emptyBlockExist) {
- EMPTY_BLOCK_STRUCTURE_ERROR.warn(configRules, emitWarn, isFixMode, "empty blocks are forbidden unless it is function with override keyword",
- node.startOffset, node)
- } else {
- node.findParentNodeWithSpecificType(ElementType.LAMBDA_ARGUMENT)?.let {
- // Lambda body is always has a BLOCK -> run { } - (LBRACE, WHITE_SPACE, BLOCK "", RBRACE)
- if (isNewLine(node)) {
- val freeText = "do not put newlines in empty lambda"
- EMPTY_BLOCK_STRUCTURE_ERROR.warnAndFix(configRules, emitWarn, isFixMode, freeText, node.startOffset, node) {
- val whiteSpaceNode = node.findChildByType(WHITE_SPACE)
- whiteSpaceNode?.let {
- node.replaceChild(whiteSpaceNode, PsiWhiteSpaceImpl(" "))
- }
+ if (!configuration.emptyBlockExist) {
+ EMPTY_BLOCK_STRUCTURE_ERROR.warn(configRules, emitWarn, isFixMode, "empty blocks are forbidden unless it is function with override keyword",
+ node.startOffset, node)
+ } else {
+ node.findParentNodeWithSpecificType(ElementType.LAMBDA_ARGUMENT)?.let {
+ // Lambda body is always has a BLOCK -> run { } - (LBRACE, WHITE_SPACE, BLOCK "", RBRACE)
+ if (isNewLine(node)) {
+ val freeText = "do not put newlines in empty lambda"
+ EMPTY_BLOCK_STRUCTURE_ERROR.warnAndFix(configRules, emitWarn, isFixMode, freeText, node.startOffset, node) {
+ val whiteSpaceNode = node.findChildByType(WHITE_SPACE)
+ whiteSpaceNode?.let {
+ node.replaceChild(whiteSpaceNode, PsiWhiteSpaceImpl(" "))
}
}
- return
}
- val space = node.findChildByType(RBRACE)!!.treePrev
- if (configuration.emptyBlockNewline && !space.text.contains("\n")) {
- EMPTY_BLOCK_STRUCTURE_ERROR.warnAndFix(configRules, emitWarn, isFixMode, "different style for empty block",
- node.startOffset, node) {
- if (space.elementType == WHITE_SPACE) {
- (space.treeNext as LeafPsiElement).rawReplaceWithText("\n")
- } else {
- node.addChild(PsiWhiteSpaceImpl("\n"), space.treeNext)
- }
- }
- } else if (!configuration.emptyBlockNewline && space.text.contains("\n")) {
- EMPTY_BLOCK_STRUCTURE_ERROR.warnAndFix(configRules, emitWarn, isFixMode, "different style for empty block",
- node.startOffset, node) {
- node.removeChild(space)
+ return
+ }
+ val space = node.findChildByType(RBRACE)!!.treePrev
+ if (configuration.emptyBlockNewline && !space.text.contains("\n")) {
+ EMPTY_BLOCK_STRUCTURE_ERROR.warnAndFix(configRules, emitWarn, isFixMode, "different style for empty block",
+ node.startOffset, node) {
+ if (space.elementType == WHITE_SPACE) {
+ (space.treeNext as LeafPsiElement).rawReplaceWithText("\n")
+ } else {
+ node.addChild(PsiWhiteSpaceImpl("\n"), space.treeNext)
}
}
+ } else if (!configuration.emptyBlockNewline && space.text.contains("\n")) {
+ EMPTY_BLOCK_STRUCTURE_ERROR.warnAndFix(configRules, emitWarn, isFixMode, "different style for empty block",
+ node.startOffset, node) {
+ node.removeChild(space)
+ }
}
}
}
From a1ad159bd7d582058f381e41d220c6fabef9db82 Mon Sep 17 00:00:00 2001
From: Nariman Abdullin
Date: Mon, 31 Oct 2022 15:36:12 +0300
Subject: [PATCH 8/9] diktatFix
---
.../org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
index 68bba81d38..cb3cc4441a 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
@@ -48,9 +48,9 @@ class EmptyBlock(configRules: List) : DiktatRule(
node.findChildByType(WHITE_SPACE)?.text?.contains("\n") ?: false
private fun isAllowedEmptyBlock(node: ASTNode) = node.treeParent.isOverridden() ||
- isAnonymousSamClass(node) ||
- isLambdaUsedAsFunction(node) ||
- isKotlinLogging(node)
+ isAnonymousSamClass(node) ||
+ isLambdaUsedAsFunction(node) ||
+ isKotlinLogging(node)
@Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION")
private fun checkEmptyBlock(node: ASTNode, configuration: EmptyBlockStyleConfiguration) {
From 4755b0f8b850419a332d3a693d9a7e5e9210dcea Mon Sep 17 00:00:00 2001
From: Nariman Abdullin
Date: Mon, 31 Oct 2022 15:40:06 +0300
Subject: [PATCH 9/9] fixed EmptyBlock
---
.../kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
index cb3cc4441a..06a231f849 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt
@@ -39,7 +39,7 @@ class EmptyBlock(configRules: List) : DiktatRule(
private fun searchNode(node: ASTNode, configuration: EmptyBlockStyleConfiguration) {
val newNode = node.findLBrace()?.treeParent ?: return
- if (!isAllowedEmptyBlock(node) && node.isBlockEmpty()) {
+ if (!isAllowedEmptyBlock(newNode) && newNode.isBlockEmpty()) {
checkEmptyBlock(newNode, configuration)
}
}