diff --git a/diktat-analysis.yml b/diktat-analysis.yml index c92be347a0..e69bed6725 100644 --- a/diktat-analysis.yml +++ b/diktat-analysis.yml @@ -228,6 +228,13 @@ - name: WRONG_MULTIPLE_MODIFIERS_ORDER enabled: true configuration: {} +- name: CONFUSING_IDENTIFIER_NAMING + enabled: true + configuration: {} +- name: WRONG_COPYRIGHT_YEAR + enabled: true + configuration: {} +# Inspection that checks if local variables are declared close to the first usage site - name: LOCAL_VARIABLE_EARLY_DECLARATION enabled: true configuration: {} diff --git a/diktat-rules/src/main/resources/diktat-analysis-huawei.yml b/diktat-rules/src/main/resources/diktat-analysis-huawei.yml index befbf9d4bf..eca4c8ac5f 100644 --- a/diktat-rules/src/main/resources/diktat-analysis-huawei.yml +++ b/diktat-rules/src/main/resources/diktat-analysis-huawei.yml @@ -228,6 +228,13 @@ - name: WRONG_MULTIPLE_MODIFIERS_ORDER enabled: true configuration: {} +- name: CONFUSING_IDENTIFIER_NAMING + enabled: true + configuration: {} +- name: WRONG_COPYRIGHT_YEAR + enabled: true + configuration: {} +# Inspection that checks if local variables are declared close to the first usage site - name: LOCAL_VARIABLE_EARLY_DECLARATION enabled: true configuration: {} diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigJsonTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigJsonTest.kt deleted file mode 100644 index b31465a95b..0000000000 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigJsonTest.kt +++ /dev/null @@ -1,53 +0,0 @@ -package org.cqfn.diktat.ruleset.utils - -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import org.cqfn.diktat.common.config.rules.RulesConfig -import org.cqfn.diktat.common.config.rules.RulesConfigReader -import org.cqfn.diktat.common.config.rules.getRuleConfig -import org.cqfn.diktat.ruleset.constants.Warnings -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test - -/** - * Special test that checks that developer has not forgotten to add his warning to a diktat-analysis.yml - * This file is needed to be in tact with latest changes in Warnings.kt - */ -class RulesConfigJsonTest { - @Test - fun `read rules config json`() { - val allRulesFromConfig = readAllRulesFromConfig() - val allRulesFromCode = readAllRulesFromCode() - - allRulesFromCode.forEach { rule -> - val foundRule = allRulesFromConfig.getRuleConfig(rule) - val jsonCodeSnippet = RulesConfig(rule.ruleName(), true, mapOf()) - val jacksonMapper = jacksonObjectMapper() - - val ruleJson = jacksonMapper.writeValueAsString(jsonCodeSnippet) - Assertions.assertTrue(foundRule != null) { - """ - Cannot find warning ${rule.ruleName()} in rules-config.json. - You can fix it by adding the following code below to rules-config.json: - $ruleJson - """ - } - } - - allRulesFromConfig.forEach { warning -> - val warningName = warning.name - val ruleFound = allRulesFromCode.find { it.ruleName() == warningName || warningName == "DIKTAT_COMMON" } != null - Assertions.assertTrue(ruleFound) { - """ - Found rule (warning) in rules-config.json: <$warningName> that does not exist in the code. Misprint or configuration was renamed? - """.trimIndent() - } - } - } - - private fun readAllRulesFromConfig() = - RulesConfigReader(javaClass.classLoader) - .readResource("diktat-analysis.yml") ?: listOf() - - private fun readAllRulesFromCode() = - Warnings.values() -} diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt new file mode 100644 index 0000000000..e4d8bbc766 --- /dev/null +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt @@ -0,0 +1,67 @@ +package org.cqfn.diktat.ruleset.utils + +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.cqfn.diktat.common.config.rules.RulesConfig +import org.cqfn.diktat.common.config.rules.RulesConfigReader +import org.cqfn.diktat.common.config.rules.getRuleConfig +import org.cqfn.diktat.ruleset.constants.Warnings +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import java.io.File + +/** + * Special test that checks that developer has not forgotten to add his warning to a diktat-analysis.yml + * This file is needed to be in tact with latest changes in Warnings.kt + */ +class RulesConfigYamlTest { + + private val pathMap = mapOf("diktat-analysis.yml" to "diKTat/diktat-rules/src/main/resources/diktat-analysis.yml", + "diktat-analysis-huawei.yml" to "diKTat/diktat-rules/src/main/resources/diktat-analysis-huawei.yml", + "parent/diktat-analysis.yml" to "diKTat/diktat-analysis.yml") + + @Test + fun `read rules config yml`() { + compareRulesAndConfig("diktat-analysis.yml") + compareRulesAndConfig("diktat-analysis-huawei.yml") + val thirdConfig = "${System.getProperty("user.dir")}${File.separator}..${File.separator}diktat-analysis.yml${File.separator}" + compareRulesAndConfig(thirdConfig, "parent/diktat-analysis.yml") + } + + private fun compareRulesAndConfig(nameConfig: String, nameConfigToText: String? = null) { + val filePath = if (nameConfigToText != null) pathMap[nameConfigToText] else pathMap[nameConfig] + val allRulesFromConfig = readAllRulesFromConfig(nameConfig) + val allRulesFromCode = readAllRulesFromCode() + + allRulesFromCode.forEach { rule -> + val foundRule = allRulesFromConfig.getRuleConfig(rule) + val ymlCodeSnippet = RulesConfig(rule.ruleName(), true, mapOf()) + val jacksonMapper = jacksonObjectMapper() + + val ruleYaml = jacksonMapper.writeValueAsString(ymlCodeSnippet) + Assertions.assertTrue(foundRule != null) { + """ + Cannot find warning ${rule.ruleName()} in $filePath. + You can fix it by adding the following code below to $filePath: + $ruleYaml + """ + } + } + + allRulesFromConfig.forEach { warning -> + val warningName = warning.name + val ruleFound = allRulesFromCode.find { it.ruleName() == warningName || warningName == "DIKTAT_COMMON" } != null + Assertions.assertTrue(ruleFound) { + """ + Found rule (warning) in $filePath: <$warningName> that does not exist in the code. Misprint or configuration was renamed? + """.trimIndent() + } + } + } + + private fun readAllRulesFromConfig(nameConfig: String) = + RulesConfigReader(javaClass.classLoader) + .readResource(nameConfig) ?: listOf() + + private fun readAllRulesFromCode() = + Warnings.values() +}