diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index cabae09d3..4e8b06928 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -2,13 +2,9 @@ object Versions { object IntegrationTest { - const val ktlint = "0.43.2" + const val ktlint = "0.45.2" const val ktlintLink = "https://github.com/pinterest/ktlint/releases/download/$ktlint/ktlint" - const val diktat = "1.0.2" + const val diktat = "1.1.0" const val diktatLink = "https://github.com/saveourtool/diKTat/releases/download/v$diktat/diktat-$diktat.jar" - const val oldKtlint = "0.39.0" - const val oldKtlintLink = "https://github.com/pinterest/ktlint/releases/download/$oldKtlint/ktlint" - const val oldDiktat = "1.0.0-rc.2" - const val oldDiktatLink = "https://github.com/saveourtool/diKTat/releases/download/v$oldDiktat/diktat-$oldDiktat.jar" } } diff --git a/buildSrc/src/main/kotlin/com/saveourtool/save/buildutils/JacocoConfiguration.kt b/buildSrc/src/main/kotlin/com/saveourtool/save/buildutils/JacocoConfiguration.kt index 61f91d9f3..030adf203 100644 --- a/buildSrc/src/main/kotlin/com/saveourtool/save/buildutils/JacocoConfiguration.kt +++ b/buildSrc/src/main/kotlin/com/saveourtool/save/buildutils/JacocoConfiguration.kt @@ -27,7 +27,7 @@ fun Project.configureJacoco() { apply() configure { - toolVersion = "0.8.7" + toolVersion = "0.8.8" } val kotlin: KotlinMultiplatformExtension = extensions.getByType() diff --git a/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter1/Bug1Expected.kt b/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter1/Bug1Expected.kt index 4b6f900f8..73ccf62b4 100644 --- a/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter1/Bug1Expected.kt +++ b/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter1/Bug1Expected.kt @@ -1,19 +1,19 @@ -// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: Bug1Expected.kt vs D +// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: Bug1Expected.kt vs D{{.*}} package com.saveourtool.save.chapter1 -// ;warn:4:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: D (cannot be auto-corrected) -// ;warn:7:7: [CLASS_NAME_INCORRECT] class/enum/interface name should be in PascalCase and should contain only latin (ASCII) letters or numbers: D -// ;warn:7:7: [IDENTIFIER_LENGTH] identifier's length is incorrect, it should be in range of [2, 64] symbols: D (cannot be auto-corrected) +// ;warn:4:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: D (cannot be auto-corrected){{.*}} +// ;warn:7:7: [CLASS_NAME_INCORRECT] class/enum/interface name should be in PascalCase and should contain only latin (ASCII) letters or numbers: D{{.*}} +// ;warn:7:7: [IDENTIFIER_LENGTH] identifier's length is incorrect, it should be in range of [2, 64] symbols: D (cannot be auto-corrected){{.*}} class D { - // ;warn:8:5: [MISSING_KDOC_CLASS_ELEMENTS] all public, internal and protected classes, functions and variables inside the class should have Kdoc: x (cannot be auto-corrected) + // ;warn:8:5: [MISSING_KDOC_CLASS_ELEMENTS] all public, internal and protected classes, functions and variables inside the class should have Kdoc: x (cannot be auto-corrected){{.*}} val x = 0 - // ;warn:13:8: [KDOC_NO_EMPTY_TAGS] no empty descriptions in tag blocks are allowed: @return (cannot be auto-corrected) + // ;warn:13:8: [KDOC_NO_EMPTY_TAGS] no empty descriptions in tag blocks are allowed: @return (cannot be auto-corrected){{.*}} /** * @return */ fun bar(): Bar { - // ;warn:17:19: [MAGIC_NUMBER] avoid using magic numbers, instead define constants with clear names describing what the magic number means: 42 (cannot be auto-corrected) + // ;warn:17:19: [MAGIC_NUMBER] avoid using magic numbers, instead define constants with clear names describing what the magic number means: 42 (cannot be auto-corrected){{.*}} val qux = 42 return Bar(qux) } diff --git a/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter2/Bug2Expected.kt b/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter2/Bug2Expected.kt index d8cb7d047..82b161ddc 100644 --- a/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter2/Bug2Expected.kt +++ b/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter2/Bug2Expected.kt @@ -1,4 +1,4 @@ -// ;warn:1:1: [HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE] files that contain multiple or no classes should contain description of what is inside of this file: there are 2 declared classes and/or objects (cannot be auto-corrected) +// ;warn:1:1: [HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE] files that contain multiple or no classes should contain description of what is inside of this file: there are 2 declared classes and/or objects (cannot be auto-corrected){{.*}} package com.saveourtool.save.chapter2 import org.slf4j.LoggerFactory @@ -26,22 +26,17 @@ internal fun createWithFile( containerName: String, file: File, resources: Collection = emptySet() - // ;warn:30:3: [EMPTY_BLOCK_STRUCTURE_ERROR] incorrect format of empty block: empty blocks are forbidden unless it is function with override keyword (cannot be auto-corrected) + // ;warn:30:3: [EMPTY_BLOCK_STRUCTURE_ERROR] incorrect format of empty block: empty blocks are forbidden unless it is function with override keyword (cannot be auto-corrected){{.*}} ) {} private fun foo(node: ASTNode) { when (node.elementType) { CLASS, FUN, PRIMARY_CONSTRUCTOR, SECONDARY_CONSTRUCTOR -> checkAnnotation(node) - else -> { - // this is a generated else block - } } val qwe = a && - // ;warn:41:1: [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): expected 12 but was 8 - b + b val qwe = a && - // ;warn:44:1: [WRONG_INDENTATION] only spaces are allowed for indentation and each indentation should equal to 4 spaces (tabs are not allowed): expected 12 but was 8 - b + b // comment if (x) { diff --git a/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter3/Example1Expected.kt b/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter3/Example1Expected.kt index ba6bb2a41..94e1ec767 100644 --- a/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter3/Example1Expected.kt +++ b/examples/kotlin-diktat/fix_and_warn/smoke/src/main/kotlin/com/saveourtool/save/chapter3/Example1Expected.kt @@ -1,10 +1,10 @@ -// ;warn:1:1 [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: Example1Expected.kt vs Example +// ;warn:1:1 [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: Example1Expected.kt vs Example{{.*}} package com.saveourtool.save.chapter3 -// ;warn:4:1 [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: Example (cannot be auto-corrected) -// ;warn:4:1 [USE_DATA_CLASS] this class can be converted to a data class: Example (cannot be auto-corrected) +// ;warn:4:1 [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: Example (cannot be auto-corrected){{.*}} +// ;warn:4:1 [USE_DATA_CLASS] this class can be converted to a data class: Example (cannot be auto-corrected){{.*}} class Example { - // ;warn:7:5 [MISSING_KDOC_CLASS_ELEMENTS] all public, internal and protected classes, functions and variables inside the class should have Kdoc: isValid (cannot be auto-corrected) + // ;warn:7:5 [MISSING_KDOC_CLASS_ELEMENTS] all public, internal and protected classes, functions and variables inside the class should have Kdoc: isValid (cannot be auto-corrected){{.*}} @get:JvmName("getIsValid") val isValid = true } diff --git a/examples/kotlin-diktat/sarif-actual/src/kotlin/EnumValueSnakeCaseTest.kt b/examples/kotlin-diktat/sarif-actual/src/kotlin/EnumValueSnakeCaseTest.kt index 6aa3ef00b..1ac0c3747 100644 --- a/examples/kotlin-diktat/sarif-actual/src/kotlin/EnumValueSnakeCaseTest.kt +++ b/examples/kotlin-diktat/sarif-actual/src/kotlin/EnumValueSnakeCaseTest.kt @@ -1,15 +1,15 @@ package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected) -// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon +// x§and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected){{.*}} +// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} enum class EnumValueSnakeCaseTest { - // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f + // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f - // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma + // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} // ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} } diff --git a/examples/kotlin-diktat/sarif-expected/src/kotlin/EnumValueSnakeCaseTest.kt b/examples/kotlin-diktat/sarif-expected/src/kotlin/EnumValueSnakeCaseTest.kt index 6aa3ef00b..7f554e1b9 100644 --- a/examples/kotlin-diktat/sarif-expected/src/kotlin/EnumValueSnakeCaseTest.kt +++ b/examples/kotlin-diktat/sarif-expected/src/kotlin/EnumValueSnakeCaseTest.kt @@ -1,15 +1,15 @@ package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected) -// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon +// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected){{.*}} +// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} enum class EnumValueSnakeCaseTest { - // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f + // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f - // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma + // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} // ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} } diff --git a/examples/kotlin-diktat/save.toml b/examples/kotlin-diktat/save.toml index 1be4e070d..344d7e543 100644 --- a/examples/kotlin-diktat/save.toml +++ b/examples/kotlin-diktat/save.toml @@ -1,6 +1,6 @@ [general] - execCmd = "java -jar ktlint-old --disabled_rules=standard -R diktat-old.jar" - description = "Test for diktat - linter and formatter for Kotlin" + execCmd = "java -jar ktlint --disabled_rules=standard -R diktat.jar" + description = "22 test for diktat (linter and formatter for Kotlin)" language = "Kotlin" # this is the default value, you don't need to add it explicitly, but can be useful, if you have different pattern: expectedWarningsPattern = "// ;warn:?(.*):(\\d*): (.+)" diff --git a/examples/kotlin-diktat/warn-dir/chapter1/EnumValueSnakeCaseTest.kt b/examples/kotlin-diktat/warn-dir/chapter1/EnumValueSnakeCaseTest.kt index 720e05663..6d4568aaa 100644 --- a/examples/kotlin-diktat/warn-dir/chapter1/EnumValueSnakeCaseTest.kt +++ b/examples/kotlin-diktat/warn-dir/chapter1/EnumValueSnakeCaseTest.kt @@ -1,19 +1,19 @@ -// ;warn:2:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save +// ;warn:2:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ -// ;warn:4:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected) -// ;warn:8:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:17:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon -// ;warn:17:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma +// ;warn:4:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected){{.*}} +// ;warn:8:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:17:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} +// ;warn:17:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} enum class EnumValueSnakeCaseTest { - // ;warn:10:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:10:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:12:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: PascAsl_f + // ;warn:12:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f, - // ;warn:14:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: START_PSaaa_DFE + // ;warn:14:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: START_PSaaa_DFE{{.*}} START_PSaaa_DFE, - // ;warn:16:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: _NAme_MYa_sayR + // ;warn:16:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: _NAme_MYa_sayR{{.*}} _NAme_MYa_sayR, - // ;warn:18:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: NAme_MYa_sayR_ + // ;warn:18:5: [ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: NAme_MYa_sayR_{{.*}} NAme_MYa_sayR_ } diff --git a/examples/kotlin-diktat/warn-dir/chapter1/GenericFunctionTest.kt b/examples/kotlin-diktat/warn-dir/chapter1/GenericFunctionTest.kt index 5420aa628..22bb156b5 100644 --- a/examples/kotlin-diktat/warn-dir/chapter1/GenericFunctionTest.kt +++ b/examples/kotlin-diktat/warn-dir/chapter1/GenericFunctionTest.kt @@ -1,15 +1,15 @@ -// ;warn:3:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save -// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName +// ;warn:3:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} +// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName{{.*}} package com.saveourtool.diktat.test.paragraph1.naming.generic private class ClassName { private fun lock(body: ((Template?) -> T?)?, value: Template?): T? { try { - // ;warn:10:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected) - // ;warn:10:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:10:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected){{.*}} + // ;warn:10:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableName: Template? = null - // ;warn:13:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT - // ;warn:13:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:13:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT{{.*}} + // ;warn:13:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableT: T? = null println(variableT) return body!!(variableName) @@ -18,7 +18,7 @@ private class ClassName { } } - // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo + // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo{{.*}} fun foo(var1: T, var2: ((T?) -> T?)?) { lock(var2, var1) } diff --git a/examples/kotlin-diktat/warn-dir/chapter1/SmallTest.kt b/examples/kotlin-diktat/warn-dir/chapter1/SmallTest.kt index b91c2da6c..44c8721ac 100644 --- a/examples/kotlin-diktat/warn-dir/chapter1/SmallTest.kt +++ b/examples/kotlin-diktat/warn-dir/chapter1/SmallTest.kt @@ -1,4 +1,4 @@ -// ;warn:1:1: [FILE_CONTAINS_ONLY_COMMENTS] empty files or files that contain only comments should be avoided: file contains no code (cannot be auto-corrected) -// ;warn:1:1: [HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE] files that contain multiple or no classes should contain description of what is inside of this file: there are 0 declared classes and/or objects (cannot be auto-corrected) -// ;warn:4:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save +// ;warn:1:1: [FILE_CONTAINS_ONLY_COMMENTS] empty files or files that contain only comments should be avoided: file contains no code (cannot be auto-corrected){{.*}} +// ;warn:1:1: [HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE] files that contain multiple or no classes should contain description of what is inside of this file: there are 0 declared classes and/or objects (cannot be auto-corrected){{.*}} +// ;warn:4:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} package com.saveourtool.diktat.test.paragraph1.naming.generic diff --git a/examples/kotlin-diktat/warn-dir/chapter2/GenericFunctionTest.kt b/examples/kotlin-diktat/warn-dir/chapter2/GenericFunctionTest.kt index c1cf3373e..f6f72820e 100644 --- a/examples/kotlin-diktat/warn-dir/chapter2/GenericFunctionTest.kt +++ b/examples/kotlin-diktat/warn-dir/chapter2/GenericFunctionTest.kt @@ -1,15 +1,15 @@ -// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName -// ;warn:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save +// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName{{.*}} +// ;warn:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} package com.saveourtool.diktat.test.paragraph1.naming.generic private class ClassName { private fun lock(body: ((Template?) -> T?)?, value: Template?): T? { try { - // ;warn:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected) - // ;warn:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected){{.*}} + // ;warn:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableName: Template? = null - // ;warn:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT - // ;warn:$line+1:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT{{.*}} + // ;warn:$line+1:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableT: T? = null println(variableT) return body!!(variableName) @@ -18,7 +18,7 @@ private class ClassName { } } - // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo + // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo{{.*}} fun foo(var1: T, var2: ((T?) -> T?)?) { lock(var2, var1) } diff --git a/examples/kotlin-diktat/warn-dir/chapter3/GenericFunctionTest.kt b/examples/kotlin-diktat/warn-dir/chapter3/GenericFunctionTest.kt index 0311bcc2c..db16a93ad 100644 --- a/examples/kotlin-diktat/warn-dir/chapter3/GenericFunctionTest.kt +++ b/examples/kotlin-diktat/warn-dir/chapter3/GenericFunctionTest.kt @@ -1,15 +1,15 @@ -// ;warn:$line:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName -// ;warn:$line+1:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save +// ;warn:$line:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName{{.*}} +// ;warn:$line+1:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} package com.saveourtool.diktat.test.paragraph1.naming.generic private class ClassName { private fun lock(body: ((Template?) -> T?)?, value: Template?): T? { try { - // ;warn:$line+2:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected) - // ;warn:$line+1:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:$line+2:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected){{.*}} + // ;warn:$line+1:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableName: Template? = null - // ;warn:$line+2:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT - // ;warn:$line+1:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:$line+2:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT{{.*}} + // ;warn:$line+1:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableT: T? = null println(variableT) return body!!(variableName) @@ -19,7 +19,7 @@ private class ClassName { } // comment comment comment - // ;warn:$line-1:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo + // ;warn:$line-1:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo{{.*}} fun foo(var1: T, var2: ((T?) -> T?)?) { lock(var2, var1) } diff --git a/examples/kotlin-diktat/warn-dir/chapter4/GenericFunctionTest.kt b/examples/kotlin-diktat/warn-dir/chapter4/GenericFunctionTest.kt index 6948a461e..6720ace5c 100644 --- a/examples/kotlin-diktat/warn-dir/chapter4/GenericFunctionTest.kt +++ b/examples/kotlin-diktat/warn-dir/chapter4/GenericFunctionTest.kt @@ -1,4 +1,4 @@ -/* ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName */ +/* ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName{{.*}} */ package com.saveourtool.save.test.paragraph1.naming.generic private class ClassName { @@ -7,7 +7,7 @@ private class ClassName { val variableName: Template /* ;warn:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should * be in lowerCamelCase and should contain only latin (ASCII) - * letters or numbers and should start from lower letter: variableT + * letters or numbers and should start from lower letter: variableT{{.*}} * */ val variableT: T println(variableT) @@ -18,7 +18,7 @@ private class ClassName { } /* ;warn:20:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected - * functions should have Kdoc with proper tags: foo */ + * functions should have Kdoc with proper tags: foo{{.*}} */ fun foo(var1: T, var2: ((T?) -> T?)?) { lock(var2, var1) } diff --git a/examples/kotlin-diktat/warn-dir/save.toml b/examples/kotlin-diktat/warn-dir/save.toml index 4c92e7593..56c7352f8 100644 --- a/examples/kotlin-diktat/warn-dir/save.toml +++ b/examples/kotlin-diktat/warn-dir/save.toml @@ -1,5 +1,5 @@ [general] - execCmd = "java -jar ktlint-old --disabled_rules=standard -R diktat-old.jar" + execCmd = "java -jar ktlint --disabled_rules=standard -R diktat.jar" tags = ["warn"] description = "Test for directory mode" diff --git a/examples/kotlin-diktat/warn/chapter1/EnumValueSnakeCaseTest.kt b/examples/kotlin-diktat/warn/chapter1/EnumValueSnakeCaseTest.kt index 6aa3ef00b..319b424f3 100644 --- a/examples/kotlin-diktat/warn/chapter1/EnumValueSnakeCaseTest.kt +++ b/examples/kotlin-diktat/warn/chapter1/EnumValueSnakeCaseTest.kt @@ -1,15 +1,16 @@ -package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ +@file:Suppress("PACKAGE_NAME_INCORRECT_PREFIX") -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected) -// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon +package com.saveourtool.save.test.resources.test.paragraph1.naming.enum_ + +// ;warn:5:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected){{.*}} +// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:12:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} enum class EnumValueSnakeCaseTest { - // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f + // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f - // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma + // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} - // ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} } diff --git a/examples/kotlin-diktat/warn/chapter1/GenericFunctionTest.kt b/examples/kotlin-diktat/warn/chapter1/GenericFunctionTest.kt index 5420aa628..22bb156b5 100644 --- a/examples/kotlin-diktat/warn/chapter1/GenericFunctionTest.kt +++ b/examples/kotlin-diktat/warn/chapter1/GenericFunctionTest.kt @@ -1,15 +1,15 @@ -// ;warn:3:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save -// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName +// ;warn:3:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} +// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName{{.*}} package com.saveourtool.diktat.test.paragraph1.naming.generic private class ClassName { private fun lock(body: ((Template?) -> T?)?, value: Template?): T? { try { - // ;warn:10:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected) - // ;warn:10:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:10:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected){{.*}} + // ;warn:10:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableName: Template? = null - // ;warn:13:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT - // ;warn:13:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:13:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT{{.*}} + // ;warn:13:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableT: T? = null println(variableT) return body!!(variableName) @@ -18,7 +18,7 @@ private class ClassName { } } - // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo + // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo{{.*}} fun foo(var1: T, var2: ((T?) -> T?)?) { lock(var2, var1) } diff --git a/examples/kotlin-diktat/warn/chapter1/IgnoreLinesTest/EnumTestDetection.kt b/examples/kotlin-diktat/warn/chapter1/IgnoreLinesTest/EnumTestDetection.kt index b5de76a1b..3eff30912 100644 --- a/examples/kotlin-diktat/warn/chapter1/IgnoreLinesTest/EnumTestDetection.kt +++ b/examples/kotlin-diktat/warn/chapter1/IgnoreLinesTest/EnumTestDetection.kt @@ -1,16 +1,16 @@ package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected) -// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon +// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected){{.*}} +// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} enum class EnumTestDetection { - // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f + // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f - // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma + // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} // ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} } -// ;warn:0:0: [YOU SHOULD NOT SEE THIS] this warning should not be shown +// ;warn:0:0: [YOU SHOULD NOT SEE THIS] this warning should not be shown{{.*}} diff --git a/examples/kotlin-diktat/warn/chapter1/TestMatchOnlyByLineColumn/EnumValueSnakeCaseTest.kt b/examples/kotlin-diktat/warn/chapter1/TestMatchOnlyByLineColumn/EnumValueSnakeCaseTest.kt index 368fc8c3c..336989bb7 100644 --- a/examples/kotlin-diktat/warn/chapter1/TestMatchOnlyByLineColumn/EnumValueSnakeCaseTest.kt +++ b/examples/kotlin-diktat/warn/chapter1/TestMatchOnlyByLineColumn/EnumValueSnakeCaseTest.kt @@ -2,7 +2,7 @@ package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ // ;warn:3:1 // ;warn:6:35 -// ;warn:10:5: This message will be ignored anyway, don't matter what this line contain +// ;warn:10:5: This message will be ignored anyway, don't matter what this line contain{{.*}} enum class EnumValueSnakeCaseTest { // ;warn:$line+1:5 paSC_SAl_l, diff --git a/examples/kotlin-diktat/warn/chapter1/TestResultsFileTest/EnumTestDetection.kt b/examples/kotlin-diktat/warn/chapter1/TestResultsFileTest/EnumTestDetection.kt index ae3341a88..6006920b6 100644 --- a/examples/kotlin-diktat/warn/chapter1/TestResultsFileTest/EnumTestDetection.kt +++ b/examples/kotlin-diktat/warn/chapter1/TestResultsFileTest/EnumTestDetection.kt @@ -1,15 +1,15 @@ package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected) -// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon +// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected){{.*}} +// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} enum class EnumTestDetection { - // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f + // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f - // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma + // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} // ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} } diff --git a/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/EnumTestDetection.kt b/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/EnumTestDetection.kt index ae3341a88..6006920b6 100644 --- a/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/EnumTestDetection.kt +++ b/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/EnumTestDetection.kt @@ -1,15 +1,15 @@ package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected) -// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon +// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected){{.*}} +// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} enum class EnumTestDetection { - // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f + // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f - // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma + // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} // ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} } diff --git a/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/NoMatchingTests/EnumTestDetection.kt b/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/NoMatchingTests/EnumTestDetection.kt index ae3341a88..6006920b6 100644 --- a/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/NoMatchingTests/EnumTestDetection.kt +++ b/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/NoMatchingTests/EnumTestDetection.kt @@ -1,15 +1,15 @@ package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected) -// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon +// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected){{.*}} +// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} enum class EnumTestDetection { - // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f + // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f - // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma + // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} // ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} } diff --git a/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/NoMatchingTests/GenericFunctionTest.kt b/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/NoMatchingTests/GenericFunctionTest.kt index 5420aa628..22bb156b5 100644 --- a/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/NoMatchingTests/GenericFunctionTest.kt +++ b/examples/kotlin-diktat/warn/chapter1/TestsWithRegex/NoMatchingTests/GenericFunctionTest.kt @@ -1,15 +1,15 @@ -// ;warn:3:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save -// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName +// ;warn:3:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} +// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName{{.*}} package com.saveourtool.diktat.test.paragraph1.naming.generic private class ClassName { private fun lock(body: ((Template?) -> T?)?, value: Template?): T? { try { - // ;warn:10:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected) - // ;warn:10:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:10:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected){{.*}} + // ;warn:10:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableName: Template? = null - // ;warn:13:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT - // ;warn:13:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:13:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT{{.*}} + // ;warn:13:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableT: T? = null println(variableT) return body!!(variableName) @@ -18,7 +18,7 @@ private class ClassName { } } - // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo + // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo{{.*}} fun foo(var1: T, var2: ((T?) -> T?)?) { lock(var2, var1) } diff --git a/examples/kotlin-diktat/warn/chapter1/ThisShouldAlwaysFailTest.kt b/examples/kotlin-diktat/warn/chapter1/ThisShouldAlwaysFailTest.kt index cb9319669..976687660 100644 --- a/examples/kotlin-diktat/warn/chapter1/ThisShouldAlwaysFailTest.kt +++ b/examples/kotlin-diktat/warn/chapter1/ThisShouldAlwaysFailTest.kt @@ -1,6 +1,6 @@ package com.saveourtool.save.test.resources.test.paragraph1.naming.enum_ -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: ThisShouldAlwaysFailTest (cannot be auto-corrected) +// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: ThisShouldAlwaysFailTest (cannot be auto-corrected){{.*}} enum class ThisShouldAlwaysFailTest { - // ;warn:8:1: [DUMMY_ERROR] this error should not match + // ;warn:8:1: [DUMMY_ERROR] this error should not match{{.*}} } diff --git a/examples/kotlin-diktat/warn/chapter2/EnumValueSnakeCaseTest.kt b/examples/kotlin-diktat/warn/chapter2/TimeoutTest1.kt similarity index 73% rename from examples/kotlin-diktat/warn/chapter2/EnumValueSnakeCaseTest.kt rename to examples/kotlin-diktat/warn/chapter2/TimeoutTest1.kt index 6aa3ef00b..7f554e1b9 100644 --- a/examples/kotlin-diktat/warn/chapter2/EnumValueSnakeCaseTest.kt +++ b/examples/kotlin-diktat/warn/chapter2/TimeoutTest1.kt @@ -1,15 +1,15 @@ package com.saveourtool.diktat.test.resources.test.paragraph1.naming.enum_ -// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected) -// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect -// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon +// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumValueSnakeCaseTest (cannot be auto-corrected){{.*}} +// ;warn:35: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect{{.*}} +// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon{{.*}} enum class EnumValueSnakeCaseTest { - // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l + // ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l{{.*}} paSC_SAl_l, - // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f + // ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}} PascAsl_f - // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma + // ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma{{.*}} // ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} } diff --git a/examples/kotlin-diktat/warn/chapter2/GenericFunctionTest.kt b/examples/kotlin-diktat/warn/chapter2/TimeoutTest2.kt similarity index 85% rename from examples/kotlin-diktat/warn/chapter2/GenericFunctionTest.kt rename to examples/kotlin-diktat/warn/chapter2/TimeoutTest2.kt index 5420aa628..22bb156b5 100644 --- a/examples/kotlin-diktat/warn/chapter2/GenericFunctionTest.kt +++ b/examples/kotlin-diktat/warn/chapter2/TimeoutTest2.kt @@ -1,15 +1,15 @@ -// ;warn:3:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save -// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName +// ;warn:3:9: [PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: com.saveourtool.save{{.*}} +// ;warn:1:1: [FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: GenericFunctionTest.kt vs ClassName{{.*}} package com.saveourtool.diktat.test.paragraph1.naming.generic private class ClassName { private fun lock(body: ((Template?) -> T?)?, value: Template?): T? { try { - // ;warn:10:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected) - // ;warn:10:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:10:13: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: is declared on line <10> and is used for the first time on line <15> (cannot be auto-corrected){{.*}} + // ;warn:10:43: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableName: Template? = null - // ;warn:13:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT - // ;warn:13:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected) + // ;warn:13:17: [VARIABLE_NAME_INCORRECT_FORMAT] variable name should be in lowerCamelCase and should contain only latin (ASCII) letters or numbers and should start from lower letter: variableT{{.*}} + // ;warn:13:33: [NULLABLE_PROPERTY_TYPE] try to avoid use of nullable types: initialize explicitly (cannot be auto-corrected){{.*}} val variableT: T? = null println(variableT) return body!!(variableName) @@ -18,7 +18,7 @@ private class ClassName { } } - // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo + // ;warn:21:5: [MISSING_KDOC_ON_FUNCTION] all public, internal and protected functions should have Kdoc with proper tags: foo{{.*}} fun foo(var1: T, var2: ((T?) -> T?)?) { lock(var2, var1) } diff --git a/gradle.properties b/gradle.properties index edf424555..ff90fc38d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,4 +13,4 @@ kotlin.mpp.stability.nowarn=true kotlin.native.cacheKind.linuxX64=none kotlin.mpp.hierarchicalStructureSupport=true # making custom cinterop libraries available in shared source sets -kotlin.mpp.enableCInteropCommonization=true +kotlin.mpp.enableCInteropCommonization=true \ No newline at end of file diff --git a/save-cli/build.gradle.kts b/save-cli/build.gradle.kts index 92429d54c..f6530466c 100644 --- a/save-cli/build.gradle.kts +++ b/save-cli/build.gradle.kts @@ -84,7 +84,6 @@ kotlin { tasks.withType().configureEach { dependsOn(":save-core:downloadTestResources") - dependsOn(":save-core:downloadOldTestResources") } // disable building of some binaries to speed up build diff --git a/save-cli/src/jvmTest/kotlin/com/saveourtool/save/cli/GeneralTest.kt b/save-cli/src/jvmTest/kotlin/com/saveourtool/save/cli/GeneralTest.kt index 5b033fa0d..b7d5e9106 100644 --- a/save-cli/src/jvmTest/kotlin/com/saveourtool/save/cli/GeneralTest.kt +++ b/save-cli/src/jvmTest/kotlin/com/saveourtool/save/cli/GeneralTest.kt @@ -62,8 +62,8 @@ class GeneralTest { assertTrue(fs.exists(destination)) // Check for existence of diktat and ktlint - assertTrue(fs.exists((examplesDir.toPath() / "diktat-old.jar"))) - assertTrue(fs.exists((examplesDir.toPath() / "ktlint-old"))) + assertTrue(fs.exists((examplesDir.toPath() / "diktat.jar"))) + assertTrue(fs.exists((examplesDir.toPath() / "ktlint"))) // Make sure, that we will check report, which will be obtained after current execution; remove old report if exist val reportFile = examplesDir.toPath() / "save.out.json".toPath() @@ -95,7 +95,6 @@ class GeneralTest { reports.forEach { report -> report.pluginExecutions.forEach { pluginExecution -> pluginExecution.testResults.find { result -> - println(result.status) // FixMe: if we will have other failing tests - we will make the logic less hardcoded result.resources.test.name != "GarbageTest.kt" && result.resources.test.name != "ThisShouldAlwaysFailTest.kt" && diff --git a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/config/TestConfig.kt b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/config/TestConfig.kt index a5ecadae2..9ddf67919 100644 --- a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/config/TestConfig.kt +++ b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/config/TestConfig.kt @@ -146,8 +146,8 @@ data class TestConfig( .filter { plugin -> plugin.discoverTestFiles(directory).any().also { isNotEmpty -> if (!isNotEmpty) { - logDebug("Plugin <${plugin::class.simpleName}> in config file ${plugin.testConfig.location} has no test resources; " + - "it's config will only be used for inheritance") + logDebug("Plugin <${plugin::class.simpleName}> in config file ${plugin.testConfig.location} has no test resources in the same directory; " + + "it's config will only be used for inheritance of configuration to nested test suites") } } } @@ -165,10 +165,10 @@ data class TestConfig( * @return merged test config */ fun mergeConfigWithParents(): TestConfig { - logDebug("Start merging configs for ${this.location}") + logDebug("Merging configs (with parental configs from higher directory level) for ${this.location}") this.parentConfigs().toList().forEach { parentConfig -> - logTrace("Processing config ${parentConfig.location} for merging with ${this.location}") + logTrace("Using parental config ${parentConfig.location} to merge it with child config: ${this.location}") // return from the function if we stay at the root element of the plugin tree val parentalPlugins = parentConfig.pluginConfigs parentalPlugins.forEach { parentalPluginConfig -> @@ -179,11 +179,10 @@ data class TestConfig( } else { // else, we will merge plugin with a corresponding plugin from a parent config // we expect that there is only one plugin of such type, otherwise we will throw an exception - logTrace("Starting actual merge of ${parentalPluginConfig.type} from ${parentConfig.location} into $location") + logTrace("Starting merging process of ${parentalPluginConfig.type} from ${parentConfig.location} into $location") val mergedConfig = childConfigs.single().mergeWith(parentalPluginConfig) - logTrace("Finished actual merge of ${parentalPluginConfig.type} from ${parentConfig.location} into $location") + logTrace("Finished merging process of ${parentalPluginConfig.type} from ${parentConfig.location} into $location") this.pluginConfigs.set(this.pluginConfigs.indexOf(childConfigs.single()), mergedConfig) - logTrace("Added merged config ${parentalPluginConfig.type} from ${parentConfig.location} into $location") } } } @@ -194,10 +193,11 @@ data class TestConfig( * Method, which validates all plugin configs and set default values, if possible */ fun validateAndSetDefaults() { - logDebug("Start plugin validation for $location") pluginConfigs.forEachIndexed { index, config -> pluginConfigs[index] = config.validateAndSetDefaults() } + logDebug("Validated plugin configuration for [$location] " + + "(${pluginConfigs.map { it.type }.filterNot { it == TestConfigSections.GENERAL }})") } } diff --git a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/plugin/Plugin.kt b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/plugin/Plugin.kt index 0b5308706..d0ac9f123 100644 --- a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/plugin/Plugin.kt +++ b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/plugin/Plugin.kt @@ -116,9 +116,10 @@ abstract class Plugin( } } }.toList() - val notFoundTests = testFiles.filter { testFile -> testFile !in foundTests.map { foundTest -> foundTest.test.toString() } } - if (notFoundTests.isNotEmpty()) { - logDebug("The following tests were not found: $notFoundTests. Try to make sure you have specified the correct relative path to the files.") + val foundTestsInDir = foundTests.filter { testFile -> testFile.test.toString() in testFiles } + if (foundTests.isNotEmpty()) { + logDebug("Following tests have been detected for the current plugin and directory: " + + "${foundTestsInDir.map { it.test.toString() } }. ") } return foundTests.asSequence() } else { diff --git a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/ProcessBuilder.kt b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/ProcessBuilder.kt index 48ec3bc3e..610d084c5 100644 --- a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/ProcessBuilder.kt +++ b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/ProcessBuilder.kt @@ -115,8 +115,10 @@ class ProcessBuilder(private val useInternalRedirections: Boolean, private val f fs.deleteRecursively(tmpDir) logErrorAndThrowProcessBuilderException(ex.message ?: "Couldn't execute $cmd") } + val stdout = fs.readLines(stdoutFile) val stderr = fs.readLines(stderrFile) + fs.myDeleteRecursively(tmpDir) logTrace("Removed temp directory $tmpDir") if (stderr.isNotEmpty()) { diff --git a/save-core/build.gradle.kts b/save-core/build.gradle.kts index d81067ec0..b04a11910 100644 --- a/save-core/build.gradle.kts +++ b/save-core/build.gradle.kts @@ -71,23 +71,6 @@ tasks.withType>().forEach { it.dependsOn(generateVersionFileTaskProvider) } -tasks.register("downloadOldTestResources") { - src(listOf( - Versions.IntegrationTest.oldKtlintLink, - Versions.IntegrationTest.oldDiktatLink, - )) - dest("../examples/kotlin-diktat") - doLast { - file("../examples/kotlin-diktat/diktat-${Versions.IntegrationTest.oldDiktat}.jar").renameTo( - file("../examples/kotlin-diktat/diktat-old.jar") - ) - - file("../examples/kotlin-diktat/ktlint").renameTo( - file("../examples/kotlin-diktat/ktlint-old") - ) - } -} - tasks.register("downloadTestResources") { src(listOf( Versions.IntegrationTest.ktlintLink, @@ -105,14 +88,11 @@ val cleanupTask = tasks.register("cleanupTestResources") { this.dependsOn(":save-cli:jvmTest") mustRunAfter(tasks.withType()) doFirst { - file("../examples/kotlin-diktat/ktlint-old").delete() file("../examples/kotlin-diktat/ktlint").delete() - file("../examples/kotlin-diktat/diktat-old.jar").delete() file("../examples/kotlin-diktat/diktat.jar").delete() } } tasks.withType().configureEach { dependsOn("downloadTestResources") - dependsOn("downloadOldTestResources") finalizedBy("cleanupTestResources") } diff --git a/save-core/src/commonNonJsTest/kotlin/com/saveourtool/save/core/test/utils/TestUtilsCommon.kt b/save-core/src/commonNonJsTest/kotlin/com/saveourtool/save/core/test/utils/TestUtilsCommon.kt index 498f83267..787327234 100644 --- a/save-core/src/commonNonJsTest/kotlin/com/saveourtool/save/core/test/utils/TestUtilsCommon.kt +++ b/save-core/src/commonNonJsTest/kotlin/com/saveourtool/save/core/test/utils/TestUtilsCommon.kt @@ -11,6 +11,7 @@ import com.saveourtool.save.core.config.LogType import com.saveourtool.save.core.config.OutputStreamType import com.saveourtool.save.core.config.ReportType import com.saveourtool.save.core.config.SaveProperties +import com.saveourtool.save.core.logging.logType import com.saveourtool.save.core.result.Fail import com.saveourtool.save.core.result.Ignored import com.saveourtool.save.core.result.Pass @@ -50,15 +51,17 @@ fun runTestsWithDiktat( mutableTestDir.add(0, "../examples/kotlin-diktat/") val saveProperties = SaveProperties( - logType = LogType.ALL, testFiles = mutableTestDir, reportType = ReportType.TEST, resultOutput = OutputStreamType.STDOUT, ).apply { addProperties() } + + // logger is not set from save properties without a config reader, need to set it explicily + logType.set(LogType.ALL) // In this test we need to merge with emulated empty save.properties file in aim to use default values, // since initially all fields are null - val testReporter = Save(saveProperties.mergeConfigWithPriorityToThis(SaveProperties()), FileSystem.SYSTEM) - .performAnalysis() as TestReporter + val save = Save(saveProperties.mergeConfigWithPriorityToThis(SaveProperties()), FileSystem.SYSTEM) + val testReporter = save.performAnalysis() as TestReporter assertEquals(numberOfTests, testReporter.results.size) testReporter.results.forEach { test -> diff --git a/save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/utils/StringUtils.kt b/save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/utils/StringUtils.kt index c702b5089..1c7ec165b 100644 --- a/save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/utils/StringUtils.kt +++ b/save-plugins/warn-plugin/src/commonMain/kotlin/com/saveourtool/save/plugin/warn/utils/StringUtils.kt @@ -19,21 +19,26 @@ fun String.findDelimitedSubStringsWith(openingDelimiter: String, closingDelimite // finding first delimited group in the initial string var delimitedGroup = this.findFirstDelimitedSubStringBy(openingDelimiter, closingDelimiter) var nextPartOfString = this - val result = if (delimitedGroup != delimiterNotFound) mutableMapOf(delimitedGroup) else mutableMapOf() - while (true) { - // offset that is used to restore indexes in the initial string (as the logic below is applied to substring) - val offset = delimitedGroup.second + closingDelimiter.length - // substring without a part of a string that was already processed (shifted by offset) - nextPartOfString = nextPartOfString.substring(offset, nextPartOfString.length) - delimitedGroup = nextPartOfString.findFirstDelimitedSubStringBy(openingDelimiter, closingDelimiter) - // no need to process if there are no delimiters in the substring - if (delimitedGroup == delimiterNotFound) { - break + // offset that is used to restore indexes in the initial string (as the logic below is applied to substring) + var offset = delimitedGroup.second + closingDelimiter.length + + return if (delimitedGroup == delimiterNotFound) { + mutableMapOf() + } else { + val result = mutableMapOf(delimitedGroup) + while (true) { + // substring without a part of a string that was already processed (shifted by offset) + nextPartOfString = nextPartOfString.substring(delimitedGroup.second + closingDelimiter.length, nextPartOfString.length) + delimitedGroup = nextPartOfString.findFirstDelimitedSubStringBy(openingDelimiter, closingDelimiter) + if (delimitedGroup == delimiterNotFound) { + break + } + result[offset + delimitedGroup.first] = offset + delimitedGroup.second + // updating the offset for + offset += delimitedGroup.second + closingDelimiter.length } - result[offset + delimitedGroup.first] = offset + delimitedGroup.second + result } - - return result } /** @@ -41,6 +46,8 @@ fun String.findDelimitedSubStringsWith(openingDelimiter: String, closingDelimite * For example, if openingDelimiter = ( , closingDelimiter = ) , this = aaa(bbb)ccc(eee) => * method will return indexes delimited string (start inclusive, end exclusive) - bbb - Pair(4, 6), counted from 0. * + * WHY NOT TO USE: `substringAfter("{").substringBefore("}")`? Because we need to raise proper error during parsing + * * Returns DELIMITER_NOT_FOUND - Pair(-1, -1) if no opening/closing group found * * @param openingDelimiter opening group of symbols that is used to separate pattern diff --git a/save-plugins/warn-plugin/src/commonNonJsTest/kotlin/com/saveourtool/save/plugin/warn/utils/StringUtilsTest.kt b/save-plugins/warn-plugin/src/commonNonJsTest/kotlin/com/saveourtool/save/plugin/warn/utils/StringUtilsTest.kt index efb476252..e0b6a40ed 100644 --- a/save-plugins/warn-plugin/src/commonNonJsTest/kotlin/com/saveourtool/save/plugin/warn/utils/StringUtilsTest.kt +++ b/save-plugins/warn-plugin/src/commonNonJsTest/kotlin/com/saveourtool/save/plugin/warn/utils/StringUtilsTest.kt @@ -56,4 +56,18 @@ class StringUtilsTest { expected = "B BBB" assertTrue { regex.matches(expected) } } + + @Test + @Suppress("SAY_NO_TO_VAR") + fun `regression with regular expressions`() { + var test = "aaa{{ should }}bbb{{ UPPER_CASE }}ccc{{.*}}" + var regex = test.createRegexFromString("{{", "}}") + + assertTrue { regex.matches("aaa should bbb UPPER_CASE ccc TESTTEST]]]") } + + test = "[ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f{{.*}}" + regex = test.createRegexFromString("{{", "}}") + + assertTrue { regex.matches("[ENUM_VALUE] enum values should be in selected UPPER_CASE snake/PascalCase format: PascAsl_f{{.*}}") } + } }