From 2d3323ffa39a57fce2ee6d58804ad178253bae05 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 26 May 2022 17:01:50 +0300 Subject: [PATCH] Added new rule for debug print ### What's done: * added prevId as VisitorModifier based on order in array --- .../cqfn/diktat/ruleset/constants/Warnings.kt | 1 + .../cqfn/diktat/ruleset/dummy/DummyWarning.kt | 5 +++-- .../cqfn/diktat/ruleset/rules/DiktatRule.kt | 4 ++-- .../ruleset/rules/DiktatRuleSetProvider.kt | 16 ++++++++++------ .../ruleset/rules/chapter1/FileNaming.kt | 5 +++-- .../rules/chapter1/IdentifierNaming.kt | 5 +++-- .../ruleset/rules/chapter1/PackageNaming.kt | 3 ++- .../rules/chapter2/comments/CommentsRule.kt | 5 +++-- .../chapter2/comments/HeaderCommentRule.kt | 3 ++- .../rules/chapter2/kdoc/CommentsFormatting.kt | 3 ++- .../rules/chapter2/kdoc/KdocComments.kt | 5 +++-- .../rules/chapter2/kdoc/KdocFormatting.kt | 3 ++- .../rules/chapter2/kdoc/KdocMethods.kt | 5 +++-- .../rules/chapter3/AnnotationNewLineRule.kt | 5 +++-- .../rules/chapter3/BlockStructureBraces.kt | 3 ++- .../rules/chapter3/BooleanExpressionsRule.kt | 5 +++-- .../BracesInConditionalsAndLoopsRule.kt | 5 +++-- .../chapter3/ClassLikeStructuresOrderRule.kt | 5 +++-- .../chapter3/CollapseIfStatementsRule.kt | 5 +++-- .../rules/chapter3/ConsecutiveSpacesRule.kt | 3 ++- .../ruleset/rules/chapter3/DebugPrintRule.kt | 19 +++++++++++++++++++ .../ruleset/rules/chapter3/EmptyBlock.kt | 5 +++-- .../ruleset/rules/chapter3/EnumsSeparated.kt | 3 ++- .../ruleset/rules/chapter3/LineLength.kt | 5 +++-- .../LongNumericalValuesSeparatedRule.kt | 5 +++-- .../ruleset/rules/chapter3/MagicNumberRule.kt | 5 +++-- .../chapter3/MultipleModifiersSequence.kt | 5 +++-- .../rules/chapter3/NullableTypeRule.kt | 5 +++-- .../rules/chapter3/RangeConventionalRule.kt | 5 +++-- .../chapter3/SingleLineStatementsRule.kt | 5 +++-- .../diktat/ruleset/rules/chapter3/SortRule.kt | 3 ++- .../rules/chapter3/StringConcatenationRule.kt | 5 +++-- .../chapter3/StringTemplateFormatRule.kt | 5 +++-- .../rules/chapter3/TrailingCommaRule.kt | 5 +++-- .../rules/chapter3/WhenMustHaveElseRule.kt | 5 +++-- .../rules/chapter3/files/BlankLinesRule.kt | 3 ++- .../ruleset/rules/chapter3/files/FileSize.kt | 5 +++-- .../rules/chapter3/files/FileStructureRule.kt | 3 ++- .../rules/chapter3/files/IndentationRule.kt | 5 +++-- .../rules/chapter3/files/NewlinesRule.kt | 5 +++-- .../rules/chapter3/files/TopLevelOrderRule.kt | 3 ++- .../rules/chapter3/files/WhiteSpaceRule.kt | 5 +++-- .../identifiers/LocalVariablesRule.kt | 5 +++-- .../rules/chapter4/ImmutableValNoVarRule.kt | 5 +++-- .../ruleset/rules/chapter4/NullChecksRule.kt | 5 +++-- .../ruleset/rules/chapter4/SmartCastRule.kt | 5 +++-- .../ruleset/rules/chapter4/TypeAliasRule.kt | 5 +++-- .../VariableGenericTypeDeclarationRule.kt | 5 +++-- .../calculations/AccurateCalculationsRule.kt | 5 +++-- .../rules/chapter5/AsyncAndSyncRule.kt | 5 +++-- .../chapter5/AvoidNestedFunctionsRule.kt | 5 +++-- .../rules/chapter5/CheckInverseMethodRule.kt | 5 +++-- .../ruleset/rules/chapter5/CustomLabel.kt | 5 +++-- .../rules/chapter5/FunctionArgumentsSize.kt | 5 +++-- .../ruleset/rules/chapter5/FunctionLength.kt | 5 +++-- .../rules/chapter5/LambdaLengthRule.kt | 5 +++-- .../rules/chapter5/LambdaParameterOrder.kt | 5 +++-- .../rules/chapter5/NestedFunctionBlock.kt | 5 +++-- .../chapter5/OverloadingArgumentsFunction.kt | 5 +++-- .../ParameterNameInOuterLambdaRule.kt | 5 +++-- .../chapter6/AvoidEmptyPrimaryConstructor.kt | 5 +++-- .../rules/chapter6/AvoidUtilityClass.kt | 5 +++-- .../rules/chapter6/CustomGetterSetterRule.kt | 5 +++-- .../chapter6/ExtensionFunctionsInFileRule.kt | 5 +++-- .../ExtensionFunctionsSameNameRule.kt | 5 +++-- .../chapter6/ImplicitBackingPropertyRule.kt | 5 +++-- .../rules/chapter6/PropertyAccessorFields.kt | 5 +++-- .../ruleset/rules/chapter6/RunInScript.kt | 2 +- .../chapter6/TrivialPropertyAccessors.kt | 5 +++-- .../ruleset/rules/chapter6/UseLastIndex.kt | 5 +++-- .../rules/chapter6/UselessSupertype.kt | 5 +++-- .../chapter6/classes/AbstractClassesRule.kt | 5 +++-- .../chapter6/classes/CompactInitialization.kt | 5 +++-- .../rules/chapter6/classes/DataClassesRule.kt | 5 +++-- .../chapter6/classes/InlineClassesRule.kt | 5 +++-- .../chapter6/classes/SingleConstructorRule.kt | 5 +++-- .../rules/chapter6/classes/SingleInitRule.kt | 5 +++-- .../chapter6/classes/StatelessClassesRule.kt | 5 +++-- .../BooleanExpressionsRuleWarnTest.kt | 2 +- .../diktat/ruleset/smoke/DiktatSmokeTest.kt | 2 +- .../diktat/util/DiktatRuleSetProvider4Test.kt | 4 ++-- .../org/cqfn/diktat/util/FixTestBase.kt | 6 +++--- .../org/cqfn/diktat/util/LintTestBase.kt | 2 +- .../kotlin/org/cqfn/diktat/util/TestUtils.kt | 4 ++-- .../long_line/LongLineCommentExpected2.kt | 2 +- .../long_line/LongLineCommentTest2.kt | 2 +- wp/sections/work.tex | 2 +- 87 files changed, 254 insertions(+), 157 deletions(-) create mode 100644 diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/DebugPrintRule.kt 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 2425f7be42..cfbbe3f2db 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 @@ -136,6 +136,7 @@ enum class Warnings( FILE_NAME_MATCH_CLASS(true, "3.1.2", "file name is incorrect - it should match with the class described in it if there is the only one class declared"), COLLAPSE_IF_STATEMENTS(true, "3.16.1", "avoid using redundant nested if-statements, which could be collapsed into a single one"), CONVENTIONAL_RANGE(true, "3.17.1", "use conventional rule for range case"), + DEBUG_PRINT(false, "3.18.1", "avoid print/println for debug logging"), // ======== chapter 4 ======== NULLABLE_PROPERTY_TYPE(true, "4.3.1", "try to avoid use of nullable types"), diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/dummy/DummyWarning.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/dummy/DummyWarning.kt index d1383a5446..089d6d8c4e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/dummy/DummyWarning.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/dummy/DummyWarning.kt @@ -9,13 +9,14 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * Dummy warning used for testing and debug purposes. * Can be used in manual testing. */ -class DummyWarning(configRules: List) : DiktatRule( +class DummyWarning(configRules: List, prevId: String?) : DiktatRule( "dummy-rule", configRules, listOf( Warnings.FILE_NAME_INCORRECT, Warnings.FILE_NAME_MATCH_CLASS - ) + ), + prevId ) { @Suppress("UNUSED") private lateinit var filePath: String diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt index 06e76cba9f..b0686750e4 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt @@ -23,8 +23,8 @@ abstract class DiktatRule( id: String, val configRules: List, private val inspections: List, - visitorModifiers: Set = emptySet(), -) : Rule(id, visitorModifiers) { + prevId: String?, +) : Rule(id, visitorModifiers = prevId?.let { setOf(VisitorModifier.RunAfterRule(it)) } ?: emptySet()) { /** * Default value is false */ diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt index 1ae2ad05ed..072fd3211b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt @@ -1,5 +1,6 @@ package org.cqfn.diktat.ruleset.rules +import com.pinterest.ktlint.core.Rule import org.cqfn.diktat.common.config.rules.DIKTAT_COMMON import org.cqfn.diktat.common.config.rules.RulesConfig import org.cqfn.diktat.common.config.rules.RulesConfigReader @@ -85,6 +86,7 @@ import org.jetbrains.kotlin.org.jline.utils.Levenshtein import org.slf4j.LoggerFactory import java.io.File +import kotlin.reflect.KFunction /** * this constant will be used everywhere in the code to mark usage of Diktat ruleset @@ -221,15 +223,17 @@ class DiktatRuleSetProvider(private var diktatConfigFile: String = DIKTAT_ANALYS ::NewlinesRule, // newlines need to be inserted right before fixing indentation ::WhiteSpaceRule, // this rule should be after other rules that can cause wrong spacing ::IndentationRule, // indentation rule should be the last because it fixes formatting after all the changes done by previous rules - ) - .map { - it.invoke(configRules) - } - .toTypedArray() + var prevRuleId: String? = null + val createdRules: List = rules.map { function -> + val result: Rule = function.invoke(configRules, prevRuleId) + prevRuleId = result.id + return RuleSet(result.id) + } + val rulesArray: Array = createdRules.toTypedArray() return RuleSet( DIKTAT_RULE_SET_ID, - *rules + rules = rulesArray ) } 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 68dd00d5b3..9dd1d57f3d 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,10 +26,11 @@ 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( +class FileNaming(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS) + listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS), + prevId ) { private lateinit var filePath: String 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 c0e9e277c1..a3bfcfcc9b 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 @@ -70,13 +70,14 @@ import java.util.Locale * // FixMe: because it fixes only declaration without the usages */ @Suppress("ForbiddenComment", "MISSING_KDOC_CLASS_ELEMENTS") -class IdentifierNaming(configRules: List) : DiktatRule( +class IdentifierNaming(configRules: List, prevId: String? = null) : DiktatRule( NAME_ID, 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, - IDENTIFIER_LENGTH, OBJECT_NAME_INCORRECT, TYPEALIAS_NAME_INCORRECT_CASE) + IDENTIFIER_LENGTH, OBJECT_NAME_INCORRECT, TYPEALIAS_NAME_INCORRECT_CASE), + prevId ) { private val allMethodPrefixes by lazy { if (configuration.allowedBooleanPrefixes.isEmpty()) { 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 874ccc08af..5280c14893 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 @@ -42,11 +42,12 @@ 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( +class PackageNaming(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(INCORRECT_PACKAGE_SEPARATOR, PACKAGE_NAME_INCORRECT_CASE, PACKAGE_NAME_MISSING, PACKAGE_NAME_INCORRECT_PATH, PACKAGE_NAME_INCORRECT_PREFIX, PACKAGE_NAME_INCORRECT_SYMBOLS), + prevId ) { private lateinit var domainName: String 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 2156dbbbd9..7ceca3a5c1 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 @@ -25,10 +25,11 @@ import org.slf4j.LoggerFactory * No commented out code is allowed, including imports. */ @Suppress("ForbiddenComment") -class CommentsRule(configRules: List) : DiktatRule( +class CommentsRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(COMMENTED_OUT_CODE) + listOf(COMMENTED_OUT_CODE), + prevId ) { private lateinit var ktPsiFactory: KtPsiFactory 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 a3b0b6ceef..6b66cf43fb 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 @@ -42,11 +42,12 @@ import java.time.LocalDate * 4) Ensure files with many or zero classes have proper description */ @Suppress("ForbiddenComment") -class HeaderCommentRule(configRules: List) : DiktatRule( +class HeaderCommentRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, 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), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == FILE && !node.getFilePath().isGradleScript()) { 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 d9422f0713..fc45b25641 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,11 +49,12 @@ 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( +class CommentsFormatting(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(COMMENT_WHITE_SPACE, FIRST_COMMENT_NO_BLANK_LINE, IF_ELSE_COMMENTS, WRONG_NEWLINES_AROUND_KDOC), + prevId ) { /** * @param node 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 6425b64bdd..f1ec76af29 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 @@ -48,11 +48,12 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * 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( +class KdocComments(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY, - KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL) + KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL), + prevId ) { private val config by lazy { configRules.getCommonConfiguration() } 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 898441993c..dd835cc153 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 @@ -60,12 +60,13 @@ import java.time.temporal.ChronoField * 7) ensuring @since tag contains only versions and not dates */ @Suppress("ForbiddenComment") -class KdocFormatting(configRules: List) : DiktatRule( +class KdocFormatting(configRules: List, prevId: String?) : DiktatRule( NAME_ID, 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), + prevId ) { private val basicTagsList = listOf(KDocKnownTag.PARAM, KDocKnownTag.RETURN, KDocKnownTag.THROWS) private val specialTagNames = setOf("implSpec", "implNote", "apiNote") 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 09586184c3..3262647f70 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 @@ -69,11 +69,12 @@ 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( +class KdocMethods(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG, - KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION) + KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION), + prevId ) { /** * @param node 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 c9a29ac7ee..c7a12b017e 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,10 +19,11 @@ 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( +class AnnotationNewLineRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(ANNOTATION_NEW_LINE) + listOf(ANNOTATION_NEW_LINE), + prevId ) { override fun logic(node: ASTNode) { when (node.elementType) { 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 47f4cb0e59..973fe572de 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 @@ -50,10 +50,11 @@ 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( +class BlockStructureBraces(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(BRACES_BLOCK_STRUCTURE_ERROR), + prevId ) { override fun logic(node: ASTNode) { val configuration = BlockStructureBracesConfiguration( diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BooleanExpressionsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BooleanExpressionsRule.kt index 8e2aec9276..8981c7cd0d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BooleanExpressionsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BooleanExpressionsRule.kt @@ -31,10 +31,11 @@ import java.lang.RuntimeException /** * Rule that checks if the boolean expression can be simplified. */ -class BooleanExpressionsRule(configRules: List) : DiktatRule( +class BooleanExpressionsRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(COMPLEX_BOOLEAN_EXPRESSION) + listOf(COMPLEX_BOOLEAN_EXPRESSION), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CONDITION) { 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 121a729503..aaeb557ba6 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 @@ -38,10 +38,11 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * Rule that checks that all conditionals and loops have braces. */ -class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule( +class BracesInConditionalsAndLoopsRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS) + listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS), + prevId ) { override fun logic(node: ASTNode) { when (node.elementType) { 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 aeb12d1af5..047296722c 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 @@ -43,10 +43,11 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings /** * Rule that checks order of declarations inside classes, interfaces and objects. */ -class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule( +class ClassLikeStructuresOrderRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES) + listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/CollapseIfStatementsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/CollapseIfStatementsRule.kt index c117a113b9..9ce66a1253 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/CollapseIfStatementsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/CollapseIfStatementsRule.kt @@ -30,12 +30,13 @@ typealias PlaceOfWarningForCurrentNode = Pair /** * Rule for redundant nested if-statements, which could be collapsed into a single one */ -class CollapseIfStatementsRule(configRules: List) : DiktatRule( +class CollapseIfStatementsRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf( Warnings.COLLAPSE_IF_STATEMENTS - ) + ), + prevId ) { private val configuration by lazy { CollapseIfStatementsConfiguration( 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 c2f0697b68..9f892ff0d6 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,10 +20,11 @@ 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( +class ConsecutiveSpacesRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(TOO_MANY_CONSECUTIVE_SPACES), + prevId ) { override fun logic(node: ASTNode) { val configuration = TooManySpacesRuleConfiguration( diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/DebugPrintRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/DebugPrintRule.kt new file mode 100644 index 0000000000..826059f289 --- /dev/null +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/DebugPrintRule.kt @@ -0,0 +1,19 @@ +package org.cqfn.diktat.ruleset.rules.chapter3 + +import org.cqfn.diktat.common.config.rules.RulesConfig +import org.cqfn.diktat.ruleset.rules.DiktatRule +import org.jetbrains.kotlin.com.intellij.lang.ASTNode + +/** + * Rule checks that print or println are not in used (assumption: it's a debug logging) + */ +class DebugPrintRule(configRules: List, prevId: String?) : DiktatRule(NAME_ID, configRules, listOf(), prevId) { + + companion object { + const val NAME_ID = "aan-empty-block-structure" + } + + override fun logic(node: ASTNode) { + TODO("Not yet implemented") + } +} \ No newline at end of file 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 3b20a5b54d..1914728143 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 @@ -24,10 +24,11 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule that checks if empty code blocks (`{ }`) are used and checks their formatting. */ -class EmptyBlock(configRules: List) : DiktatRule( +class EmptyBlock(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(EMPTY_BLOCK_STRUCTURE_ERROR) + listOf(EMPTY_BLOCK_STRUCTURE_ERROR), + prevId ) { override fun logic(node: ASTNode) { val configuration = EmptyBlockStyleConfiguration( 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 30970edc44..26479cfaac 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,10 +26,11 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl /** * Rule that checks enum classes formatting */ -class EnumsSeparated(configRules: List) : DiktatRule( +class EnumsSeparated(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(ENUMS_SEPARATED), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CLASS && node.hasChildOfType(CLASS_BODY) && 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 04469c307e..50f0d4ebee 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 @@ -66,10 +66,11 @@ 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( +class LineLength(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(LONG_LINE) + listOf(LONG_LINE), + prevId ) { private val configuration by lazy { LineLengthConfiguration( 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 e50332bab1..127202b9fb 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,10 +16,11 @@ import java.lang.StringBuilder /** * Rule that checks if numerical separators (`_`) are used for long numerical literals */ -class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule( +class LongNumericalValuesSeparatedRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(LONG_NUMERICAL_VALUES_SEPARATED) + listOf(LONG_NUMERICAL_VALUES_SEPARATED), + prevId ) { override fun logic(node: ASTNode) { val configuration = LongNumericalValuesConfiguration( diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt index 0bef978165..eeaa0064eb 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MagicNumberRule.kt @@ -28,10 +28,11 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule for magic number */ -class MagicNumberRule(configRules: List) : DiktatRule( +class MagicNumberRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(MAGIC_NUMBER) + listOf(MAGIC_NUMBER), + prevId ) { private val configuration by lazy { MagicNumberConfiguration( 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 609377bb37..a941ee30b3 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,10 +15,11 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * @property configRules */ -class MultipleModifiersSequence(configRules: List) : DiktatRule( +class MultipleModifiersSequence(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(WRONG_MULTIPLE_MODIFIERS_ORDER) + listOf(WRONG_MULTIPLE_MODIFIERS_ORDER), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == MODIFIER_LIST) { 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 c328ed135d..2f658a3fb6 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,10 +37,11 @@ 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( +class NullableTypeRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(NULLABLE_PROPERTY_TYPE) + listOf(NULLABLE_PROPERTY_TYPE), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/RangeConventionalRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/RangeConventionalRule.kt index c9317191b9..bcfdf7e85b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/RangeConventionalRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/RangeConventionalRule.kt @@ -31,10 +31,11 @@ import org.jetbrains.kotlin.psi.KtDotQualifiedExpression * This rule warn and fix cases when it possible to replace range with until or replace rangeTo function with range */ @Suppress("UnsafeCallOnNullableType") -class RangeConventionalRule(configRules: List) : DiktatRule( +class RangeConventionalRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(CONVENTIONAL_RANGE) + listOf(CONVENTIONAL_RANGE), + prevId ) { private val configuration by lazy { RangeConventionalConfiguration( 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 fbf10f5b4e..96d74a4ee0 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,10 +18,11 @@ 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( +class SingleLineStatementsRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(MORE_THAN_ONE_STATEMENT_PER_LINE) + listOf(MORE_THAN_ONE_STATEMENT_PER_LINE), + prevId ) { 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 99c6de74ed..6de45b3453 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 @@ -31,10 +31,11 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings /** * Rule that sorts class properties and enum members alphabetically */ -class SortRule(configRules: List) : DiktatRule( +class SortRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(WRONG_DECLARATIONS_ORDER), + prevId ) { override fun logic(node: ASTNode) { val configuration = SortRuleConfiguration( 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 1f2ee49149..08e406133d 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 @@ -28,12 +28,13 @@ import org.jetbrains.kotlin.psi.KtStringTemplateExpression * "string " + 1 will be converted to "string 1" * "string one " + "string two " */ -class StringConcatenationRule(configRules: List) : DiktatRule( +class StringConcatenationRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf( STRING_CONCATENATION - ) + ), + prevId ) { @Suppress("COLLAPSE_IF_STATEMENTS") override fun logic(node: ASTNode) { 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 13a933b105..e32867bd9a 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 @@ -27,10 +27,11 @@ 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( +class StringTemplateFormatRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES) + listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES), + prevId ) { 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 9eb3d1fb76..b9917f153e 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 @@ -52,10 +52,11 @@ import org.slf4j.LoggerFactory * [12] Destructuring declarations */ @Suppress("TOO_LONG_FUNCTION") -class TrailingCommaRule(configRules: List) : DiktatRule( +class TrailingCommaRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(TRAILING_COMMA) + listOf(TRAILING_COMMA), + prevId ) { private val commonConfig = configRules.getCommonConfiguration() private val trailingConfig = this.configRules.getRuleConfig(TRAILING_COMMA)?.configuration ?: emptyMap() 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 91380f570f..8ffc9d35ba 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 @@ -45,10 +45,11 @@ import org.jetbrains.kotlin.psi.KtWhenExpression * The compiler can issue a warning when it is missing. */ @Suppress("ForbiddenComment") -class WhenMustHaveElseRule(configRules: List) : DiktatRule( +class WhenMustHaveElseRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(WHEN_WITHOUT_ELSE) + listOf(WHEN_WITHOUT_ELSE), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.WHEN && isStatement(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 6386640585..4c2b9d1f7d 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 @@ -21,10 +21,11 @@ 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( +class BlankLinesRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(TOO_MANY_BLANK_LINES), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == WHITE_SPACE) { 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 395f706571..a925aa9343 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 @@ -12,10 +12,11 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Rule that checks number of lines in a file */ -class FileSize(configRules: List) : DiktatRule( +class FileSize(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(FILE_IS_TOO_LONG) + listOf(FILE_IS_TOO_LONG), + prevId ) { private val configuration by lazy { FileSizeConfiguration( 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 5f77d00f26..c565a00a4d 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 @@ -56,11 +56,12 @@ 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( +class FileStructureRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(FILE_CONTAINS_ONLY_COMMENTS, FILE_INCORRECT_BLOCKS_ORDER, FILE_NO_BLANK_LINE_BETWEEN_BLOCKS, FILE_UNORDERED_IMPORTS, FILE_WILDCARD_IMPORTS, UNUSED_IMPORT), + prevId ) { private val domainName by lazy { configRules 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 77f74537eb..8b277a3bf1 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 @@ -68,10 +68,11 @@ import kotlin.math.abs * @see CustomIndentationChecker */ @Suppress("LargeClass") -class IndentationRule(configRules: List) : DiktatRule( +class IndentationRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(WRONG_INDENTATION) + listOf(WRONG_INDENTATION), + prevId ) { 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 a3802d4686..4cf7ea53e0 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 @@ -116,10 +116,11 @@ import org.slf4j.LoggerFactory * 10. Complex expression inside condition replaced with new variable */ @Suppress("ForbiddenComment") -class NewlinesRule(configRules: List) : DiktatRule( +class NewlinesRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES) + listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES), + prevId ) { private val configuration by lazy { NewlinesRuleConfiguration(configRules.getRuleConfig(WRONG_NEWLINES)?.configuration ?: emptyMap()) 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 09f8e97e99..c441f5c364 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 @@ -26,10 +26,11 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings /** * Rule that checks order in top level */ -class TopLevelOrderRule(configRules: List) : DiktatRule( +class TopLevelOrderRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, listOf(TOP_LEVEL_ORDER), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { 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 52a45356b3..4972b99eff 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 @@ -93,10 +93,11 @@ import org.slf4j.LoggerFactory * 10. There should be no spaces between prefix/postfix operator (like `!!` or `++`) and it's operand */ @Suppress("ForbiddenComment") -class WhiteSpaceRule(configRules: List) : DiktatRule( +class WhiteSpaceRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(WRONG_WHITESPACE) + listOf(WRONG_WHITESPACE), + prevId ) { @Suppress("ComplexMethod") override fun logic(node: ASTNode) { 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 79deb89351..76fe0b9eeb 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,10 +37,11 @@ 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( +class LocalVariablesRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(LOCAL_VARIABLE_EARLY_DECLARATION) + listOf(LOCAL_VARIABLE_EARLY_DECLARATION), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { 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 189513986b..13c3a572bf 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,10 +19,11 @@ 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( +class ImmutableValNoVarRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(SAY_NO_TO_VAR) + listOf(SAY_NO_TO_VAR), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FILE) { 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 747e80fe2f..a67d471112 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 @@ -30,10 +30,11 @@ import org.jetbrains.kotlin.psi.psiUtil.blockExpressionsOrSingle * 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( +class NullChecksRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(AVOID_NULL_CHECKS) + listOf(AVOID_NULL_CHECKS), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CONDITION) { 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 36973ca5c9..e1f8a4517f 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 @@ -34,10 +34,11 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule that detects redundant explicit casts */ -class SmartCastRule(configRules: List) : DiktatRule( +class SmartCastRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(SMART_CAST_NEEDED) + listOf(SMART_CAST_NEEDED), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { 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 a1dac69daa..0c9270952d 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,10 +19,11 @@ 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( +class TypeAliasRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(TYPE_ALIAS) + listOf(TYPE_ALIAS), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == TYPE_REFERENCE && node 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 991f089880..be37d2cf6f 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,10 +21,11 @@ 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( +class VariableGenericTypeDeclarationRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(GENERIC_VARIABLE_WRONG_DECLARATION) + listOf(GENERIC_VARIABLE_WRONG_DECLARATION), + prevId ) { 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 60972952d5..6593f1648e 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,10 +24,11 @@ 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( +class AccurateCalculationsRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(FLOAT_IN_ACCURATE_CALCULATIONS) + listOf(FLOAT_IN_ACCURATE_CALCULATIONS), + prevId ) { private fun KtCallExpression?.isAbsOfFloat() = this ?.run { 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 cb5435d697..bd7fb9f338 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,10 +17,11 @@ import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier /** * This rule finds if using runBlocking in asynchronous code */ -class AsyncAndSyncRule(configRules: List) : DiktatRule( +class AsyncAndSyncRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(RUN_BLOCKING_INSIDE_ASYNC) + listOf(RUN_BLOCKING_INSIDE_ASYNC), + prevId ) { private val asyncList = listOf("async", "launch") 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 8fdc38eaf5..6ff4a0c4cf 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,10 +24,11 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * This rule checks for nested functions and warns if it finds any. */ -class AvoidNestedFunctionsRule(configRules: List) : DiktatRule( +class AvoidNestedFunctionsRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(AVOID_NESTED_FUNCTIONS) + listOf(AVOID_NESTED_FUNCTIONS), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == FUN) { 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 ccfba1e0ed..9cc0bf26ee 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,10 +22,11 @@ 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( +class CheckInverseMethodRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(INVERSE_FUNCTION_PREFERRED) + listOf(INVERSE_FUNCTION_PREFERRED), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CALL_EXPRESSION && node.text in methodMap.keys) { 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 c14c0718f9..7427ee0c1b 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,10 +17,11 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule that checks using custom label */ -class CustomLabel(configRules: List) : DiktatRule( +class CustomLabel(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(CUSTOM_LABEL) + listOf(CUSTOM_LABEL), + prevId ) { private val forEachReference = listOf("forEach", "forEachIndexed") private val labels = listOf("@loop", "@forEach", "@forEachIndexed") 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 e3bed256ca..53f381be79 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,10 +14,11 @@ import org.jetbrains.kotlin.psi.KtFunction /** * Rule that checks that function doesn't contains too many parameters */ -class FunctionArgumentsSize(configRules: List) : DiktatRule( +class FunctionArgumentsSize(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(TOO_MANY_PARAMETERS) + listOf(TOO_MANY_PARAMETERS), + prevId ) { 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 5fbe953c40..9cd3ac2287 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,10 +14,11 @@ import org.jetbrains.kotlin.psi.KtFunction /** * Rule 5.1.1 check function length */ -class FunctionLength(configRules: List) : DiktatRule( +class FunctionLength(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(TOO_LONG_FUNCTION) + listOf(TOO_LONG_FUNCTION), + prevId ) { override fun logic(node: ASTNode) { val configuration = FunctionLengthConfiguration( 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 eafa95e20a..d4c899b83a 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,10 +13,11 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Rule 5.2.5 check lambda length without parameters */ -class LambdaLengthRule(configRules: List) : DiktatRule( +class LambdaLengthRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(TOO_MANY_LINES_IN_LAMBDA) + listOf(TOO_MANY_LINES_IN_LAMBDA), + prevId ) { private val configuration by lazy { LambdaLengthConfiguration( 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 cd23b9022e..1c4bc68d16 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 @@ -16,10 +16,11 @@ 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( +class LambdaParameterOrder(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(LAMBDA_IS_NOT_LAST_PARAMETER) + listOf(LAMBDA_IS_NOT_LAST_PARAMETER), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FUN) { 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 6c75a95c12..1057b8b981 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,10 +20,11 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule 5.1.2 Nested blokcs */ -class NestedFunctionBlock(configRules: List) : DiktatRule( +class NestedFunctionBlock(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(NESTED_BLOCK) + listOf(NESTED_BLOCK), + prevId ) { 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 225c3649f1..312b1eae83 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,10 +17,11 @@ 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( +class OverloadingArgumentsFunction(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS) + listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == FUN) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/ParameterNameInOuterLambdaRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/ParameterNameInOuterLambdaRule.kt index 416b47de2c..be9475d58e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/ParameterNameInOuterLambdaRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/ParameterNameInOuterLambdaRule.kt @@ -12,10 +12,11 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Rule 5.2.7 check parameter name in outer lambda */ -class ParameterNameInOuterLambdaRule(configRules: List) : DiktatRule( +class ParameterNameInOuterLambdaRule(configRules: List, prevId: String?) : DiktatRule( "parameter-name-in-outer-lambda", configRules, - listOf(PARAMETER_NAME_IN_OUTER_LAMBDA) + listOf(PARAMETER_NAME_IN_OUTER_LAMBDA), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.LAMBDA_EXPRESSION) { 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 8a86997bb9..739c610ebd 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,10 +11,11 @@ import org.jetbrains.kotlin.psi.KtClass /** * This rule checks if a class has an empty primary constructor. */ -class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule( +class AvoidEmptyPrimaryConstructor(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(EMPTY_PRIMARY_CONSTRUCTOR) + listOf(EMPTY_PRIMARY_CONSTRUCTOR), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { 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 6670feae8f..1475575c96 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 @@ -25,10 +25,11 @@ import java.util.Locale /** * Rule 6.4.1 checks that class/object, with a word "util" in its name, has only functions. */ -class AvoidUtilityClass(configRules: List) : DiktatRule( +class AvoidUtilityClass(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(AVOID_USING_UTILITY_CLASS) + listOf(AVOID_USING_UTILITY_CLASS), + prevId ) { override fun logic(node: ASTNode) { val config = configRules.getCommonConfiguration() 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 8b971207ee..3d6e992fb0 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,10 +15,11 @@ 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( +class CustomGetterSetterRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(CUSTOM_GETTERS_SETTERS) + listOf(CUSTOM_GETTERS_SETTERS), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { 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 34944b4d53..e950fb867c 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,10 +20,11 @@ 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( +class ExtensionFunctionsInFileRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(EXTENSION_FUNCTION_WITH_CLASS) + listOf(EXTENSION_FUNCTION_WITH_CLASS), + prevId ) { 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 46970b911a..9a8a2584ea 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,10 +32,11 @@ internal typealias SimilarSignatures = List) : DiktatRule( +class ExtensionFunctionsSameNameRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(EXTENSION_FUNCTION_SAME_SIGNATURE) + listOf(EXTENSION_FUNCTION_SAME_SIGNATURE), + prevId ) { 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 1c8bb0cf92..d95380623c 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,10 +24,11 @@ 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( +class ImplicitBackingPropertyRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(NO_CORRESPONDING_PROPERTY) + listOf(NO_CORRESPONDING_PROPERTY), + prevId ) { 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 1153900389..d0ef6af1a1 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 @@ -22,10 +22,11 @@ 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( +class PropertyAccessorFields(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR) + listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt index 0b6bb9a7cd..48345aab0b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/RunInScript.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement * In .kts files allow use only property declaration, function, classes, and code inside `run` block * In gradle.kts files allow to call binary expression with EQ, expression and dot qualified expression in addition to everything used in .kts files */ -class RunInScript(private val configRules: List) : Rule(NAME_ID) { +class RunInScript(private val configRules: List, prevId: String?) : Rule(NAME_ID) { private var isFixMode: Boolean = false private lateinit var emitWarn: EmitType 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 35602552c9..1cf0d79684 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,10 +26,11 @@ 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( +class TrivialPropertyAccessors(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED) + listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UseLastIndex.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UseLastIndex.kt index 71f9bafb00..20163a2892 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UseLastIndex.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UseLastIndex.kt @@ -16,10 +16,11 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * This rule checks if there use property length with operation - 1 and fix this on lastIndex */ -class UseLastIndex(configRules: List) : DiktatRule( +class UseLastIndex(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(Warnings.USE_LAST_INDEX) + listOf(Warnings.USE_LAST_INDEX), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == BINARY_EXPRESSION) { 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 110dc921a4..396a00e316 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,10 +31,11 @@ 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( +class UselessSupertype(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(USELESS_SUPERTYPE) + listOf(USELESS_SUPERTYPE), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { 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 3d960b7b35..5c1b3e67d0 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 @@ -25,10 +25,11 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * Checks if abstract class has any abstract method. If not, warns that class should not be abstract */ -class AbstractClassesRule(configRules: List) : DiktatRule( +class AbstractClassesRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(CLASS_SHOULD_NOT_BE_ABSTRACT) + listOf(CLASS_SHOULD_NOT_BE_ABSTRACT), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { 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 d0cb43a182..caf0d578b7 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 @@ -40,10 +40,11 @@ import org.slf4j.LoggerFactory * 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 CompactInitialization(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(COMPACT_OBJECT_INITIALIZATION) + listOf(COMPACT_OBJECT_INITIALIZATION), + prevId ) { private val kotlinParser by lazy { KotlinParser() } 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 8e8cc86937..c5555e2332 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 @@ -30,10 +30,11 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor /** * This rule checks if class can be made as data class */ -class DataClassesRule(configRules: List) : DiktatRule( +class DataClassesRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(USE_DATA_CLASS) + listOf(USE_DATA_CLASS), + prevId ) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { 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 f76cbc510e..257d16c891 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,10 +25,11 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType /** * This rule checks if inline class can be used. */ -class InlineClassesRule(configRules: List) : DiktatRule( +class InlineClassesRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(INLINE_CLASS_CAN_BE_USED) + listOf(INLINE_CLASS_CAN_BE_USED), + prevId ) { override fun logic(node: ASTNode) { val configuration = configRules.getCommonConfiguration() 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 e6f72f38a2..f8ec232d80 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 @@ -38,10 +38,11 @@ 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( +class SingleConstructorRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY) + listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY), + prevId ) { private val kotlinParser by lazy { KotlinParser() } 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 b9600221e0..696c24d319 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 @@ -31,10 +31,11 @@ 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( +class SingleInitRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(MULTIPLE_INIT_BLOCKS) + listOf(MULTIPLE_INIT_BLOCKS), + prevId ) { override fun logic(node: ASTNode) { when (node.elementType) { 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 54e842f591..803255a7a5 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,10 +27,11 @@ 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( +class StatelessClassesRule(configRules: List, prevId: String?) : DiktatRule( NAME_ID, configRules, - listOf(OBJECT_IS_PREFERRED) + listOf(OBJECT_IS_PREFERRED), + prevId ) { override fun logic(node: ASTNode) { // Fixme: We should find interfaces in all project and then check them diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BooleanExpressionsRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BooleanExpressionsRuleWarnTest.kt index 380c25171b..3e5e42b727 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BooleanExpressionsRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BooleanExpressionsRuleWarnTest.kt @@ -283,7 +283,7 @@ class BooleanExpressionsRuleWarnTest : LintTestBase(::BooleanExpressionsRule) { val stream = ByteArrayOutputStream() System.setErr(PrintStream(stream)) val node = KotlinParser().createNode(expression) - val rule = BooleanExpressionsRule(emptyList()) + val rule = BooleanExpressionsRule(emptyList(), null) val map: BooleanExpressionsRule.ExpressionsReplacement = rule.ExpressionsReplacement() val result = rule.formatBooleanExpressionAsString(node, map) Assertions.assertEquals(expectedRepresentation, result) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt index 58080bcbc5..a637ea14b5 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt @@ -51,7 +51,7 @@ typealias RuleToConfig = Map> */ @OptIn(ExperimentalPathApi::class) class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", - { DiktatRuleSetProvider(configFilePath) }, + { _, _ -> DiktatRuleSetProvider(configFilePath) }, { lintError, _ -> unfixedLintErrors.add(lintError) }, null ) { diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/DiktatRuleSetProvider4Test.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/DiktatRuleSetProvider4Test.kt index 5661b44b08..c2e5b70abf 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/DiktatRuleSetProvider4Test.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/DiktatRuleSetProvider4Test.kt @@ -20,13 +20,13 @@ import java.io.File /** * simple class for emulating RuleSetProvider to inject .yml rule configuration and mock this part of code */ -class DiktatRuleSetProvider4Test(private val ruleSupplier: (rulesConfigList: List) -> Rule, +class DiktatRuleSetProvider4Test(private val ruleSupplier: (rulesConfigList: List, prevId: String?) -> Rule, rulesConfigList: List?) : RuleSetProvider { private val rulesConfigList: List? = rulesConfigList ?: RulesConfigReader(javaClass.classLoader).readResource("diktat-analysis.yml") override fun get() = RuleSet( DIKTAT_RULE_SET_ID, - ruleSupplier.invoke(rulesConfigList ?: emptyList()) + ruleSupplier.invoke(rulesConfigList ?: emptyList(), null) ) } 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 ea538ffcdc..9a68124a88 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 @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Assertions * @property resourceFilePath path to files which will be compared in tests */ open class FixTestBase(protected val resourceFilePath: String, - private val ruleSetProviderRef: (rulesConfigList: List?) -> RuleSetProvider, + private val ruleSetProviderRef: (rulesConfigList: List?, prevId: String?) -> RuleSetProvider, private val cb: LintErrorCallback = defaultCallback, private val rulesConfigList: List? = null ) { @@ -20,12 +20,12 @@ open class FixTestBase(protected val resourceFilePath: String, } constructor(resourceFilePath: String, - ruleSupplier: (rulesConfigList: List) -> Rule, + ruleSupplier: (rulesConfigList: List, String?) -> Rule, rulesConfigList: List? = null, cb: LintErrorCallback = defaultCallback ) : this( resourceFilePath, - { overrideRulesConfigList -> DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList) }, + { overrideRulesConfigList, _ -> DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList) }, cb, rulesConfigList ) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt index bd53570716..00b8fc86bf 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt @@ -12,7 +12,7 @@ import com.pinterest.ktlint.core.api.FeatureInAlphaState * @property ruleSupplier mapping of list of [RulesConfig] into a [Rule] * @property rulesConfigList optional custom rules config */ -open class LintTestBase(private val ruleSupplier: (rulesConfigList: List) -> Rule, +open class LintTestBase(private val ruleSupplier: (rulesConfigList: List, String?) -> Rule, private val rulesConfigList: List? = null) { /** * Perform linting of [code], collect errors and compare with [lintErrors] diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt index aff5745ae0..6994a3d9fd 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt @@ -81,13 +81,13 @@ internal fun List.assertEquals(vararg expectedLintErrors: LintError) */ @OptIn(FeatureInAlphaState::class) @Suppress("LAMBDA_IS_NOT_LAST_PARAMETER") -internal fun format(ruleSetProviderRef: (rulesConfigList: List?) -> RuleSetProvider, +internal fun format(ruleSetProviderRef: (rulesConfigList: List?, prevId: String?) -> RuleSetProvider, text: String, fileName: String, rulesConfigList: List? = null, cb: LintErrorCallback = defaultCallback ): String { - val ruleSets = listOf(ruleSetProviderRef.invoke(rulesConfigList).get()) + val ruleSets = listOf(ruleSetProviderRef.invoke(rulesConfigList, null).get()) return KtLint.format( KtLint.ExperimentalParams( text = text, diff --git a/diktat-rules/src/test/resources/test/paragraph3/long_line/LongLineCommentExpected2.kt b/diktat-rules/src/test/resources/test/paragraph3/long_line/LongLineCommentExpected2.kt index 4f15518fd6..8bf0909b99 100644 --- a/diktat-rules/src/test/resources/test/paragraph3/long_line/LongLineCommentExpected2.kt +++ b/diktat-rules/src/test/resources/test/paragraph3/long_line/LongLineCommentExpected2.kt @@ -1,7 +1,7 @@ /** * This rule checks if there is a backing property for field with property accessors, in case they don't use field keyword */ -class ImplicitBackingPropertyRuleTest(configRules: List) { +class ImplicitBackingPropertyRuleTest(configRules: List, prevId: String?) { private fun validateAccessors(node: ASTNode, propsWithBackSymbol: List) { val accessors = node.findAllDescendantsWithSpecificType(PROPERTY_ACCESSOR).filter { it.hasChildOfType(BLOCK) } // Comment, which shouldn't be moved diff --git a/diktat-rules/src/test/resources/test/paragraph3/long_line/LongLineCommentTest2.kt b/diktat-rules/src/test/resources/test/paragraph3/long_line/LongLineCommentTest2.kt index f9b6d642e4..2c65b6a808 100644 --- a/diktat-rules/src/test/resources/test/paragraph3/long_line/LongLineCommentTest2.kt +++ b/diktat-rules/src/test/resources/test/paragraph3/long_line/LongLineCommentTest2.kt @@ -1,7 +1,7 @@ /** * This rule checks if there is a backing property for field with property accessors, in case they don't use field keyword */ -class ImplicitBackingPropertyRuleTest(configRules: List) { +class ImplicitBackingPropertyRuleTest(configRules: List, prevId: String?) { private fun validateAccessors(node: ASTNode, propsWithBackSymbol: List) { val accessors = node.findAllDescendantsWithSpecificType(PROPERTY_ACCESSOR).filter { it.hasChildOfType(BLOCK) } // Comment, which shouldn't be moved accessors.filter { it.hasChildOfType(GET_KEYWORD) }.forEach { handleGetAccessors(it, node, propsWithBackSymbol) } diff --git a/wp/sections/work.tex b/wp/sections/work.tex index eee8fd8cb4..3277a49c7b 100644 --- a/wp/sections/work.tex +++ b/wp/sections/work.tex @@ -95,7 +95,7 @@ \subsection{DiKTat} Each rule must implement the \textsl{visit} method of the abstract Rule class, which describes the logic of the rule. By the way it is a special case of a famous pattern Visitor \cite{ref:gang}. Implementation example of the simple Rule that contains one Inspections can be found below. \begin{lstlisting}[caption={Example of the Rule.}, label={lst:example1}, language=Kotlin] -class SingleLineStatementsRule(private val configRules: List) : Rule("statement") { +class SingleLineStatementsRule(private val configRules: List, prevId: String?) : Rule("statement") { private var isFixMode: Boolean = false private lateinit var emitWarn: EmitType