From aee9fb2061de398ccea8bd32c1add620dd84d8bf Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Fri, 16 Jul 2021 16:21:27 +0300 Subject: [PATCH 1/3] Remove ignoreFolders option from FileSize rule (#981) ### What's done: * Removed code * Fixed docs --- diktat-analysis.yml | 1 - .../src/test/resources/test-rules-config.yml | 1 - .../ruleset/rules/chapter1/PackageNaming.kt | 6 +-- .../ruleset/rules/chapter3/files/FileSize.kt | 22 ++------ .../cqfn/diktat/ruleset/utils/FileUtils.kt | 31 +++++++++++ .../cqfn/diktat/ruleset/utils/StringUtils.kt | 24 --------- .../main/resources/diktat-analysis-huawei.yml | 1 - .../src/main/resources/diktat-analysis.yml | 1 - .../ruleset/chapter3/FileSizeWarnTest.kt | 52 ------------------- info/available-rules.md | 2 +- 10 files changed, 38 insertions(+), 103 deletions(-) create mode 100644 diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/FileUtils.kt diff --git a/diktat-analysis.yml b/diktat-analysis.yml index e893badf57..b0c040c1f6 100644 --- a/diktat-analysis.yml +++ b/diktat-analysis.yml @@ -148,7 +148,6 @@ configuration: # number of lines maxSize: '2000' - ignoreFolders: '' # Checks that file does not contain commented out code - name: COMMENTED_OUT_CODE enabled: true diff --git a/diktat-common/src/test/resources/test-rules-config.yml b/diktat-common/src/test/resources/test-rules-config.yml index d2ae232fa9..44b8b1dab6 100644 --- a/diktat-common/src/test/resources/test-rules-config.yml +++ b/diktat-common/src/test/resources/test-rules-config.yml @@ -95,7 +95,6 @@ enabled: true configuration: maxSize: '2000' - ignoreFolders: '' - name: COMMENTED_OUT_CODE enabled: true - name: FILE_CONTAINS_ONLY_COMMENTS 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 2a43bdec9e..ca0d755ff7 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 @@ -116,8 +116,8 @@ class PackageNaming(configRules: List) : DiktatRule( val filePathParts = fileName.splitPathToDirs() return if (!filePathParts.contains(PACKAGE_PATH_ANCHOR)) { - log.error("Not able to determine a path to a scanned file or src directory cannot be found in it's path." + - " Will not be able to determine correct package name. It can happen due to missing directory in the path") + log.error("Not able to determine a path to a scanned file or \"$PACKAGE_PATH_ANCHOR\" directory cannot be found in it's path." + + " Will not be able to determine correct package name. It can happen due to missing <$PACKAGE_PATH_ANCHOR> directory in the path") emptyList() } else { // creating a real package name: @@ -276,7 +276,7 @@ class PackageNaming(configRules: List) : DiktatRule( /** * Directory which is considered the start of sources file tree */ - const val PACKAGE_PATH_ANCHOR = "src" + const val PACKAGE_PATH_ANCHOR = SRC_DIRECTORY_NAME /** * Symbol that is used to separate parts in package name 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 64b8ec6901..d140e553e2 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 @@ -5,7 +5,9 @@ import org.cqfn.diktat.common.config.rules.RulesConfig import org.cqfn.diktat.common.config.rules.getRuleConfig import org.cqfn.diktat.ruleset.constants.Warnings.FILE_IS_TOO_LONG import org.cqfn.diktat.ruleset.rules.DiktatRule +import org.cqfn.diktat.ruleset.utils.SRC_DIRECTORY_NAME import org.cqfn.diktat.ruleset.utils.getFilePath +import org.cqfn.diktat.ruleset.utils.isGradleScript import org.cqfn.diktat.ruleset.utils.splitPathToDirs import com.pinterest.ktlint.core.ast.ElementType @@ -27,16 +29,7 @@ class FileSize(configRules: List) : DiktatRule( override fun logic(node: ASTNode) { if (node.elementType == ElementType.FILE) { - val filePathParts = node.getFilePath().splitPathToDirs() - if (SRC_PATH !in filePathParts) { - log.error("$SRC_PATH directory is not found in file path ${node.getFilePath()}") - } else { - if (configuration.ignoreFolders.none { - filePathParts.containsAll(it.splitPathToDirs()) - }) { - checkFileSize(node, configuration.maxSize) - } - } + checkFileSize(node, configuration.maxSize) } } @@ -58,18 +51,9 @@ class FileSize(configRules: List) : DiktatRule( * Maximum allowed number of lines in a file */ val maxSize = config["maxSize"]?.toLongOrNull() ?: MAX_SIZE - - /** - * List of folders, files from which are ignored during the check. For example, for tests. - */ - val ignoreFolders = config["ignoreFolders"]?.replace("\\s+".toRegex(), "")?.split(IGNORE_FOLDERS_SEPARATOR) ?: ignoreFolder } companion object { - private val log = LoggerFactory.getLogger(FileSize::class.java) - const val IGNORE_FOLDERS_SEPARATOR = "," const val MAX_SIZE = 2000L - const val SRC_PATH = "src" - private val ignoreFolder: List = emptyList() } } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/FileUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/FileUtils.kt new file mode 100644 index 0000000000..29343a7f2d --- /dev/null +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/FileUtils.kt @@ -0,0 +1,31 @@ +/** + * Utility methods to work with file paths. + */ + +package org.cqfn.diktat.ruleset.utils + +internal const val SRC_DIRECTORY_NAME = "src" + +/** + * Splits [this] string by file path separator + * + * @return list of path parts + */ +fun String.splitPathToDirs(): List = + this.replace("\\", "/") + .replace("//", "/") + .split("/") + +/** + * Checks if [this] String is a name of a kotlin script file by checking whether file extension equals 'kts' + * + * @return true if this is a kotlin script file name, false otherwise + */ +fun String.isKotlinScript() = endsWith(".kts") + +/** + * Checks if [this] String is a name of a gradle kotlin script file by checking whether file extension equals 'gradle.kts' + * + * @return true if this is a gradle kotlin script file name, false otherwise + */ +fun String.isGradleScript() = endsWith("gradle.kts") diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringUtils.kt index 259fad1a7b..e414ad41c7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringUtils.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/StringUtils.kt @@ -58,16 +58,6 @@ fun String.containsOneLetterOrZero(): Boolean { return count == 1 || count == 0 } -/** - * Splits [this] string by file path separator - * - * @return list of path parts - */ -fun String.splitPathToDirs(): List = - this.replace("\\", "/") - .replace("//", "/") - .split("/") - /** * method checks that string has prefix like: * mFunction, kLength or M_VAR @@ -105,17 +95,3 @@ fun String.removePrefix(): String { } return this } - -/** - * Checks if [this] String is a name of a kotlin script file by checking whether file extension equals 'kts' - * - * @return true if this is a kotlin script file name, false otherwise - */ -fun String.isKotlinScript() = endsWith(".kts") - -/** - * Checks if [this] String is a name of a gradle kotlin script file by checking whether file extension equals 'gradle.kts' - * - * @return true if this is a gradle kotlin script file name, false otherwise - */ -fun String.isGradleScript() = endsWith("gradle.kts") diff --git a/diktat-rules/src/main/resources/diktat-analysis-huawei.yml b/diktat-rules/src/main/resources/diktat-analysis-huawei.yml index 4d85d15adf..4fad2669f5 100644 --- a/diktat-rules/src/main/resources/diktat-analysis-huawei.yml +++ b/diktat-rules/src/main/resources/diktat-analysis-huawei.yml @@ -148,7 +148,6 @@ configuration: # number of lines maxSize: '2000' - ignoreFolders: '' # Checks that file does not contain commented out code - name: COMMENTED_OUT_CODE enabled: true diff --git a/diktat-rules/src/main/resources/diktat-analysis.yml b/diktat-rules/src/main/resources/diktat-analysis.yml index 41b41375b3..328db72ddc 100644 --- a/diktat-rules/src/main/resources/diktat-analysis.yml +++ b/diktat-rules/src/main/resources/diktat-analysis.yml @@ -148,7 +148,6 @@ configuration: # number of lines maxSize: '2000' - ignoreFolders: '' # Checks that file does not contain commented out code - name: COMMENTED_OUT_CODE enabled: true diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/FileSizeWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/FileSizeWarnTest.kt index c94418d858..75e78ce379 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/FileSizeWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/FileSizeWarnTest.kt @@ -22,30 +22,10 @@ class FileSizeWarnTest : LintTestBase(::FileSize) { RulesConfig(Warnings.FILE_IS_TOO_LONG.name, true, mapOf("maxSize" to "10")) ) - private val rulesConfigListIgnore: List = listOf( - RulesConfig(Warnings.FILE_IS_TOO_LONG.name, true, - mapOf("maxSize" to "5", "ignoreFolders" to "main")) - ) private val rulesConfigListEmpty: List = listOf( RulesConfig(Warnings.FILE_IS_TOO_LONG.name, true, emptyMap()) ) - private val rulesConfigListOnlyIgnore: List = listOf( - RulesConfig(Warnings.FILE_IS_TOO_LONG.name, true, - mapOf("ignoreFolders" to "A")) - ) - private val rulesConfigListTwoIgnoreFolders: List = listOf( - RulesConfig(Warnings.FILE_IS_TOO_LONG.name, true, - mapOf("maxSize" to "8", "ignoreFolders" to "A, B")) - ) - - @Test - @Tag(WarningNames.FILE_IS_TOO_LONG) - fun `file larger then max with ignore`() { - val path = javaClass.classLoader.getResource("test/paragraph3/src/main/FileSizeLarger.kt") - val file = File(path!!.file) - lintMethod(file.readText(), fileName = file.absolutePath, rulesConfigList = rulesConfigListIgnore) - } @Test @Tag(WarningNames.FILE_IS_TOO_LONG) @@ -91,42 +71,10 @@ class FileSizeWarnTest : LintTestBase(::FileSize) { fileName = file.absolutePath, rulesConfigList = rulesConfigListLarge) } - @Test - @Tag(WarningNames.FILE_IS_TOO_LONG) - fun `config has only ignoreFolders`() { - val path = javaClass.classLoader.getResource("test/paragraph3/src/main/A/FileSize2000.kt") - val file = File(path!!.file) - lintMethod(file.readText(), fileName = file.absolutePath, rulesConfigList = rulesConfigListOnlyIgnore) - } - private fun generate2000lines(): Int { val path = javaClass.classLoader.getResource("test/paragraph3/src/main/A/FileSize2000.kt") val file = File(path!!.file) file.writeText("//hello \n".repeat(2000)) return 2000 } - - @Test - @Tag(WarningNames.FILE_IS_TOO_LONG) - @Suppress("SAY_NO_TO_VAR") - fun `ignoring two out of three folders`() { - var path = javaClass.classLoader.getResource("test/paragraph3/src/main/A/FileSizeA.kt") - var file = File(path!!.file) - lintMethod(file.readText(), fileName = file.absolutePath, rulesConfigList = rulesConfigListTwoIgnoreFolders) - path = javaClass.classLoader.getResource("test/paragraph3/src/main/B/FileSizeB.kt") - file = File(path!!.file) - lintMethod(file.readText(), fileName = file.absolutePath, rulesConfigList = rulesConfigListTwoIgnoreFolders) - path = javaClass.classLoader.getResource("test/paragraph3/src/main/C/FileSizeC.kt") - file = File(path!!.file) - val size = SIZE - lintMethod(file.readText(), - LintError(1, 1, "$DIKTAT_RULE_SET_ID:file-size", - "${Warnings.FILE_IS_TOO_LONG.warnText()} $size", false), - fileName = file.absolutePath, - rulesConfigList = rulesConfigListTwoIgnoreFolders) - } - - companion object { - private const val SIZE = 10 - } } diff --git a/info/available-rules.md b/info/available-rules.md index 7f47f2d701..915eaa47f1 100644 --- a/info/available-rules.md +++ b/info/available-rules.md @@ -53,7 +53,7 @@ | 2 | 2.4.1 | FIRST_COMMENT_NO_BLANK_LINE | Check: warns if there is a new line before first comment
Fix: deletes a new line | yes | no | - | | 2 | 2.4.1 | IF_ELSE_COMMENTS | Check: warns if there is a comment not in the else block
Fix: adds the comment to the first line in else block | yes | no | - | | 2 | 2.2.1 | HEADER_NOT_BEFORE_PACKAGE | Check: warns if header KDoc if file is located not before package directive
Fix: moves this KDoc | yes | no | | -| 3 | 3.1.1 | FILE_IS_TOO_LONG | Check: warns if file has too many lines
Fix: no | no | maxSize
ignoreFolders | - | +| 3 | 3.1.1 | FILE_IS_TOO_LONG | Check: warns if file has too many lines
Fix: no | no | maxSize | - | | 3 | 3.1.2 | FILE_CONTAINS_ONLY_COMMENTS | Check: warns if file contains only comments, imports and package directive. | no | no | - | | 3 | 3.1.2 | FILE_INCORRECT_BLOCKS_ORDER | Check: warns if general order of code parts is wrong.
Fix: rearranges them. | yes | no | handle other elements that could be present before package directive (other comments) | | 3 | 3.1.2 | FILE_NO_BLANK_LINE_BETWEEN_BLOCKS | Check: warns if there is not exactly one blank line between code parts.
Fix: leaves single empty line | yes | no | - | From 3f8f0e6789058a34a529258036c5b5b4fb456d28 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Jul 2021 17:05:25 +0300 Subject: [PATCH 2/3] Bump dokka-maven-plugin from 1.4.32 to 1.5.0 (#976) Bumps [dokka-maven-plugin](https://github.com/Kotlin/dokka) from 1.4.32 to 1.5.0. - [Release notes](https://github.com/Kotlin/dokka/releases) - [Commits](https://github.com/Kotlin/dokka/compare/v1.4.32...v1.5.0) --- updated-dependencies: - dependency-name: org.jetbrains.dokka:dokka-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Peter Trifanov --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e420bcf5bc..b9312a5c17 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ 1.0.0-rc.2 1.9.0 1.17.1 - 1.4.32 + 1.5.0 0.8.7 3.6.1 1.23 From 502baa7a84cd96f7ceab78d88da6d73a01f4bd0c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Jul 2021 17:09:01 +0300 Subject: [PATCH 3/3] Bump kotlinx-serialization-json-jvm from 1.2.1 to 1.2.2 (#977) Bumps [kotlinx-serialization-json-jvm](https://github.com/Kotlin/kotlinx.serialization) from 1.2.1 to 1.2.2. - [Release notes](https://github.com/Kotlin/kotlinx.serialization/releases) - [Changelog](https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md) - [Commits](https://github.com/Kotlin/kotlinx.serialization/compare/v1.2.1...v1.2.2) --- updated-dependencies: - dependency-name: org.jetbrains.kotlinx:kotlinx-serialization-json-jvm dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Andrey Kuleshov Co-authored-by: Peter Trifanov --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b9312a5c17..af4df4e38c 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ UTF-8 1.5.20 true - 1.2.1 + 1.2.2 0.39.0 5.7.2 30.1.1-jre