Skip to content

Commit

Permalink
Multiple error
Browse files Browse the repository at this point in the history
### What's done:
   Simplified and fixed code according to new logic
  • Loading branch information
kentr0w committed Feb 10, 2021
1 parent c7abfc9 commit b183c77
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import org.slf4j.LoggerFactory

import java.io.BufferedReader
import java.io.File
import java.util.concurrent.atomic.AtomicInteger

import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import java.util.concurrent.atomic.AtomicInteger

const val DIKTAT_COMMON = "DIKTAT_COMMON"

Expand Down Expand Up @@ -123,7 +123,7 @@ data class CommonConfiguration(private val configuration: Map<String, String>?)
*/
val kotlinVersion: KotlinVersion by lazy {
configuration?.get("kotlinVersion")?.kotlinVersion() ?: run {
if(visitorCounter.incrementAndGet() == 1) {
if (visitorCounter.incrementAndGet() == 1) {
log.error("Kotlin version not specified in the configuration file. Will be using ${KotlinVersion.CURRENT} version")
}
KotlinVersion.CURRENT
Expand All @@ -148,9 +148,7 @@ data class CommonConfiguration(private val configuration: Map<String, String>?)
/**
* @return common configuration from list of all rules configuration
*/
fun List<RulesConfig>.getCommonConfiguration() = lazy {
CommonConfiguration(getCommonConfig()?.configuration)
}
fun List<RulesConfig>.getCommonConfiguration() = CommonConfiguration(getCommonConfig()?.configuration)

/**
* Get [RulesConfig] for particular [Rule] object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConfigReaderTest {
.readResource("src/test/resources/test-rules-config.yml")
val kotlinVersionForTest = KotlinVersion(1, 4, 21)
requireNotNull(rulesConfigList)
assert(rulesConfigList.getCommonConfiguration().value.kotlinVersion == kotlinVersionForTest)
assert(rulesConfigList.getCommonConfiguration().kotlinVersion == kotlinVersionForTest)
assert(rulesConfigList.find { it.name == DIKTAT_COMMON }
?.configuration
?.get("kotlinVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum class Chapters(val number: String, val title: String) {
*/
fun Warnings.isRuleFromActiveChapter(configRules: List<RulesConfig>): Boolean {
val chapterFromRule = getChapterByWarning()
val configuration by configRules.getCommonConfiguration()
val configuration = configRules.getCommonConfiguration()
val disabledChapters = configuration.disabledChapters
?.takeIf { it.isNotBlank() }
?.split(",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PackageNaming(configRules: List<RulesConfig>) : DiktatRule("package-naming
private lateinit var domainName: String

override fun logic(node: ASTNode) {
val configuration by configRules.getCommonConfiguration()
val configuration = configRules.getCommonConfiguration()
configuration.domainName?.let {
domainName = it
if (node.elementType == PACKAGE_DIRECTIVE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class KdocComments(configRules: List<RulesConfig>) : DiktatRule("kdoc-comments",
* @param emit
*/
override fun logic(node: ASTNode) {
val config = configRules.getCommonConfiguration().value
val config = configRules.getCommonConfiguration()
val filePath = node.getRootNode().getFilePath()
if (!(node.hasTestAnnotation() || isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors))) {
when (node.elementType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class KdocMethods(configRules: List<RulesConfig>) : DiktatRule("kdoc-methods", c
*/
override fun logic(node: ASTNode) {
if (node.elementType == FUN && node.getFirstChildWithType(MODIFIER_LIST).isAccessibleOutside() && !node.isOverridden()) {
val config = configRules.getCommonConfiguration().value
val config = configRules.getCommonConfiguration()
val filePath = node.getRootNode().getFilePath()
val isTestMethod = node.hasTestAnnotation() || isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors)
if (!isTestMethod && !node.isStandardMethod() && !node.isSingleLineGetterOrSetter()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
*/
@Suppress("TOO_LONG_FUNCTION")
class TrailingCommaRule(configRules: List<RulesConfig>) : DiktatRule("trailing-comma", configRules, listOf(TRAILING_COMMA)) {
private val commonConfig by configRules.getCommonConfiguration()
private val commonConfig = configRules.getCommonConfiguration()
private val trailingConfig = this.configRules.getRuleConfig(TRAILING_COMMA)?.configuration ?: emptyMap()
private val configuration by lazy {
if (trailingConfig.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class FileStructureRule(configRules: List<RulesConfig>) : DiktatRule("file-struc
private val domainName by lazy {
configRules
.getCommonConfiguration()
.value
.domainName
}
private val standardImportsAsName = StandardPlatforms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.psiUtil.children
*/
class AvoidUtilityClass(configRules: List<RulesConfig>) : DiktatRule("avoid-utility-class", configRules, listOf(AVOID_USING_UTILITY_CLASS)) {
override fun logic(node: ASTNode) {
val config by configRules.getCommonConfiguration()
val config = configRules.getCommonConfiguration()
val filePath = node.getRootNode().getFilePath()
if (!(node.hasTestAnnotation() || isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors))) {
if (node.elementType == OBJECT_DECLARATION || node.elementType == CLASS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
*/
class InlineClassesRule(configRules: List<RulesConfig>) : DiktatRule("inline-classes", configRules, listOf(INLINE_CLASS_CAN_BE_USED)) {
override fun logic(node: ASTNode) {
val configuration by configRules.getCommonConfiguration()
val configuration = configRules.getCommonConfiguration()
if (node.elementType == CLASS && configuration.kotlinVersion >= ktVersion) {
handleClasses(node.psi as KtClass)
}
Expand Down

0 comments on commit b183c77

Please sign in to comment.