Repository: analysis-dev/diktat (kotlin)

Issue:
src directory is not found in file path <...>/build.gradle.kts
## Describe the bug
This message is true, but we shouldn't log it. We have some special handling of gradle scripts, and it should include legal absence of src directory

## Environment information
* diktat version: 1.0.0-rc.2
* build tool (maven/gradle): gradle

Pull request:
### What's done:
* Removed code
* Fixed docs

This pull request closes #971

Patch:
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-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<RulesConfig>) : 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 <src> 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<RulesConfig>) : 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<RulesConfig>) : 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<RulesConfig>) : 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<String> = 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<String> =
+        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<String> =
-        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/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<br>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<br>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<br>Fix: moves this KDoc                                                                           |  yes  |  no  | |
-|    3  |     3.1.1  |  FILE_IS_TOO_LONG                         |  Check: warns if file has too many lines<br>Fix: no                                                                                                                            |   no  |  maxSize<br> ignoreFolders  |                                                                                      - |
+|    3  |     3.1.1  |  FILE_IS_TOO_LONG                         |  Check: warns if file has too many lines<br>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.<br>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.<br>Fix: leaves single empty line                                                                      |  yes  |  no  |                                                                                      - |


Test patch:
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/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<RulesConfig> = listOf(
-        RulesConfig(Warnings.FILE_IS_TOO_LONG.name, true,
-            mapOf("maxSize" to "5", "ignoreFolders" to "main"))
-    )
     private val rulesConfigListEmpty: List<RulesConfig> = listOf(
         RulesConfig(Warnings.FILE_IS_TOO_LONG.name, true,
             emptyMap())
     )
-    private val rulesConfigListOnlyIgnore: List<RulesConfig> = listOf(
-        RulesConfig(Warnings.FILE_IS_TOO_LONG.name, true,
-            mapOf("ignoreFolders" to "A"))
-    )
-    private val rulesConfigListTwoIgnoreFolders: List<RulesConfig> = 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
-    }
 }