diff --git a/README.md b/README.md
index fe82b07bda..0cc29e5a45 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ Now diKTat was already added to the lists of [static analysis tools](https://git
| | | | | | |
| --- | --- | --- | --- | --- | --- |
-|[Codestyle](info/guide/diktat-coding-convention.md)|[Inspections](info/available-rules.md) | [Examples](https://github.com/akuleshov7/diktat-examples) | [Demo](https://ktlint-demo.herokuapp.com) | [White Paper](wp/wp.pdf) | [Groups of Inspections](info/rules-mapping.md) |
+|[Codestyle](info/guide/diktat-coding-convention.md)|[Inspections](info/available-rules.md) | [Examples](examples) | [Demo](https://ktlint-demo.herokuapp.com) | [White Paper](wp/wp.pdf) | [Groups of Inspections](info/rules-mapping.md) |
## Why should I use diktat in my CI/CD?
@@ -163,6 +163,74 @@ diktat {
You can run diktat checks using task `diktatCheck` and automatically fix errors with tasks `diktatFix`.
+## Run with Spotless
+[Spotless](https://github.com/diffplug/spotless) is a linter aggregator.
+
+### Gradle
+Diktat can be run via spotless-gradle-plugin since version 5.10.0
+
+
+Add this plugin to your build.gradle.kts
+
+```kotlin
+plugins {
+ id("com.diffplug.spotless") version "5.10.0"
+}
+
+spotless {
+ kotlin {
+ diktat()
+ }
+ kotlinGradle {
+ diktat()
+ }
+}
+```
+
+
+
+You can provide a version and configuration path manually as configFile.
+
+```kotlin
+spotless {
+ kotlin {
+ diktat("0.4.0").configFile("full/path/to/diktat-analysis.yml")
+ }
+}
+```
+
+
+### Maven
+Diktat can be run via spotless-maven-plugin since version 2.8.0
+
+
+Add this plugin to your pom.xml
+
+```xml
+
+ com.diffplug.spotless
+ spotless-maven-plugin
+ ${spotless.version}
+
+
+
+
+
+
+```
+
+
+
+You can provide a version and configuration path manually as configFile
+
+```xml
+
+ 0.4.0
+ full/path/to/diktat-analysis.yml
+
+```
+
+
## Customizations via `diktat-analysis.yml`
In KTlint, rules can be configured via `.editorconfig`, but
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 94394510b2..771e063597 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
@@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory
import java.io.BufferedReader
import java.io.File
+import java.util.concurrent.atomic.AtomicInteger
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
@@ -122,7 +123,9 @@ data class CommonConfiguration(private val configuration: Map?)
*/
val kotlinVersion: KotlinVersion by lazy {
configuration?.get("kotlinVersion")?.kotlinVersion() ?: run {
- log.error("Kotlin version not specified in the configuration file. Will be using ${KotlinVersion.CURRENT} version")
+ if (visitorCounter.incrementAndGet() == 1) {
+ log.error("Kotlin version not specified in the configuration file. Will be using ${KotlinVersion.CURRENT} version")
+ }
KotlinVersion.CURRENT
}
}
@@ -131,6 +134,13 @@ data class CommonConfiguration(private val configuration: Map?)
* False if configuration has been read from config file, true if defaults are used
*/
val isDefault = configuration == null
+
+ companion object {
+ /**
+ * Counter that helps not to raise multiple warnings about kotlin version
+ */
+ var visitorCounter = AtomicInteger(0)
+ }
}
// ================== utils for List from yml config
@@ -138,9 +148,7 @@ data class CommonConfiguration(private val configuration: Map?)
/**
* @return common configuration from list of all rules configuration
*/
-fun List.getCommonConfiguration() = lazy {
- CommonConfiguration(getCommonConfig()?.configuration)
-}
+fun List.getCommonConfiguration() = CommonConfiguration(getCommonConfig()?.configuration)
/**
* Get [RulesConfig] for particular [Rule] object.
diff --git a/diktat-common/src/test/kotlin/org/cqfn/diktat/test/ConfigReaderTest.kt b/diktat-common/src/test/kotlin/org/cqfn/diktat/test/ConfigReaderTest.kt
index 4c0678fe65..ca7e2829e8 100644
--- a/diktat-common/src/test/kotlin/org/cqfn/diktat/test/ConfigReaderTest.kt
+++ b/diktat-common/src/test/kotlin/org/cqfn/diktat/test/ConfigReaderTest.kt
@@ -25,7 +25,7 @@ class ConfigReaderTest {
.readResource("src/test/resources/test-rules-config.yml")
val kotlinVersionForTest = KotlinVersion(1, 4, 21)
requireNotNull(rulesConfigList)
- assert(rulesConfigList.getCommonConfiguration().value.kotlinVersion == kotlinVersionForTest)
+ assert(rulesConfigList.getCommonConfiguration().kotlinVersion == kotlinVersionForTest)
assert(rulesConfigList.find { it.name == DIKTAT_COMMON }
?.configuration
?.get("kotlinVersion")
diff --git a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt
index 58ee144069..20bda86b63 100644
--- a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt
+++ b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt
@@ -8,8 +8,14 @@ package org.cqfn.diktat.plugin.gradle
import groovy.lang.Closure
-@Suppress("MISSING_KDOC_TOP_LEVEL", "MISSING_KDOC_CLASS_ELEMENTS", "KDOC_NO_CONSTRUCTOR_PROPERTY",
- "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", "KDOC_WITHOUT_RETURN_TAG")
+@Suppress(
+ "MISSING_KDOC_TOP_LEVEL",
+ "MISSING_KDOC_CLASS_ELEMENTS",
+ "KDOC_NO_CONSTRUCTOR_PROPERTY",
+ "MISSING_KDOC_ON_FUNCTION",
+ "KDOC_WITHOUT_PARAM_TAG",
+ "KDOC_WITHOUT_RETURN_TAG"
+)
class KotlinClosure1(
val function: T.() -> V?,
owner: Any? = null,
@@ -21,6 +27,11 @@ class KotlinClosure1(
// These two are copy-pasted from `kotlin-dsl` plugin's groovy interop.
// Because `kotlin-dsl` depends on kotlin 1.3.x.
-@Suppress("MISSING_KDOC_TOP_LEVEL", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", "KDOC_WITHOUT_RETURN_TAG")
+@Suppress(
+ "MISSING_KDOC_TOP_LEVEL",
+ "MISSING_KDOC_ON_FUNCTION",
+ "KDOC_WITHOUT_PARAM_TAG",
+ "KDOC_WITHOUT_RETURN_TAG"
+)
fun Any.closureOf(action: T.() -> Unit): Closure =
KotlinClosure1(action, this, this)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Chapters.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Chapters.kt
index 82886b3175..0861526047 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Chapters.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Chapters.kt
@@ -30,7 +30,7 @@ enum class Chapters(val number: String, val title: String) {
*/
fun Warnings.isRuleFromActiveChapter(configRules: List): Boolean {
val chapterFromRule = getChapterByWarning()
- val configuration by configRules.getCommonConfiguration()
+ val configuration = configRules.getCommonConfiguration()
val disabledChapters = configuration.disabledChapters
?.takeIf { it.isNotBlank() }
?.split(",")
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
index 92d00419a9..495c6c2aab 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
@@ -18,7 +18,13 @@ typealias ListOfPairs = MutableList>
* @property canBeAutoCorrected whether this inspection can automatically fix the code
* @property ruleId number of the inspection according to []diktat code style](https://www.cqfn.org/diKTat/info/guide/diktat-coding-convention.html)
*/
-@Suppress("ForbiddenComment", "MagicNumber", "WRONG_DECLARATIONS_ORDER", "MaxLineLength")
+@Suppress(
+ "ForbiddenComment",
+ "MagicNumber",
+ "WRONG_DECLARATIONS_ORDER",
+ "MaxLineLength",
+ "WRONG_NEWLINES"
+)
enum class Warnings(
val canBeAutoCorrected: Boolean,
val ruleId: String,
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt
index 26fc069de3..8c89d666d8 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt
@@ -26,7 +26,10 @@ import java.io.File
* Aggressive: In case file contains only one class on upper level - it should be named with the same name
*/
@Suppress("ForbiddenComment")
-class FileNaming(configRules: List) : DiktatRule("file-naming", configRules, listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) {
+class FileNaming(configRules: List) : DiktatRule(
+ "file-naming",
+ configRules,
+ listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) {
private lateinit var filePath: String
override fun logic(node: ASTNode) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt
index f80c6a6561..5974a76ad5 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt
@@ -79,7 +79,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
* // FixMe: because it fixes only declaration without the usages
*/
@Suppress("ForbiddenComment", "MISSING_KDOC_CLASS_ELEMENTS")
-class IdentifierNaming(configRules: List) : DiktatRule("identifier-naming", configRules,
+class IdentifierNaming(configRules: List) : DiktatRule(
+ "identifier-naming",
+ configRules,
listOf(BACKTICKS_PROHIBITED, VARIABLE_NAME_INCORRECT, VARIABLE_NAME_INCORRECT_FORMAT, CONSTANT_UPPERCASE,
VARIABLE_HAS_PREFIX, CONFUSING_IDENTIFIER_NAMING, GENERIC_NAME, CLASS_NAME_INCORRECT,
ENUM_VALUE, EXCEPTION_SUFFIX, FUNCTION_BOOLEAN_PREFIX, FUNCTION_NAME_INCORRECT_CASE,
@@ -148,7 +150,11 @@ class IdentifierNaming(configRules: List) : DiktatRule("identifier-
/**
* all checks for case and naming for vals/vars/constants
*/
- @Suppress("SAY_NO_TO_VAR", "TOO_LONG_FUNCTION", "ComplexMethod")
+ @Suppress(
+ "SAY_NO_TO_VAR",
+ "TOO_LONG_FUNCTION",
+ "ComplexMethod"
+ )
private fun checkVariableName(node: ASTNode): List {
// special case for Destructuring declarations that can be treated as parameters in lambda:
var namesOfVariables = extractVariableIdentifiers(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt
index 8756f3d898..cfb90b317f 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt
@@ -33,13 +33,15 @@ import java.util.concurrent.atomic.AtomicInteger
* package a.b.c.D -> then class D should be placed in a/b/c/ directories
*/
@Suppress("ForbiddenComment", "TOO_MANY_LINES_IN_LAMBDA")
-class PackageNaming(configRules: List) : DiktatRule("package-naming", configRules,
+class PackageNaming(configRules: List) : DiktatRule(
+ "package-naming",
+ configRules,
listOf(INCORRECT_PACKAGE_SEPARATOR, PACKAGE_NAME_INCORRECT_CASE, PACKAGE_NAME_MISSING,
PACKAGE_NAME_INCORRECT_PATH, PACKAGE_NAME_INCORRECT_PREFIX, PACKAGE_NAME_INCORRECT_SYMBOLS)) {
private lateinit var domainName: String
override fun logic(node: ASTNode) {
- val configuration by configRules.getCommonConfiguration()
+ val configuration = configRules.getCommonConfiguration()
configuration.domainName?.let {
domainName = it
if (node.elementType == PACKAGE_DIRECTIVE) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt
index 38d860bcbd..4b60e373ed 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt
@@ -23,7 +23,10 @@ import org.jetbrains.kotlin.resolve.ImportPath
* No commented out code is allowed, including imports.
*/
@Suppress("ForbiddenComment")
-class CommentsRule(configRules: List) : DiktatRule("comments", configRules, listOf(COMMENTED_OUT_CODE)) {
+class CommentsRule(configRules: List) : DiktatRule(
+ "comments",
+ configRules,
+ listOf(COMMENTED_OUT_CODE)) {
private lateinit var ktPsiFactory: KtPsiFactory
override fun logic(node: ASTNode) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt
index 05c5a95469..0b7541f012 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt
@@ -39,7 +39,9 @@ import java.time.LocalDate
* 4) Ensure files with many or zero classes have proper description
*/
@Suppress("ForbiddenComment")
-class HeaderCommentRule(configRules: List) : DiktatRule("header-comment", configRules,
+class HeaderCommentRule(configRules: List) : DiktatRule(
+ "header-comment",
+ configRules,
listOf(HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE, HEADER_MISSING_OR_WRONG_COPYRIGHT, HEADER_NOT_BEFORE_PACKAGE,
HEADER_NOT_BEFORE_PACKAGE, HEADER_WRONG_FORMAT, WRONG_COPYRIGHT_YEAR)) {
override fun logic(node: ASTNode) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt
index 97599a127e..d617286972 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt
@@ -49,7 +49,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
* * Leave one single space between the comment on the right side of the code and the code.
* * Comments in if else should be inside code blocks. Exception: General if comment
*/
-class CommentsFormatting(configRules: List) : DiktatRule("kdoc-comments-codeblocks-formatting", configRules,
+class CommentsFormatting(configRules: List) : DiktatRule(
+ "kdoc-comments-codeblocks-formatting",
+ configRules,
listOf(COMMENT_WHITE_SPACE, FIRST_COMMENT_NO_BLANK_LINE,
IF_ELSE_COMMENTS, WRONG_NEWLINES_AROUND_KDOC)) {
/**
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt
index 8e16f44d0f..96842d2c7f 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt
@@ -44,7 +44,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
* 2) All internal elements in class like class, property or function should be documented with KDoc
* 3) All properties declared in the primary constructor are documented using `@property` tag in class KDoc
*/
-class KdocComments(configRules: List) : DiktatRule("kdoc-comments", configRules,
+class KdocComments(configRules: List) : DiktatRule(
+ "kdoc-comments",
+ configRules,
listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY,
KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) {
/**
@@ -53,7 +55,7 @@ class KdocComments(configRules: List) : DiktatRule("kdoc-comments",
* @param emit
*/
override fun logic(node: ASTNode) {
- val config = configRules.getCommonConfiguration().value
+ val config = configRules.getCommonConfiguration()
val filePath = node.getRootNode().getFilePath()
if (!(node.hasTestAnnotation() || isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors))) {
when (node.elementType) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt
index 5fd4df686b..e958a8a0fb 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt
@@ -59,7 +59,9 @@ import java.time.temporal.ChronoField
* 7) ensuring @since tag contains only versions and not dates
*/
@Suppress("ForbiddenComment")
-class KdocFormatting(configRules: List) : DiktatRule("kdoc-formatting", configRules,
+class KdocFormatting(configRules: List) : DiktatRule(
+ "kdoc-formatting",
+ configRules,
listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG,
KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS,
KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt
index 2e13a98b9f..7957f96b96 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt
@@ -65,7 +65,9 @@ import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
* Currently only `throw` keyword from this methods body is supported for `@throws` check.
*/
@Suppress("ForbiddenComment")
-class KdocMethods(configRules: List) : DiktatRule("kdoc-methods", configRules,
+class KdocMethods(configRules: List) : DiktatRule(
+ "kdoc-methods",
+ configRules,
listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG,
KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) {
/**
@@ -75,7 +77,7 @@ class KdocMethods(configRules: List) : DiktatRule("kdoc-methods", c
*/
override fun logic(node: ASTNode) {
if (node.elementType == FUN && node.getFirstChildWithType(MODIFIER_LIST).isAccessibleOutside() && !node.isOverridden()) {
- val config = configRules.getCommonConfiguration().value
+ val config = configRules.getCommonConfiguration()
val filePath = node.getRootNode().getFilePath()
val isTestMethod = node.hasTestAnnotation() || isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors)
if (!isTestMethod && !node.isStandardMethod() && !node.isSingleLineGetterOrSetter()) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt
index dbd1f16b1a..ec025d6f15 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt
@@ -19,7 +19,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
/**
* This rule makes each annotation applied to a class, method or constructor is on its own line. Except: if first annotation of constructor, class or method
*/
-class AnnotationNewLineRule(configRules: List) : DiktatRule("annotation-new-line", configRules, listOf(ANNOTATION_NEW_LINE)) {
+class AnnotationNewLineRule(configRules: List) : DiktatRule(
+ "annotation-new-line",
+ configRules,
+ listOf(ANNOTATION_NEW_LINE)) {
override fun logic(node: ASTNode) {
when (node.elementType) {
CLASS, FUN, PRIMARY_CONSTRUCTOR, SECONDARY_CONSTRUCTOR -> checkAnnotation(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt
index fd1b254786..49a15eab5c 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt
@@ -49,7 +49,10 @@ import org.jetbrains.kotlin.psi.KtTryExpression
* - opening brace of lambda
* - braces around `else`/`catch`/`finally`/`while` (in `do-while` loop)
*/
-class BlockStructureBraces(configRules: List) : DiktatRule("block-structure", configRules, listOf(BRACES_BLOCK_STRUCTURE_ERROR)) {
+class BlockStructureBraces(configRules: List) : DiktatRule(
+ "block-structure",
+ configRules,
+ listOf(BRACES_BLOCK_STRUCTURE_ERROR)) {
override fun logic(node: ASTNode) {
val configuration = BlockStructureBracesConfiguration(
configRules.getRuleConfig(BRACES_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap()
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt
index d03b9a7dab..40ce08799a 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt
@@ -34,7 +34,10 @@ import org.jetbrains.kotlin.psi.psiUtil.astReplace
/**
* Rule that checks that all conditionals and loops have braces.
*/
-class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule("braces-rule", configRules, listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) {
+class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule(
+ "braces-rule",
+ configRules,
+ listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) {
override fun logic(node: ASTNode) {
when (node.elementType) {
IF -> checkIfNode(node)
@@ -47,7 +50,12 @@ class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatR
/**
* Check braces in if-else statements. Check for both IF and ELSE needs to be done in one method to discover single-line if-else statements correctly.
*/
- @Suppress("ForbiddenComment", "UnsafeCallOnNullableType", "ComplexMethod", "TOO_LONG_FUNCTION")
+ @Suppress(
+ "ForbiddenComment",
+ "UnsafeCallOnNullableType",
+ "ComplexMethod",
+ "TOO_LONG_FUNCTION"
+ )
private fun checkIfNode(node: ASTNode) {
val ifPsi = node.psi as KtIfExpression
val thenNode = ifPsi.then?.node
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt
index d3ef6941cc..bcfddb8934 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt
@@ -41,7 +41,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
/**
* Rule that checks order of declarations inside classes, interfaces and objects.
*/
-class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule("class-like-structures", configRules,
+class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule(
+ "class-like-structures",
+ configRules,
listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS_BODY) {
@@ -51,7 +53,12 @@ class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule(
}
}
- @Suppress("UnsafeCallOnNullableType", "LongMethod", "ComplexMethod", "TOO_LONG_FUNCTION")
+ @Suppress(
+ "UnsafeCallOnNullableType",
+ "LongMethod",
+ "ComplexMethod",
+ "TOO_LONG_FUNCTION"
+ )
private fun checkDeclarationsOrderInClass(node: ASTNode) {
val allProperties = node.getChildren(TokenSet.create(PROPERTY))
val constProperties = allProperties.filter { it.findLeafWithSpecificType(CONST_KEYWORD) != null }.toMutableList()
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt
index caac371b96..73411dc604 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt
@@ -20,7 +20,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement
* 2) If saveInitialFormattingForEnums is true then white spaces in enums will not be affected
*
*/
-class ConsecutiveSpacesRule(configRules: List) : DiktatRule("too-many-spaces", configRules, listOf(TOO_MANY_CONSECUTIVE_SPACES)) {
+class ConsecutiveSpacesRule(configRules: List) : DiktatRule(
+ "too-many-spaces",
+ configRules,
+ listOf(TOO_MANY_CONSECUTIVE_SPACES)) {
override fun logic(node: ASTNode) {
val configuration = TooManySpacesRuleConfiguration(
configRules.getRuleConfig(TOO_MANY_CONSECUTIVE_SPACES)?.configuration ?: emptyMap())
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 4525e11ea7..1034ed1063 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
@@ -25,7 +25,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
/**
* Rule that checks if empty code blocks (`{ }`) are used and checks their formatting.
*/
-class EmptyBlock(configRules: List) : DiktatRule("empty-block-structure", configRules, listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) {
+class EmptyBlock(configRules: List) : DiktatRule(
+ "empty-block-structure",
+ configRules,
+ listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) {
override fun logic(node: ASTNode) {
val configuration = EmptyBlockStyleConfiguration(
configRules.getRuleConfig(EMPTY_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap()
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt
index cbe6e1c8e9..fe607214c4 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt
@@ -26,7 +26,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
/**
* Rule that checks enum classes formatting
*/
-class EnumsSeparated(configRules: List) : DiktatRule("enum-separated", configRules, listOf(ENUMS_SEPARATED)) {
+class EnumsSeparated(configRules: List) : DiktatRule(
+ "enum-separated",
+ configRules,
+ listOf(ENUMS_SEPARATED)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS && node.hasChildOfType(CLASS_BODY)) {
if (node.isClassEnum()) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt
index 92612f05be..a259e7c3f4 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt
@@ -57,7 +57,10 @@ import java.net.URL
* Rule can fix long binary expressions in condition inside `if` and in property declarations and one line functions
*/
@Suppress("ForbiddenComment")
-class LineLength(configRules: List) : DiktatRule("line-length", configRules, listOf(LONG_LINE)) {
+class LineLength(configRules: List) : DiktatRule(
+ "line-length",
+ configRules,
+ listOf(LONG_LINE)) {
private lateinit var positionByOffset: (Int) -> Pair
override fun logic(node: ASTNode) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt
index 93da60e617..556b79cff2 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt
@@ -16,7 +16,10 @@ import java.lang.StringBuilder
/**
* Rule that checks if numerical separators (`_`) are used for long numerical literals
*/
-class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule("long-numerical-values", configRules, listOf(LONG_NUMERICAL_VALUES_SEPARATED)) {
+class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule(
+ "long-numerical-values",
+ configRules,
+ listOf(LONG_NUMERICAL_VALUES_SEPARATED)) {
override fun logic(node: ASTNode) {
val configuration = LongNumericalValuesConfiguration(
configRules.getRuleConfig(LONG_NUMERICAL_VALUES_SEPARATED)?.configuration ?: emptyMap())
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt
index 113c2b9077..a326996341 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt
@@ -15,7 +15,10 @@ import org.jetbrains.kotlin.psi.psiUtil.children
/**
* @property configRules
*/
-class MultipleModifiersSequence(configRules: List) : DiktatRule("multiple-modifiers", configRules, listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) {
+class MultipleModifiersSequence(configRules: List) : DiktatRule(
+ "multiple-modifiers",
+ configRules,
+ listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) {
override fun logic(node: ASTNode) {
if (node.elementType == MODIFIER_LIST) {
checkModifierList(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt
index 8215f3b5a5..6ef6d78631 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt
@@ -37,7 +37,10 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
/**
* Rule that checks if nullable types are used and suggest to substitute them with non-nullable
*/
-class NullableTypeRule(configRules: List) : DiktatRule("nullable-type", configRules, listOf(NULLABLE_PROPERTY_TYPE)) {
+class NullableTypeRule(configRules: List) : DiktatRule(
+ "nullable-type",
+ configRules,
+ listOf(NULLABLE_PROPERTY_TYPE)) {
override fun logic(node: ASTNode) {
if (node.elementType == PROPERTY) {
checkProperty(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt
index 806dafa989..a4fc8ec5e4 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt
@@ -18,7 +18,10 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet
/**
* Rule that looks for multiple statements on a single line separated with a `;` and splits them in multiple lines.
*/
-class SingleLineStatementsRule(configRules: List) : DiktatRule("statement", configRules, listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) {
+class SingleLineStatementsRule(configRules: List) : DiktatRule(
+ "statement",
+ configRules,
+ listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) {
override fun logic(node: ASTNode) {
checkSemicolon(node)
}
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt
index 8f9179558f..51fee533d6 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt
@@ -5,28 +5,36 @@ import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.common.config.rules.getRuleConfig
import org.cqfn.diktat.ruleset.constants.Warnings.WRONG_DECLARATIONS_ORDER
import org.cqfn.diktat.ruleset.rules.DiktatRule
+import org.cqfn.diktat.ruleset.utils.findAllNodesWithSpecificType
import org.cqfn.diktat.ruleset.utils.hasChildOfType
import org.cqfn.diktat.ruleset.utils.isClassEnum
-import com.pinterest.ktlint.core.ast.ElementType
import com.pinterest.ktlint.core.ast.ElementType.CLASS_BODY
import com.pinterest.ktlint.core.ast.ElementType.COMMA
import com.pinterest.ktlint.core.ast.ElementType.CONST_KEYWORD
+import com.pinterest.ktlint.core.ast.ElementType.ENUM_ENTRY
+import com.pinterest.ktlint.core.ast.ElementType.EOL_COMMENT
import com.pinterest.ktlint.core.ast.ElementType.IDENTIFIER
import com.pinterest.ktlint.core.ast.ElementType.MODIFIER_LIST
import com.pinterest.ktlint.core.ast.ElementType.PROPERTY
import com.pinterest.ktlint.core.ast.ElementType.SEMICOLON
+import com.pinterest.ktlint.core.ast.isPartOfComment
+import com.pinterest.ktlint.core.ast.isWhiteSpace
import com.pinterest.ktlint.core.ast.isWhiteSpaceWithNewline
import com.pinterest.ktlint.core.ast.nextSibling
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
import org.jetbrains.kotlin.psi.KtObjectDeclaration
+import org.jetbrains.kotlin.psi.psiUtil.siblings
/**
* Rule that sorts class properties and enum members alphabetically
*/
-class SortRule(configRules: List) : DiktatRule("sort-rule", configRules, listOf(WRONG_DECLARATIONS_ORDER)) {
+class SortRule(configRules: List) : DiktatRule(
+ "sort-rule",
+ configRules,
+ listOf(WRONG_DECLARATIONS_ORDER)) {
override fun logic(node: ASTNode) {
val configuration = SortRuleConfiguration(
configRules.getRuleConfig(WRONG_DECLARATIONS_ORDER)?.configuration ?: emptyMap()
@@ -67,17 +75,41 @@ class SortRule(configRules: List) : DiktatRule("sort-rule", configR
}
}
+ @OptIn(ExperimentalStdlibApi::class)
private fun swapSortNodes(
sortList: List,
nonSortList: List,
node: ASTNode) {
- val nodeBefore: ASTNode? = nonSortList.last().treeNext
+ val isEnum = nonSortList.first().elementType == ENUM_ENTRY
+ val spaceBefore = if (node.findAllNodesWithSpecificType(EOL_COMMENT).isNotEmpty() && isEnum) {
+ nonSortList.last().run {
+ if (this.hasChildOfType(EOL_COMMENT) && !this.hasChildOfType(COMMA)) {
+ this.addChild(LeafPsiElement(COMMA, ","), this.findChildByType(EOL_COMMENT))
+ }
+ }
+ buildList(nonSortList.size) {
+ add(null)
+ repeat(nonSortList.size - 1) {
+ add(listOf(PsiWhiteSpaceImpl("\n")))
+ }
+ }
+ } else {
+ nonSortList.map { astNode ->
+ astNode
+ .siblings(false)
+ .toList()
+ .takeWhile { it.isWhiteSpace() || it.isPartOfComment() }
+ .ifEmpty { null }
+ }
+ }
+ val nodeInsertBefore: ASTNode? = nonSortList.last().treeNext
node.removeRange(nonSortList.first(), nonSortList.last().treeNext)
- sortList.forEachIndexed { nodeIndex, astNode ->
- if (nodeIndex != 0) {
- node.addChild(PsiWhiteSpaceImpl("\n"), nodeBefore)
+ sortList.mapIndexed { index, astNode ->
+ spaceBefore[index]?.let { prevList -> prevList.map { node.addChild(it, nodeInsertBefore) } }
+ if (!astNode.hasChildOfType(COMMA) && isEnum) {
+ astNode.addChild(LeafPsiElement(COMMA, ","), null)
}
- node.addChild(astNode, nodeBefore)
+ node.addChild(astNode, nodeInsertBefore)
}
}
@@ -99,7 +131,7 @@ class SortRule(configRules: List) : DiktatRule("sort-rule", configR
@Suppress("UnsafeCallOnNullableType")
private fun sortEnum(node: ASTNode) {
- val enumEntryList = node.getChildren(null).filter { it.elementType == ElementType.ENUM_ENTRY }
+ val enumEntryList = node.getChildren(null).filter { it.elementType == ENUM_ENTRY }
if (enumEntryList.size <= 1) {
return
}
@@ -110,8 +142,8 @@ class SortRule(configRules: List) : DiktatRule("sort-rule", configR
val hasTrailingComma = (sortList.last() != enumEntryList.last() && enumEntryList.last().hasChildOfType(COMMA))
swapSortNodes(sortList, enumEntryList, node)
if (!hasTrailingComma) {
- enumEntryList.last().addChild(LeafPsiElement(COMMA, ","), null)
- sortList.last().removeChild(sortList.last().findChildByType(COMMA)!!)
+ val lastEntry = node.findAllNodesWithSpecificType(ENUM_ENTRY).last()
+ lastEntry.removeChild(lastEntry.findChildByType(COMMA)!!)
}
if (isEndSpace) {
sortList.last().addChild(PsiWhiteSpaceImpl("\n"), null)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt
index cdd52d046d..9b2be11948 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt
@@ -19,7 +19,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
* // FixMe: fixes will be added
* // FixMe: .toString() method and functions that return strings are not supported
*/
-class StringConcatenationRule(configRules: List) : DiktatRule("string-concatenation", configRules, listOf(STRING_CONCATENATION)) {
+class StringConcatenationRule(configRules: List) : DiktatRule(
+ "string-concatenation",
+ configRules,
+ listOf(STRING_CONCATENATION)) {
override fun logic(node: ASTNode) {
if (node.elementType == BINARY_EXPRESSION) {
// searching top-level binary expression to detect any operations with "plus" (+)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt
index 00563eaf29..40d5b607cf 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt
@@ -28,7 +28,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
*
* FixMe: The important caveat here: in "$foo" kotlin compiler adds implicit call to foo.toString() in case foo type is not string.
*/
-class StringTemplateFormatRule(configRules: List) : DiktatRule("string-template-format", configRules,
+class StringTemplateFormatRule(configRules: List) : DiktatRule(
+ "string-template-format",
+ configRules,
listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) {
override fun logic(node: ASTNode) {
when (node.elementType) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt
index 4d2d29c23a..c1061ff8cc 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt
@@ -49,8 +49,11 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
* [12] Destructuring declarations
*/
@Suppress("TOO_LONG_FUNCTION")
-class TrailingCommaRule(configRules: List) : DiktatRule("trailing-comma", configRules, listOf(TRAILING_COMMA)) {
- private val commonConfig by configRules.getCommonConfiguration()
+class TrailingCommaRule(configRules: List) : DiktatRule(
+ "trailing-comma",
+ configRules,
+ listOf(TRAILING_COMMA)) {
+ private val commonConfig = configRules.getCommonConfiguration()
private val trailingConfig = this.configRules.getRuleConfig(TRAILING_COMMA)?.configuration ?: emptyMap()
private val configuration by lazy {
if (trailingConfig.isEmpty()) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt
index f40c874d7f..98f289431a 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt
@@ -36,7 +36,10 @@ import org.jetbrains.kotlin.psi.KtWhenExpression
* The compiler can issue a warning when it is missing.
*/
@Suppress("ForbiddenComment")
-class WhenMustHaveElseRule(configRules: List) : DiktatRule("no-else-in-when", configRules, listOf(WHEN_WITHOUT_ELSE)) {
+class WhenMustHaveElseRule(configRules: List) : DiktatRule(
+ "no-else-in-when",
+ configRules,
+ listOf(WHEN_WITHOUT_ELSE)) {
override fun logic(node: ASTNode) {
if (node.elementType == ElementType.WHEN && isStatement(node)) {
checkEntries(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt
index 2cd8be0c2e..d055ffbf7f 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt
@@ -23,7 +23,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
* 1. Checks that no more than two consecutive blank lines are used in a row
* 2. Checks that blank lines are not put in the beginning or at the end of code blocks with curly braces
*/
-class BlankLinesRule(configRules: List) : DiktatRule("blank-lines", configRules, listOf(TOO_MANY_BLANK_LINES)) {
+class BlankLinesRule(configRules: List) : DiktatRule(
+ "blank-lines",
+ configRules,
+ listOf(TOO_MANY_BLANK_LINES)) {
override fun logic(node: ASTNode) {
if (node.elementType == WHITE_SPACE) {
// note that no blank lines counts as one newline
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt
index e9d8086b2b..461c9ec925 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt
@@ -15,7 +15,10 @@ import org.slf4j.LoggerFactory
/**
* Rule that checks number of lines in a file
*/
-class FileSize(configRules: List) : DiktatRule("file-size", configRules, listOf(FILE_IS_TOO_LONG)) {
+class FileSize(configRules: List) : DiktatRule(
+ "file-size",
+ configRules,
+ listOf(FILE_IS_TOO_LONG)) {
private val configuration by lazy {
FileSizeConfiguration(
this.configRules.getRuleConfig(FILE_IS_TOO_LONG)?.configuration ?: emptyMap()
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileStructureRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileStructureRule.kt
index 76ec154d8f..a6b2eb85b6 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileStructureRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileStructureRule.kt
@@ -55,13 +55,14 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
* 4. Ensures imports are ordered alphabetically without blank lines
* 5. Ensures there are no wildcard imports
*/
-class FileStructureRule(configRules: List) : DiktatRule("file-structure", configRules,
+class FileStructureRule(configRules: List) : DiktatRule(
+ "file-structure",
+ configRules,
listOf(FILE_CONTAINS_ONLY_COMMENTS, FILE_INCORRECT_BLOCKS_ORDER, FILE_NO_BLANK_LINE_BETWEEN_BLOCKS,
FILE_UNORDERED_IMPORTS, FILE_WILDCARD_IMPORTS, UNUSED_IMPORT)) {
private val domainName by lazy {
configRules
.getCommonConfiguration()
- .value
.domainName
}
private val standardImportsAsName = StandardPlatforms
@@ -73,6 +74,7 @@ class FileStructureRule(configRules: List) : DiktatRule("file-struc
}
private val refSet: MutableSet = mutableSetOf()
private var packageName = ""
+ private val ignoreImports = setOf("invoke", "get", "set")
override fun logic(node: ASTNode) {
if (node.elementType == FILE) {
@@ -222,7 +224,7 @@ class FileStructureRule(configRules: List) : DiktatRule("file-struc
) {
// this branch corresponds to imports from the same package
deleteImport(importPath, node, ktImportDirective)
- } else if (importName != null && !refSet.contains(
+ } else if (importName != null && !ignoreImports.contains(importName) && !refSet.contains(
importName
)
) {
@@ -245,14 +247,21 @@ class FileStructureRule(configRules: List) : DiktatRule("file-struc
}
private fun findAllReferences(node: ASTNode) {
- node.findAllNodesWithSpecificType(OPERATION_REFERENCE)?.forEach { ref ->
+ node.findAllNodesWithSpecificType(OPERATION_REFERENCE).forEach { ref ->
if (!ref.isPartOf(IMPORT_DIRECTIVE)) {
- operatorMap.filterValues { it == ref.text }.keys.forEach { key -> refSet.add(key) }
+ val references = operatorMap.filterValues { it == ref.text }
+ if (references.isNotEmpty()) {
+ references.keys.forEach { key -> refSet.add(key) }
+ } else {
+ // this is needed to check infix functions that relate to operation reference
+ refSet.add(ref.text)
+ }
}
}
- node.findAllNodesWithSpecificType(REFERENCE_EXPRESSION)?.forEach {
+ node.findAllNodesWithSpecificType(REFERENCE_EXPRESSION).forEach {
if (!it.isPartOf(IMPORT_DIRECTIVE)) {
- refSet.add(it.text)
+ // the importedName method removes the quotes, but the node.text method does not
+ refSet.add(it.text.replace("`", ""))
}
}
}
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt
index 7f2118dc88..e016143a83 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt
@@ -69,7 +69,10 @@ import kotlin.math.abs
* Additionally, a set of CustomIndentationChecker objects checks all WHITE_SPACE node if they are exceptions from general rules.
* @see CustomIndentationChecker
*/
-class IndentationRule(configRules: List) : DiktatRule("indentation", configRules, listOf(WRONG_INDENTATION)) {
+class IndentationRule(configRules: List) : DiktatRule(
+ "indentation",
+ configRules,
+ listOf(WRONG_INDENTATION)) {
private val configuration: IndentationConfig by lazy {
IndentationConfig(configRules.getRuleConfig(WRONG_INDENTATION)?.configuration ?: emptyMap())
}
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt
index d75eedfcaa..bf98038dfe 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt
@@ -51,6 +51,7 @@ import com.pinterest.ktlint.core.ast.ElementType.PLUS
import com.pinterest.ktlint.core.ast.ElementType.PLUSEQ
import com.pinterest.ktlint.core.ast.ElementType.POSTFIX_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.PRIMARY_CONSTRUCTOR
+import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.RETURN
import com.pinterest.ktlint.core.ast.ElementType.RETURN_KEYWORD
import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS
@@ -77,6 +78,7 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtParameterList
import org.jetbrains.kotlin.psi.KtSuperTypeList
+import org.jetbrains.kotlin.psi.KtValueArgumentList
import org.jetbrains.kotlin.psi.psiUtil.children
import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.psi.psiUtil.siblings
@@ -95,7 +97,10 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
* 10. Complex expression inside condition replaced with new variable
*/
@Suppress("ForbiddenComment")
-class NewlinesRule(configRules: List) : DiktatRule("newlines", configRules, listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) {
+class NewlinesRule(configRules: List) : DiktatRule(
+ "newlines",
+ configRules,
+ listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) {
private val configuration by lazy {
NewlinesRuleConfiguration(configRules.getRuleConfig(WRONG_NEWLINES)?.configuration ?: emptyMap())
}
@@ -108,7 +113,7 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf
COMMA -> handleComma(node)
BLOCK -> handleLambdaBody(node)
RETURN -> handleReturnStatement(node)
- SUPER_TYPE_LIST, VALUE_PARAMETER_LIST -> handleList(node)
+ SUPER_TYPE_LIST, VALUE_PARAMETER_LIST, VALUE_ARGUMENT_LIST -> handleList(node)
else -> {
}
}
@@ -299,15 +304,22 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf
* Checks that members of [VALUE_PARAMETER_LIST] (list of function parameters at declaration site) are separated with newlines.
* Also checks that entries of [SUPER_TYPE_LIST] are separated by newlines.
*/
+ @Suppress("ComplexMethod")
private fun handleList(node: ASTNode) {
if (node.elementType == VALUE_PARAMETER_LIST && node.treeParent.elementType.let { it == FUNCTION_TYPE || it == FUNCTION_TYPE_RECEIVER }) {
// do not check other value lists
return
}
+ if (node.elementType == VALUE_ARGUMENT_LIST && node.siblings(forward = false).any { it.elementType == REFERENCE_EXPRESSION }) {
+ // check that it is not function invocation, but only supertype constructor calls
+ return
+ }
+
val (numEntries, entryType) = when (node.elementType) {
VALUE_PARAMETER_LIST -> (node.psi as KtParameterList).parameters.size to "value parameters"
SUPER_TYPE_LIST -> (node.psi as KtSuperTypeList).entries.size to "supertype list entries"
+ VALUE_ARGUMENT_LIST -> (node.psi as KtValueArgumentList).arguments.size to "value arguments"
else -> {
log.warn("Unexpected node element type ${node.elementType}")
return
@@ -315,7 +327,10 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf
}
if (numEntries > configuration.maxParametersInOneLine) {
when (node.elementType) {
- VALUE_PARAMETER_LIST -> handleFirstValueParameter(node)
+ VALUE_PARAMETER_LIST -> handleFirstValue(node, VALUE_PARAMETER, "first parameter should be placed on a separate line " +
+ "or all other parameters should be aligned with it in declaration of <${node.getParentIdentifier()}>")
+ VALUE_ARGUMENT_LIST -> handleFirstValue(node, VALUE_ARGUMENT, "first value argument (%s) should be placed on the new line " +
+ "or all other parameters should be aligned with it")
else -> {
}
}
@@ -324,24 +339,31 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf
}
}
- private fun handleFirstValueParameter(node: ASTNode) = node
+ private fun handleFirstValue(node: ASTNode,
+ filterType: IElementType,
+ warnText: String) = node
.children()
.takeWhile { !it.textContains('\n') }
- .filter { it.elementType == VALUE_PARAMETER }
+ .filter { it.elementType == filterType }
.toList()
.takeIf { it.size > 1 }
- ?.let {
- WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, "first parameter should be placed on a separate line " +
- "or all other parameters should be aligned with it in declaration of <${node.getParentIdentifier()}>", node.startOffset, node) {
+ ?.let { list ->
+ val freeText = if (filterType == VALUE_ARGUMENT) {
+ warnText.format(list.first().text)
+ } else {
+ warnText
+ }
+ WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, freeText, node.startOffset, node) {
node.appendNewlineMergingWhiteSpace(
- it.first()
+ list.first()
.treePrev
.takeIf { it.elementType == WHITE_SPACE },
- it.first()
+ list.first()
)
}
}
+ @Suppress("AVOID_NULL_CHECKS")
private fun handleValueParameterList(node: ASTNode, entryType: String) = node
.children()
.filter {
@@ -351,8 +373,13 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf
.toList()
.takeIf { it.isNotEmpty() }
?.let { invalidCommas ->
+ val warnText = if (node.getParentIdentifier() != null) {
+ "$entryType should be placed on different lines in declaration of <${node.getParentIdentifier()}>"
+ } else {
+ "$entryType should be placed on different lines"
+ }
WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode,
- "$entryType should be placed on different lines in declaration of <${node.getParentIdentifier()}>", node.startOffset, node) {
+ warnText, node.startOffset, node) {
invalidCommas.forEach { comma ->
val nextWhiteSpace = comma.treeNext.takeIf { it.elementType == WHITE_SPACE }
comma.appendNewlineMergingWhiteSpace(nextWhiteSpace, nextWhiteSpace?.treeNext ?: comma.treeNext)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt
index ac967e1e46..473d3b3627 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt
@@ -25,7 +25,10 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
/**
* Rule that checks order in top level
*/
-class TopLevelOrderRule(configRules: List) : DiktatRule("top-level-order", configRules, listOf(TOP_LEVEL_ORDER)) {
+class TopLevelOrderRule(configRules: List) : DiktatRule(
+ "top-level-order",
+ configRules,
+ listOf(TOP_LEVEL_ORDER)) {
override fun logic(node: ASTNode) {
if (node.elementType == FILE) {
checkNode(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt
index b05694f620..254de14f43 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt
@@ -92,7 +92,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
* 10. There should be no spaces between prefix/postfix operator (like `!!` or `++`) and it's operand
*/
@Suppress("ForbiddenComment")
-class WhiteSpaceRule(configRules: List) : DiktatRule("horizontal-whitespace", configRules, listOf(WRONG_WHITESPACE)) {
+class WhiteSpaceRule(configRules: List) : DiktatRule(
+ "horizontal-whitespace",
+ configRules,
+ listOf(WRONG_WHITESPACE)) {
@Suppress("ComplexMethod")
override fun logic(node: ASTNode) {
when (node.elementType) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt
index 6f5c2880c9..8170e552c3 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt
@@ -37,7 +37,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
* * Only properties without initialization or initialized with expressions based on constants are supported.
* * Properties initialized with constructor calls cannot be distinguished from method call and are no supported.
*/
-class LocalVariablesRule(configRules: List) : DiktatRule("local-variables", configRules, listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) {
+class LocalVariablesRule(configRules: List) : DiktatRule(
+ "local-variables",
+ configRules,
+ listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) {
override fun logic(node: ASTNode) {
if (node.elementType == FILE) {
// collect all local properties and associate with corresponding references
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt
index 1c1c41889b..520772ed87 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt
@@ -19,7 +19,10 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
* because `var` variables can be reassigned several times in the business logic. Of course, in some scenarios with loops or accumulators only `var`s can be used and are allowed.
* FixMe: here we should also raise warnings for a reassignment of a var (if var has no assignments except in declaration - it can be final)
*/
-class ImmutableValNoVarRule(configRules: List) : DiktatRule("no-var-rule", configRules, listOf(SAY_NO_TO_VAR)) {
+class ImmutableValNoVarRule(configRules: List) : DiktatRule(
+ "no-var-rule",
+ configRules,
+ listOf(SAY_NO_TO_VAR)) {
override fun logic(node: ASTNode) {
if (node.elementType == ElementType.FILE) {
// we will raise warning for cases when var property has no assignments
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt
index 366cff96d0..51ce63c06d 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt
@@ -26,7 +26,10 @@ import org.jetbrains.kotlin.psi.KtIfExpression
* This rule check and fixes explicit null checks (explicit comparison with `null`)
* There are several code-structures that can be used in Kotlin to avoid null-checks. For example: `?:`, `.let {}`, `.also {}`, e.t.c
*/
-class NullChecksRule(configRules: List) : DiktatRule("null-checks", configRules, listOf(AVOID_NULL_CHECKS)) {
+class NullChecksRule(configRules: List) : DiktatRule(
+ "null-checks",
+ configRules,
+ listOf(AVOID_NULL_CHECKS)) {
override fun logic(node: ASTNode) {
if (node.elementType == CONDITION) {
node.parent(IF)?.let {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt
index 45bbe16327..e34ceb96cb 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt
@@ -39,7 +39,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
/**
* Rule that detects redundant explicit casts
*/
-class SmartCastRule(configRules: List) : DiktatRule("smart-cast-rule", configRules, listOf(SMART_CAST_NEEDED)) {
+class SmartCastRule(configRules: List) : DiktatRule(
+ "smart-cast-rule",
+ configRules,
+ listOf(SMART_CAST_NEEDED)) {
override fun logic(node: ASTNode) {
if (node.elementType == FILE) {
val usages = collectLocalPropertiesWithUsages(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt
index 41e46615b6..1804b09aa1 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt
@@ -19,7 +19,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
* This rule checks if variable has long type reference and two or more nested generics.
* Length type reference can be configured
*/
-class TypeAliasRule(configRules: List) : DiktatRule("type-alias", configRules, listOf(TYPE_ALIAS)) {
+class TypeAliasRule(configRules: List) : DiktatRule(
+ "type-alias",
+ configRules,
+ listOf(TYPE_ALIAS)) {
override fun logic(node: ASTNode) {
if (node.elementType == TYPE_REFERENCE && node
.parents()
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt
index 07a24644c7..b2027af05c 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt
@@ -21,7 +21,9 @@ import org.jetbrains.kotlin.psi.KtProperty
* Recommended: val myVariable: Map = emptyMap()
*/
// FIXME: we now don't have access to return types, so we can perform this check only if explicit type is present, but should be able also if it's not.
-class VariableGenericTypeDeclarationRule(configRules: List) : DiktatRule("variable-generic-type", configRules,
+class VariableGenericTypeDeclarationRule(configRules: List) : DiktatRule(
+ "variable-generic-type",
+ configRules,
listOf(GENERIC_VARIABLE_WRONG_DECLARATION)) {
override fun logic(node: ASTNode) {
when (node.elementType) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt
index cb40295a68..fb32b85809 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt
@@ -24,7 +24,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
* Exception: allows arithmetic operations only when absolute value of result is immediately used in comparison
* Fixme: detect variables by type, not only floating-point literals
*/
-class AccurateCalculationsRule(configRules: List) : DiktatRule("accurate-calculations", configRules, listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) {
+class AccurateCalculationsRule(configRules: List) : DiktatRule(
+ "accurate-calculations",
+ configRules,
+ listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) {
private fun KtCallExpression?.isAbsOfFloat() = this
?.run {
(calleeExpression as? KtNameReferenceExpression)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt
index 927b6fb637..e79140b160 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt
@@ -17,7 +17,10 @@ import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier
/**
* This rule finds if using runBlocking in asynchronous code
*/
-class AsyncAndSyncRule(configRules: List) : DiktatRule("sync-in-async", configRules, listOf(RUN_BLOCKING_INSIDE_ASYNC)) {
+class AsyncAndSyncRule(configRules: List) : DiktatRule(
+ "sync-in-async",
+ configRules,
+ listOf(RUN_BLOCKING_INSIDE_ASYNC)) {
private val asyncList = listOf("async", "launch")
override fun logic(node: ASTNode) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt
index e597764640..17eff7b2e9 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt
@@ -24,7 +24,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
/**
* This rule checks for nested functions and warns if it finds any.
*/
-class AvoidNestedFunctionsRule(configRules: List) : DiktatRule("avoid-nested-functions", configRules, listOf(AVOID_NESTED_FUNCTIONS)) {
+class AvoidNestedFunctionsRule(configRules: List) : DiktatRule(
+ "avoid-nested-functions",
+ configRules,
+ listOf(AVOID_NESTED_FUNCTIONS)) {
override fun logic(node: ASTNode) {
if (node.elementType == FUN) {
handleNestedFunctions(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt
index 8c92f48a18..c5504798d7 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt
@@ -22,7 +22,10 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
* This rule checks if inverse method can be used.
* For example if there is !isEmpty() on collection call that it changes it to isNotEmpty()
*/
-class CheckInverseMethodRule(configRules: List) : DiktatRule("inverse-method", configRules, listOf(INVERSE_FUNCTION_PREFERRED)) {
+class CheckInverseMethodRule(configRules: List) : DiktatRule(
+ "inverse-method",
+ configRules,
+ listOf(INVERSE_FUNCTION_PREFERRED)) {
override fun logic(node: ASTNode) {
if (node.elementType == CALL_EXPRESSION && node.text in methodMap.keys) {
checkCallExpressionName(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt
index 518040b1b3..2359b3a8aa 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt
@@ -17,7 +17,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
/**
* Rule that checks using custom label
*/
-class CustomLabel(configRules: List) : DiktatRule("custom-label", configRules, listOf(CUSTOM_LABEL)) {
+class CustomLabel(configRules: List) : DiktatRule(
+ "custom-label",
+ configRules,
+ listOf(CUSTOM_LABEL)) {
private val forEachReference = listOf("forEach", "forEachIndexed")
private val labels = listOf("@loop", "@forEach", "@forEachIndexed")
private val stopWords = listOf(RETURN, BREAK, CONTINUE)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt
index 5f07f8a9f2..a5ee1f9045 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt
@@ -14,7 +14,10 @@ import org.jetbrains.kotlin.psi.KtFunction
/**
* Rule that checks that function doesn't contains too many parameters
*/
-class FunctionArgumentsSize(configRules: List) : DiktatRule("argument-size", configRules, listOf(TOO_MANY_PARAMETERS)) {
+class FunctionArgumentsSize(configRules: List) : DiktatRule(
+ "argument-size",
+ configRules,
+ listOf(TOO_MANY_PARAMETERS)) {
private val configuration: FunctionArgumentsSizeConfiguration by lazy {
FunctionArgumentsSizeConfiguration(configRules.getRuleConfig(TOO_MANY_PARAMETERS)?.configuration ?: emptyMap())
}
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt
index 670fef2377..22de1d88a6 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt
@@ -14,7 +14,10 @@ import org.jetbrains.kotlin.psi.KtFunction
/**
* Rule 5.1.1 check function length
*/
-class FunctionLength(configRules: List) : DiktatRule("function-length", configRules, listOf(TOO_LONG_FUNCTION)) {
+class FunctionLength(configRules: List) : DiktatRule(
+ "function-length",
+ configRules,
+ listOf(TOO_LONG_FUNCTION)) {
override fun logic(node: ASTNode) {
val configuration = FunctionLengthConfiguration(
configRules.getRuleConfig(TOO_LONG_FUNCTION)?.configuration ?: emptyMap()
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt
index f231535a74..77fe03e357 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt
@@ -13,7 +13,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
/**
* Rule 5.2.5 check lambda length without parameters
*/
-class LambdaLengthRule(configRules: List) : DiktatRule("lambda-length", configRules, listOf(TOO_MANY_LINES_IN_LAMBDA)) {
+class LambdaLengthRule(configRules: List) : DiktatRule(
+ "lambda-length",
+ configRules,
+ listOf(TOO_MANY_LINES_IN_LAMBDA)) {
private val configuration by lazy {
LambdaLengthConfiguration(
this.configRules.getRuleConfig(TOO_MANY_LINES_IN_LAMBDA)?.configuration ?: emptyMap()
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt
index 28bf1a9082..efa7d4fae2 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt
@@ -15,7 +15,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
/**
* Rule that checks if parameter with function type is the last in parameter list
*/
-class LambdaParameterOrder(configRules: List) : DiktatRule("lambda-parameter-order", configRules, listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) {
+class LambdaParameterOrder(configRules: List) : DiktatRule(
+ "lambda-parameter-order",
+ configRules,
+ listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) {
override fun logic(node: ASTNode) {
if (node.elementType == ElementType.FUN) {
checkArguments(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt
index dc537c668a..66cbf9bd5a 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt
@@ -20,7 +20,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
/**
* Rule 5.1.2 Nested blokcs
*/
-class NestedFunctionBlock(configRules: List) : DiktatRule("nested-block", configRules, listOf(NESTED_BLOCK)) {
+class NestedFunctionBlock(configRules: List) : DiktatRule(
+ "nested-block",
+ configRules,
+ listOf(NESTED_BLOCK)) {
private val configuration: NestedBlockConfiguration by lazy {
NestedBlockConfiguration(configRules.getRuleConfig(NESTED_BLOCK)?.configuration ?: emptyMap())
}
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt
index 632db0609e..9c67a1b7fe 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt
@@ -17,7 +17,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
/**
* Rule that suggests to use functions with default parameters instead of multiple overloads
*/
-class OverloadingArgumentsFunction(configRules: List) : DiktatRule("overloading-default-values", configRules,
+class OverloadingArgumentsFunction(configRules: List) : DiktatRule(
+ "overloading-default-values",
+ configRules,
listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS)) {
override fun logic(node: ASTNode) {
if (node.elementType == FUN) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt
index d90f3ae304..d5a500660f 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt
@@ -11,7 +11,10 @@ import org.jetbrains.kotlin.psi.KtClass
/**
* This rule checks if a class has an empty primary constructor.
*/
-class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule("avoid-empty-primary-constructor", configRules, listOf(EMPTY_PRIMARY_CONSTRUCTOR)) {
+class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule(
+ "avoid-empty-primary-constructor",
+ configRules,
+ listOf(EMPTY_PRIMARY_CONSTRUCTOR)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS) {
checkClass(node.psi as KtClass)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt
index 79635772ae..9144aac9d5 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt
@@ -24,9 +24,12 @@ import org.jetbrains.kotlin.psi.psiUtil.children
/**
* Rule 6.4.1 checks that class/object, with a word "util" in its name, has only functions.
*/
-class AvoidUtilityClass(configRules: List) : DiktatRule("avoid-utility-class", configRules, listOf(AVOID_USING_UTILITY_CLASS)) {
+class AvoidUtilityClass(configRules: List) : DiktatRule(
+ "avoid-utility-class",
+ configRules,
+ listOf(AVOID_USING_UTILITY_CLASS)) {
override fun logic(node: ASTNode) {
- val config by configRules.getCommonConfiguration()
+ val config = configRules.getCommonConfiguration()
val filePath = node.getRootNode().getFilePath()
if (!(node.hasTestAnnotation() || isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors))) {
if (node.elementType == OBJECT_DECLARATION || node.elementType == CLASS) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt
index 9002f51737..647ef47b84 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt
@@ -15,7 +15,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
/**
* Inspection that checks that no custom getters and setters are used for properties.
*/
-class CustomGetterSetterRule(configRules: List) : DiktatRule("custom-getter-setter", configRules, listOf(CUSTOM_GETTERS_SETTERS)) {
+class CustomGetterSetterRule(configRules: List) : DiktatRule(
+ "custom-getter-setter",
+ configRules,
+ listOf(CUSTOM_GETTERS_SETTERS)) {
override fun logic(node: ASTNode) {
if (node.elementType == PROPERTY_ACCESSOR) {
checkForCustomGetersSetters(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt
index e3a66b4389..09cae45047 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt
@@ -20,7 +20,9 @@ import org.jetbrains.kotlin.psi.KtFunction
/**
* This rule checks if there are any extension functions for the class in the same file, where it is defined
*/
-class ExtensionFunctionsInFileRule(configRules: List) : DiktatRule("extension-functions-class-file", configRules,
+class ExtensionFunctionsInFileRule(configRules: List) : DiktatRule(
+ "extension-functions-class-file",
+ configRules,
listOf(EXTENSION_FUNCTION_WITH_CLASS)) {
override fun logic(node: ASTNode) {
if (node.elementType == ElementType.FILE) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt
index 58e4ea2f72..2f37ae2de6 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt
@@ -32,7 +32,9 @@ internal typealias SimilarSignatures = List) : DiktatRule("extension-functions-same-name", configRules,
+class ExtensionFunctionsSameNameRule(configRules: List) : DiktatRule(
+ "extension-functions-same-name",
+ configRules,
listOf(EXTENSION_FUNCTION_SAME_SIGNATURE)) {
override fun logic(node: ASTNode) {
/**
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt
index be46671279..23116a6607 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt
@@ -24,7 +24,9 @@ import org.jetbrains.kotlin.psi.KtProperty
/**
* This rule checks if there is a backing property for field with property accessors, in case they don't use field keyword
*/
-class ImplicitBackingPropertyRule(configRules: List) : DiktatRule("implicit-backing-property", configRules,
+class ImplicitBackingPropertyRule(configRules: List) : DiktatRule(
+ "implicit-backing-property",
+ configRules,
listOf(NO_CORRESPONDING_PROPERTY)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS_BODY) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt
index cdd75f4376..10d05e6136 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt
@@ -20,7 +20,10 @@ import org.jetbrains.kotlin.psi.KtProperty
/**
* Rule check that never use the name of a variable in the custom getter or setter
*/
-class PropertyAccessorFields(configRules: List) : DiktatRule("getter-setter-fields", configRules, listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) {
+class PropertyAccessorFields(configRules: List) : DiktatRule(
+ "getter-setter-fields",
+ configRules,
+ listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) {
override fun logic(node: ASTNode) {
if (node.elementType == PROPERTY_ACCESSOR) {
checkPropertyAccessor(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt
index c2c821a9c1..899f71f390 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt
@@ -26,7 +26,9 @@ import org.jetbrains.kotlin.psi.KtPropertyAccessor
/**
* This rule checks if there are any trivial getters and setters and, if so, deletes them
*/
-class TrivialPropertyAccessors(configRules: List) : DiktatRule("trivial-property-accessors", configRules,
+class TrivialPropertyAccessors(configRules: List) : DiktatRule(
+ "trivial-property-accessors",
+ configRules,
listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED)) {
override fun logic(node: ASTNode) {
if (node.elementType == PROPERTY_ACCESSOR) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt
index c740b623aa..9b63c527fb 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt
@@ -31,7 +31,10 @@ import java.util.HashMap
* Explicit supertype qualification should not be used if there is not clash between called methods
* fixme can't fix supertypes that are defined in other files.
*/
-class UselessSupertype(configRules: List) : DiktatRule("useless-override", configRules, listOf(USELESS_SUPERTYPE)) {
+class UselessSupertype(configRules: List) : DiktatRule(
+ "useless-override",
+ configRules,
+ listOf(USELESS_SUPERTYPE)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS) {
checkClass(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt
index 4755f42b55..66b9fcc8c6 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt
@@ -19,7 +19,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
/**
* Checks if abstract class has any abstract method. If not, warns that class should not be abstract
*/
-class AbstractClassesRule(configRules: List) : DiktatRule("abstract-classes", configRules, listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) {
+class AbstractClassesRule(configRules: List) : DiktatRule(
+ "abstract-classes",
+ configRules,
+ listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS) {
val classBody = node.getFirstChildWithType(CLASS_BODY) ?: return
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt
index 807459f103..f9dfcf8b9c 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt
@@ -27,7 +27,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
* FixMe: When assigned variable's name is also a `this@apply`'s property, it should be changed to qualified name,
* e.g `this@Foo`. But for this we need a mechanism to determine declaration scope and it's label.
*/
-class CompactInitialization(configRules: List) : DiktatRule("class-compact-initialization", configRules, listOf(COMPACT_OBJECT_INITIALIZATION)) {
+class CompactInitialization(configRules: List) : DiktatRule(
+ "class-compact-initialization",
+ configRules,
+ listOf(COMPACT_OBJECT_INITIALIZATION)) {
private val kotlinParser by lazy { KotlinParser() }
override fun logic(node: ASTNode) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt
index f89eb1239b..0080391d0e 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt
@@ -3,14 +3,13 @@ package org.cqfn.diktat.ruleset.rules.chapter6.classes
import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.ruleset.constants.Warnings.USE_DATA_CLASS
import org.cqfn.diktat.ruleset.rules.DiktatRule
-import org.cqfn.diktat.ruleset.utils.getAllChildrenWithType
-import org.cqfn.diktat.ruleset.utils.getFirstChildWithType
-import org.cqfn.diktat.ruleset.utils.hasChildOfType
+import org.cqfn.diktat.ruleset.utils.*
import com.pinterest.ktlint.core.ast.ElementType.ABSTRACT_KEYWORD
import com.pinterest.ktlint.core.ast.ElementType.BLOCK
import com.pinterest.ktlint.core.ast.ElementType.CLASS
import com.pinterest.ktlint.core.ast.ElementType.CLASS_BODY
+import com.pinterest.ktlint.core.ast.ElementType.CLASS_INITIALIZER
import com.pinterest.ktlint.core.ast.ElementType.DATA_KEYWORD
import com.pinterest.ktlint.core.ast.ElementType.ENUM_KEYWORD
import com.pinterest.ktlint.core.ast.ElementType.FUN
@@ -20,6 +19,7 @@ import com.pinterest.ktlint.core.ast.ElementType.OPEN_KEYWORD
import com.pinterest.ktlint.core.ast.ElementType.PRIMARY_CONSTRUCTOR
import com.pinterest.ktlint.core.ast.ElementType.PROPERTY
import com.pinterest.ktlint.core.ast.ElementType.PROPERTY_ACCESSOR
+import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.SEALED_KEYWORD
import com.pinterest.ktlint.core.ast.ElementType.SUPER_TYPE_LIST
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
@@ -31,7 +31,10 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor
/**
* This rule checks if class can be made as data class
*/
-class DataClassesRule(configRules: List) : DiktatRule("data-classes", configRules, listOf(USE_DATA_CLASS)) {
+class DataClassesRule(configRules: List) : DiktatRule(
+ "data-classes",
+ configRules,
+ listOf(USE_DATA_CLASS)) {
override fun logic(node: ASTNode) {
if (node.elementType == CLASS) {
handleClass(node)
@@ -53,18 +56,43 @@ class DataClassesRule(configRules: List) : DiktatRule("data-classes
USE_DATA_CLASS.warn(configRules, emitWarn, isFixMode, "${(node.psi as KtClass).name}", node.startOffset, node)
}
- @Suppress("UnsafeCallOnNullableType", "FUNCTION_BOOLEAN_PREFIX", "ComplexMethod")
+ @Suppress(
+ "UnsafeCallOnNullableType",
+ "FUNCTION_BOOLEAN_PREFIX",
+ "ComplexMethod"
+ )
private fun ASTNode.canBeDataClass(): Boolean {
val isNotPropertyInClassBody = findChildByType(CLASS_BODY)?.let { (it.psi as KtClassBody).properties.isEmpty() } ?: true
+ val constructorParametersNames: MutableList = mutableListOf()
val hasPropertyInConstructor = findChildByType(PRIMARY_CONSTRUCTOR)
?.let { constructor ->
(constructor.psi as KtPrimaryConstructor)
.valueParameters
+ .onEach {
+ if (!it.hasValOrVar()) {
+ constructorParametersNames.add(it.name!!)
+ }
+ }
.run { isNotEmpty() && all { it.hasValOrVar() } }
} ?: false
if (isNotPropertyInClassBody && !hasPropertyInConstructor) {
return false
}
+ // if parameter of the primary constructor is used in init block then it is hard to refactor this class to data class
+ if (constructorParametersNames.isNotEmpty()) {
+ val initBlocks = findChildByType(CLASS_BODY)?.getAllChildrenWithType(CLASS_INITIALIZER)
+ initBlocks?.forEach { init ->
+ val refExpressions = init.findAllNodesWithSpecificType(REFERENCE_EXPRESSION)
+ if (refExpressions.any { it.text in constructorParametersNames }) {
+ return false
+ }
+ }
+ }
+ return hasAppropriateClassBody()
+ }
+
+ @Suppress("UnsafeCallOnNullableType")
+ private fun ASTNode.hasAppropriateClassBody(): Boolean {
val classBody = getFirstChildWithType(CLASS_BODY)
if (hasChildOfType(MODIFIER_LIST)) {
val list = getFirstChildWithType(MODIFIER_LIST)!!
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt
index 1665c8481e..7b42eba4a4 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt
@@ -25,9 +25,12 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
/**
* This rule checks if inline class can be used.
*/
-class InlineClassesRule(configRules: List) : DiktatRule("inline-classes", configRules, listOf(INLINE_CLASS_CAN_BE_USED)) {
+class InlineClassesRule(configRules: List) : DiktatRule(
+ "inline-classes",
+ configRules,
+ listOf(INLINE_CLASS_CAN_BE_USED)) {
override fun logic(node: ASTNode) {
- val configuration by configRules.getCommonConfiguration()
+ val configuration = configRules.getCommonConfiguration()
if (node.elementType == CLASS && configuration.kotlinVersion >= ktVersion) {
handleClasses(node.psi as KtClass)
}
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt
index 802c2fde9c..6924e6a508 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt
@@ -33,7 +33,10 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
* This rule ensures that if a class has a single constructor, this constructor is primary.
* Secondary constructor is converted into primary, statements that are not assignments are moved into an `init` block.
*/
-class SingleConstructorRule(configRules: List) : DiktatRule("single-constructor", configRules, listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) {
+class SingleConstructorRule(configRules: List) : DiktatRule(
+ "single-constructor",
+ configRules,
+ listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) {
private val kotlinParser by lazy { KotlinParser() }
override fun logic(node: ASTNode) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt
index eaa56a3620..8e0fbf7649 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt
@@ -25,7 +25,10 @@ import org.jetbrains.kotlin.psi.psiUtil.children
/**
* The rule that checks whether a class has a single `init` block or multiple. Having multiple `init` blocks is a bad practice.
*/
-class SingleInitRule(configRules: List) : DiktatRule("multiple-init-block", configRules, listOf(MULTIPLE_INIT_BLOCKS)) {
+class SingleInitRule(configRules: List) : DiktatRule(
+ "multiple-init-block",
+ configRules,
+ listOf(MULTIPLE_INIT_BLOCKS)) {
override fun logic(node: ASTNode) {
when (node.elementType) {
CLASS_BODY -> handleInitBlocks(node)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt
index 7ed2903736..3512aaa33e 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt
@@ -27,7 +27,10 @@ import org.jetbrains.kotlin.psi.KtClass
/**
* This rule checks if class is stateless and if so changes it to object.
*/
-class StatelessClassesRule(configRules: List) : DiktatRule("stateless-class", configRules, listOf(OBJECT_IS_PREFERRED)) {
+class StatelessClassesRule(configRules: List) : DiktatRule(
+ "stateless-class",
+ configRules,
+ listOf(OBJECT_IS_PREFERRED)) {
override fun logic(node: ASTNode) {
// Fixme: We should find interfaces in all project and then check them
if (node.elementType == FILE) {
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
index 8352db3b0f..a7a52b8a82 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
@@ -3,7 +3,11 @@
* FixMe: fix suppressed inspections on KDocs
*/
-@file:Suppress("FILE_NAME_MATCH_CLASS", "KDOC_WITHOUT_RETURN_TAG", "KDOC_WITHOUT_PARAM_TAG")
+@file:Suppress(
+ "FILE_NAME_MATCH_CLASS",
+ "KDOC_WITHOUT_RETURN_TAG",
+ "KDOC_WITHOUT_PARAM_TAG"
+)
package org.cqfn.diktat.ruleset.utils
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt
index d5e0cbc0a6..3a994703f7 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt
@@ -89,7 +89,11 @@ class KotlinParser {
* Else, try to create node based on text.
* If this node will contain ERROR_ELEMENT type children this mean that cannot create node based on this text
*/
- @Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION", "SAY_NO_TO_VAR")
+ @Suppress(
+ "UnsafeCallOnNullableType",
+ "TOO_LONG_FUNCTION",
+ "SAY_NO_TO_VAR"
+ )
private fun makeNode(text: String, isPackage: Boolean = false): ASTNode? {
if (text.isEmpty()) {
return null
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/PositionInTextLocator.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/PositionInTextLocator.kt
index cb7906d23d..28d8fd2874 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/PositionInTextLocator.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/PositionInTextLocator.kt
@@ -7,7 +7,11 @@ package org.cqfn.diktat.ruleset.utils
internal typealias LineAndColumn = Pair
-@Suppress("MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", "KDOC_WITHOUT_RETURN_TAG")
+@Suppress(
+ "MISSING_KDOC_ON_FUNCTION",
+ "KDOC_WITHOUT_PARAM_TAG",
+ "KDOC_WITHOUT_RETURN_TAG"
+)
private class SegmentTree(sortedArray: IntArray) {
private val segments: List = sortedArray
.dropLast(1)
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt
index fbc1789e8d..86985471e4 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt
@@ -1,4 +1,8 @@
-@file:Suppress("KDOC_NO_CONSTRUCTOR_PROPERTY", "MISSING_KDOC_CLASS_ELEMENTS", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG",
+@file:Suppress(
+ "KDOC_NO_CONSTRUCTOR_PROPERTY",
+ "MISSING_KDOC_CLASS_ELEMENTS",
+ "MISSING_KDOC_ON_FUNCTION",
+ "KDOC_WITHOUT_PARAM_TAG",
"KDOC_WITHOUT_RETURN_TAG")
package org.cqfn.diktat.ruleset.utils.search
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithAssignmentSearch.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithAssignmentSearch.kt
index bc9ec08ce3..4cdf7e7f3f 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithAssignmentSearch.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithAssignmentSearch.kt
@@ -1,5 +1,12 @@
-@file:Suppress("MISSING_KDOC_TOP_LEVEL", "KDOC_NO_CONSTRUCTOR_PROPERTY", "MISSING_KDOC_CLASS_ELEMENTS", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG",
- "KDOC_WITHOUT_RETURN_TAG", "KDOC_NO_EMPTY_TAGS")
+@file:Suppress(
+ "MISSING_KDOC_TOP_LEVEL",
+ "KDOC_NO_CONSTRUCTOR_PROPERTY",
+ "MISSING_KDOC_CLASS_ELEMENTS",
+ "MISSING_KDOC_ON_FUNCTION",
+ "KDOC_WITHOUT_PARAM_TAG",
+ "KDOC_WITHOUT_RETURN_TAG",
+ "KDOC_NO_EMPTY_TAGS"
+)
package org.cqfn.diktat.ruleset.utils.search
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithUsagesSearch.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithUsagesSearch.kt
index c18d7e115f..ccea032ad0 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithUsagesSearch.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithUsagesSearch.kt
@@ -1,5 +1,12 @@
-@file:Suppress("MISSING_KDOC_TOP_LEVEL", "KDOC_NO_CONSTRUCTOR_PROPERTY", "MISSING_KDOC_CLASS_ELEMENTS", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG",
- "KDOC_WITHOUT_RETURN_TAG", "KDOC_NO_EMPTY_TAGS")
+@file:Suppress(
+ "MISSING_KDOC_TOP_LEVEL",
+ "KDOC_NO_CONSTRUCTOR_PROPERTY",
+ "MISSING_KDOC_CLASS_ELEMENTS",
+ "MISSING_KDOC_ON_FUNCTION",
+ "KDOC_WITHOUT_PARAM_TAG",
+ "KDOC_WITHOUT_RETURN_TAG",
+ "KDOC_NO_EMPTY_TAGS"
+)
package org.cqfn.diktat.ruleset.utils.search
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt
index ea4e5b813d..22ff9a0a90 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt
@@ -122,7 +122,11 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) {
}
@Test
- @Tags(Tag(WarningNames.CLASS_NAME_INCORRECT), Tag(WarningNames.VARIABLE_NAME_INCORRECT_FORMAT), Tag(WarningNames.CONSTANT_UPPERCASE))
+ @Tags(
+ Tag(WarningNames.CLASS_NAME_INCORRECT),
+ Tag(WarningNames.VARIABLE_NAME_INCORRECT_FORMAT),
+ Tag(WarningNames.CONSTANT_UPPERCASE)
+ )
fun `check identifiers case format (check - negative)`() {
val code =
"""
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt
index 43150abcfe..53d0f3a217 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt
@@ -19,7 +19,12 @@ class CommentsFormattingFixTest : FixTestBase("test/paragraph2/kdoc/", ::Comment
}
@Test
- @Tags(Tag(WRONG_NEWLINES_AROUND_KDOC), Tag(COMMENT_WHITE_SPACE), Tag(IF_ELSE_COMMENTS), Tag(FIRST_COMMENT_NO_BLANK_LINE))
+ @Tags(
+ Tag(WRONG_NEWLINES_AROUND_KDOC),
+ Tag(COMMENT_WHITE_SPACE),
+ Tag(IF_ELSE_COMMENTS),
+ Tag(FIRST_COMMENT_NO_BLANK_LINE)
+ )
fun `check lines and spaces in comments`() {
fixAndCompare("KdocCodeBlocksFormattingExpected.kt", "KdocCodeBlocksFormattingTest.kt")
}
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsFixTest.kt
index 440f5cdfdb..ae8a5074c9 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsFixTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsFixTest.kt
@@ -47,7 +47,11 @@ class KdocMethodsFixTest : FixTestBase("test/paragraph2/kdoc/package/src/main/ko
}
@Test
- @Tags(Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG))
+ @Tags(
+ Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG),
+ Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG),
+ Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG)
+ )
fun `KdocMethods rule should reformat code (full example)`() {
fixAndCompare("KdocMethodsFullExpected.kt", "KdocMethodsFullTested.kt")
}
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt
index 0e3b8fa47d..9002b23029 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt
@@ -27,7 +27,11 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) {
""".trimIndent()
@Test
- @Tags(Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG))
+ @Tags(
+ Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG),
+ Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG),
+ Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG)
+ )
fun `Accessible methods with parameters, return type and throws should have proper KDoc (positive example)`() {
val validCode = """
/**
@@ -51,8 +55,12 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) {
}
@Test
- @Tags(Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG),
- Tag(WarningNames.MISSING_KDOC_ON_FUNCTION))
+ @Tags(
+ Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG),
+ Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG),
+ Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG),
+ Tag(WarningNames.MISSING_KDOC_ON_FUNCTION)
+ )
fun `Warning should not be triggered for functions in tests`() {
val validCode = "@Test $funCode"
val complexAnnotationCode = "@Anno(test = [\"args\"]) $funCode"
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/FileStructureRuleTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/FileStructureRuleTest.kt
index 4d9a90d103..9ac9122706 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/FileStructureRuleTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/FileStructureRuleTest.kt
@@ -327,4 +327,71 @@ class FileStructureRuleTest : LintTestBase(::FileStructureRule) {
""".trimMargin(),
)
}
+
+ @Test
+ @Tag(WarningNames.UNUSED_IMPORT)
+ fun `Should correctly check infix functions`() {
+ lintMethod(
+ """
+ |package org.cqfn.diktat.example
+ |
+ |import org.cqfn.diktat.utils.logAndExit
+ |
+ |fun main() {
+ |"Type is not supported yet" logAndExit 1
+ |}
+ """.trimMargin(),
+ )
+ }
+
+ @Test
+ @Tag(WarningNames.UNUSED_IMPORT)
+ fun `unused import to infix functions`() {
+ lintMethod(
+ """
+ |package org.cqfn.diktat.example
+ |
+ |import org.cqfn.diktat.utils.logAndExit
+ |
+ |fun main() {
+ |println("Type is not supported yet")
+ |}
+ """.trimMargin(),
+ LintError(1, 1, ruleId, "${Warnings.UNUSED_IMPORT.warnText()} org.cqfn.diktat.utils.logAndExit - unused import", true)
+ )
+ }
+
+ @Test
+ @Tag(WarningNames.UNUSED_IMPORT)
+ fun `Acute`() {
+ lintMethod(
+ """
+ |package org.cqfn.diktat.example
+ |
+ |import js.externals.jquery.`${'$'}`
+ |
+ |fun main() {
+ | `${'$'}`("document").ready {}
+ |}
+ """.trimMargin(),
+ )
+ }
+
+ @Test
+ @Tag(WarningNames.UNUSED_IMPORT)
+ fun `Ignore Imports`() {
+ lintMethod(
+ """
+ |package org.cqfn.diktat.example
+ |
+ |import com.example.get
+ |import com.example.invoke
+ |import com.example.set
+ |
+ |fun main() {
+ | val a = list[1]
+ |}
+ """.trimMargin(),
+ )
+ }
}
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt
index 61dc547f73..06973b02e1 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt
@@ -614,7 +614,10 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) {
LintError(3, 10, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of ", true),
LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} first parameter should be placed on a separate line or all other parameters " +
"should be aligned with it in declaration of ", true),
- LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of ", true)
+ LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of ", true),
+ LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (arg1) should be placed on the new line or " +
+ "all other parameters should be aligned with it", true),
+ LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} value arguments should be placed on different lines", true)
)
}
@@ -643,6 +646,49 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) {
)
}
+ @Test
+ @Tag(WarningNames.WRONG_NEWLINES)
+ fun `should not raise warning on value arguments`() {
+ lintMethod(
+ """
+ |class SomeRule(configRules: List) : Rule("id",
+ |configRules,
+ |listOf("foo", "baz")) {
+ |
+ |}
+ """.trimMargin()
+ )
+ }
+
+ @Test
+ @Tag(WarningNames.WRONG_NEWLINES)
+ fun `should not raise warning on list params`() {
+ lintMethod(
+ """
+ |class SomeRule(configRules: List) : Rule("id",
+ |configRules,
+ |listOf("foo", "baz", "triple", "bar")) {
+ |
+ |}
+ """.trimMargin()
+ )
+ }
+
+ @Test
+ @Tag(WarningNames.WRONG_NEWLINES)
+ fun `should raise warning on value arguments`() {
+ lintMethod(
+ """
+ |class SomeRule(configRules: List) : Rule("id", configRules, listOf("foo", "baz")) {
+ |
+ |}
+ """.trimMargin(),
+ LintError(1, 46, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (\"id\") should be placed on the new line or " +
+ "all other parameters should be aligned with it", true),
+ LintError(1, 46, ruleId, "${WRONG_NEWLINES.warnText()} value arguments should be placed on different lines", true),
+ )
+ }
+
@Test
@Tag(WarningNames.WRONG_NEWLINES)
fun `should suggest newlines in a long supertype list`() {
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt
index f25d4b2f99..e9638b1656 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt
@@ -143,9 +143,136 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) {
| val q = 10
| fun foo() = 10
|}
- """.trimMargin(),
+ """.trimMargin(),
LintError(1, 1, ruleId, "${Warnings.USE_DATA_CLASS.warnText()} B"),
LintError(5, 1, ruleId, "${Warnings.USE_DATA_CLASS.warnText()} Ab")
)
}
+
+ @Test
+ @Tag(USE_DATA_CLASS)
+ fun `shouldn't trigger on class with init block`() {
+ lintMethod(
+ """
+ |class Credentials(auth: String) {
+ | val gitHubUserName: String
+ | val gitHubAuthToken: String
+ |
+ | init {
+ | auth.let {
+ |
+ | }
+ | }
+ |}
+ """.trimMargin()
+ )
+ }
+
+ @Test
+ @Tag(USE_DATA_CLASS)
+ fun `should not trigger on init block with if`() {
+ lintMethod(
+ """
+ |class Credentials(auth: String, second: Int?, third: Double) {
+ | val gitHubUserName: String
+ | val gitHubAuthToken: String
+ |
+ | init {
+ | if (second != null) {
+ | }
+ | }
+ |}
+ """.trimMargin()
+ )
+ }
+
+ @Test
+ @Tag(USE_DATA_CLASS)
+ fun `should not trigger on init block with function call`() {
+ lintMethod(
+ """
+ |class Credentials(auth: String, second: Int?, third: Double) {
+ | val gitHubUserName: String
+ | val gitHubAuthToken: String
+ |
+ | init {
+ | foo(third)
+ | }
+ |}
+ """.trimMargin()
+ )
+ }
+
+ @Test
+ @Tag(USE_DATA_CLASS)
+ fun `should not trigger on class with several parameters`() {
+ lintMethod(
+ """
+ |class Credentials(auth: String, second: Int?, third: Double) {
+ | val gitHubUserName: String
+ | val gitHubAuthToken: String
+ |
+ | init {
+ | auth.let {
+ |
+ | }
+ |
+ | if (second != null) {
+ | }
+ |
+ | foo(third)
+ | }
+ |}
+ """.trimMargin()
+ )
+ }
+
+ @Test
+ @Tag(USE_DATA_CLASS)
+ fun `should trigger on class with parameter in constructor`() {
+ lintMethod(
+ """
+ |class Credentials(auth: String) {
+ | val gitHubUserName: String = auth.toUpperCase()
+ | val gitHubAuthToken: String = auth.toLowerCase()
+ |}
+ """.trimMargin(),
+ LintError(1, 1, ruleId, "${Warnings.USE_DATA_CLASS.warnText()} Credentials")
+ )
+ }
+
+ @Test
+ @Tag(USE_DATA_CLASS)
+ fun `should trigger on class with parameter in constructor and init block`() {
+ lintMethod(
+ """
+ |class Credentials(auth: String) {
+ | val gitHubUserName: String = auth.toUpperCase()
+ | val gitHubAuthToken: String = auth.toLowerCase()
+ |
+ | init {
+ | // some logic
+ | }
+ |}
+ """.trimMargin(),
+ LintError(1, 1, ruleId, "${Warnings.USE_DATA_CLASS.warnText()} Credentials")
+ )
+ }
+
+ @Test
+ @Tag(USE_DATA_CLASS)
+ fun `should not trigger on init block with one ref expression`() {
+ lintMethod(
+ """
+ |class Credentials(auth: String, some: Int?) {
+ | val gitHubUserName: String = auth.toUpperCase()
+ | val gitHubAuthToken: String = auth.toLowerCase()
+ |
+ | init {
+ | val a = auth
+ | }
+ |}
+ """.trimMargin()
+ )
+ }
}
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt
index 0f49f436c8..c1c7089986 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt
@@ -1,4 +1,8 @@
-@file:Suppress("HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE", "LOCAL_VARIABLE_EARLY_DECLARATION", "AVOID_NULL_CHECKS")
+@file:Suppress(
+ "HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE",
+ "LOCAL_VARIABLE_EARLY_DECLARATION",
+ "AVOID_NULL_CHECKS"
+)
package org.cqfn.diktat.ruleset.utils
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt
index ff1ab3e719..284b7de51a 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt
@@ -96,7 +96,11 @@ class KotlinParserTest {
}
@Test
- @Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION", "AVOID_NULL_CHECKS")
+ @Suppress(
+ "UnsafeCallOnNullableType",
+ "TOO_LONG_FUNCTION",
+ "AVOID_NULL_CHECKS"
+ )
fun `test multiline class code compare with applyToCode`() {
val emptyClass = """
|package org.cqfn.diktat.ruleset.utils
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt
index daf3fa71f1..94ad54041d 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt
@@ -22,7 +22,8 @@ open class FixTestBase(protected val resourceFilePath: String,
ruleSupplier: (rulesConfigList: List) -> Rule,
rulesConfigList: List? = null,
cb: LintErrorCallback = defaultCallback) : this(
- resourceFilePath, { overrideRulesConfigList -> DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList) },
+ resourceFilePath,
+ { overrideRulesConfigList -> DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList) },
cb,
rulesConfigList
)
diff --git a/diktat-rules/src/test/resources/test/paragraph3/newlines/ParameterListExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/newlines/ParameterListExpected.kt
index c18ac4bf33..cdcff7da86 100644
--- a/diktat-rules/src/test/resources/test/paragraph3/newlines/ParameterListExpected.kt
+++ b/diktat-rules/src/test/resources/test/paragraph3/newlines/ParameterListExpected.kt
@@ -18,7 +18,10 @@ val arg1: Int,
constructor(
arg1: Int,
arg2: String,
- arg3: String) : this(arg1, 0, 0) { }
+ arg3: String) : this(
+arg1,
+ 0,
+ 0) { }
}
class Foo(val arg1: Int,
diff --git a/diktat-rules/src/test/resources/test/paragraph3/sort_error/ConstantsExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/sort_error/ConstantsExpected.kt
index ba8d1eedb5..c10d078c44 100644
--- a/diktat-rules/src/test/resources/test/paragraph3/sort_error/ConstantsExpected.kt
+++ b/diktat-rules/src/test/resources/test/paragraph3/sort_error/ConstantsExpected.kt
@@ -3,8 +3,8 @@ package test.paragraph3.sort_error
class Test {
companion object {
private const val B = 4
-private const val C = 4
-private const val D = 4
+ private const val C = 4
+ private const val D = 4
private val SIMPLE_VALUE = listOf(IDENTIFIER, WHITE_SPACE, COMMA, SEMICOLON)
}
}
@@ -28,7 +28,7 @@ class Test2 {
private const val D = 4
private val SIMPLE_VALUE = listOf(IDENTIFIER, WHITE_SPACE, COMMA, SEMICOLON)
private const val Ba = 4
-private const val Baa = 4
-private const val Bb = 4
+ private const val Baa = 4
+ private const val Bb = 4
}
}
diff --git a/diktat-rules/src/test/resources/test/paragraph3/sort_error/EnumSortExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/sort_error/EnumSortExpected.kt
index 348610a1a6..e48588d699 100644
--- a/diktat-rules/src/test/resources/test/paragraph3/sort_error/EnumSortExpected.kt
+++ b/diktat-rules/src/test/resources/test/paragraph3/sort_error/EnumSortExpected.kt
@@ -2,8 +2,8 @@ package test.paragraph3.sort_error
enum class Alp {
BLUE(0x0000FF),
-GREEN(0x00FF00),
-RED(0xFF0000),
+ GREEN(0x00FF00),
+ RED(0xFF0000),
;
}
@@ -11,7 +11,7 @@ enum class Warnings {
TALKING {
override fun signal() = TALKING
},
-WAITING {
+ WAITING {
override fun signal() = TALKING
},
;
@@ -23,7 +23,7 @@ enum class Warnings {
TALKING {
override fun signal() = TALKING
},
-WAITING {
+ WAITING {
override fun signal() = TALKING
};
@@ -32,13 +32,33 @@ WAITING {
enum class Alp {
BLUE(0x0000FF),
-GREEN(0x00FF00),
-RED(0xFF0000),
+ GREEN(0x00FF00),
+ RED(0xFF0000),
}
enum class Alp {
BLUE(0x0000FF),
-GREEN(0x00FF00),
-RED(0xFF0000)
+ GREEN(0x00FF00),
+ RED(0xFF0000)
;
}
+
+enum class IssueType {
+ PROJECT_STRUCTURE, TESTS, VCS
+}
+
+enum class IssueType {
+ PROJECT_STRUCTURE,TESTS,VCS
+}
+
+enum class IssueType {
+ PROJECT_STRUCTURE, // comment
+TESTS,
+VCS
+}
+
+enum class IssueType {
+ PROJECT_STRUCTURE ,// comment
+TESTS,
+VCS
+}
diff --git a/diktat-rules/src/test/resources/test/paragraph3/sort_error/EnumSortTest.kt b/diktat-rules/src/test/resources/test/paragraph3/sort_error/EnumSortTest.kt
index e663ba99f7..1c87f8c520 100644
--- a/diktat-rules/src/test/resources/test/paragraph3/sort_error/EnumSortTest.kt
+++ b/diktat-rules/src/test/resources/test/paragraph3/sort_error/EnumSortTest.kt
@@ -40,5 +40,22 @@ enum class Alp {
RED(0xFF0000),
GREEN(0x00FF00),
BLUE(0x0000FF)
- ;
+;
+}
+
+enum class IssueType {
+ VCS, PROJECT_STRUCTURE, TESTS
+}
+
+enum class IssueType {
+ VCS,PROJECT_STRUCTURE,TESTS
+}
+
+enum class IssueType {
+ VCS,PROJECT_STRUCTURE, // comment
+ TESTS
+}
+
+enum class IssueType {
+ VCS, TESTS, PROJECT_STRUCTURE // comment
}
diff --git a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt
index 943de52b8a..92c20ffb49 100644
--- a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt
+++ b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt
@@ -35,6 +35,10 @@ class Example {
}
}
+enum class IssueType {
+ PROJECT_STRUCTURE, TESTS, VCS
+}
+
class Foo {
/**
* @implNote lorem ipsum
diff --git a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt
index ddd801edf8..ee6d20b539 100644
--- a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt
+++ b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt
@@ -41,6 +41,9 @@ class Example {
}
}
+enum class IssueType {
+ VCS, PROJECT_STRUCTURE, TESTS
+}
class Foo {
/**