saveourtool / diktat

Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs
https://diktat.saveourtool.com
MIT License
544 stars 39 forks source link

Bug in `WRONG_DECLARATIONS_ORDER` rule #1865

Closed DrAlexD closed 11 months ago

DrAlexD commented 11 months ago

Describe the bug

Looks like it happens due to private const val DELAY = 15000L // 15s line with comment.

Expected behavior

Same but without newline at 7 line

package com.saveourtool.diktat

class ActiveBinsMetric {
    companion object {
        private const val ACTIVE_BINS_METRIC_NAME = "c.concurrent.bins"
        private const val ALL_ACTIVE_BINS_LABEL = "total"
        private const val DELAY = 15000L  // 15s
        private const val EGG_1_BUCKET_LABEL = "1"
        private const val EGG_2_BUCKET_LABEL = "2"
        private const val EGG_3_BUCKET_LABEL = "3"
        private const val EGG_4_5_BUCKET_LABEL = "4-5"
        private const val EGG_7_9_BUCKET_LABEL = "7-9"
        private const val EGG_OVER_10_BUCKET_LABEL = "10+"
        private const val NUMBER_OF_EGGS_LABEL = "numberOfEggs"
        private val numberOfEggsBuckets = setOf(
            EGG_4_5_BUCKET_LABEL,
            EGG_2_BUCKET_LABEL,
            EGG_3_BUCKET_LABEL,
            EGG_7_9_BUCKET_LABEL,
            EGG_1_BUCKET_LABEL,
            EGG_OVER_10_BUCKET_LABEL,
            ALL_ACTIVE_BINS_LABEL)
    }
}

Observed behavior

package com.saveourtool.diktat

class ActiveBinsMetric {
    companion object {
        private const val ACTIVE_BINS_METRIC_NAME = "c.concurrent.bins"
        private const val ALL_ACTIVE_BINS_LABEL = "total"

        private const val DELAY = 15000L  // 15s
        private const val EGG_1_BUCKET_LABEL = "1"
        private const val EGG_2_BUCKET_LABEL = "2"
        private const val EGG_3_BUCKET_LABEL = "3"
        private const val EGG_4_5_BUCKET_LABEL = "4-5"
        private const val EGG_7_9_BUCKET_LABEL = "7-9"
        private const val EGG_OVER_10_BUCKET_LABEL = "10+"
        private const val NUMBER_OF_EGGS_LABEL = "numberOfEggs"
        private val numberOfEggsBuckets = setOf(
            EGG_4_5_BUCKET_LABEL,
            EGG_2_BUCKET_LABEL,
            EGG_3_BUCKET_LABEL,
            EGG_7_9_BUCKET_LABEL,
            EGG_1_BUCKET_LABEL,
            EGG_OVER_10_BUCKET_LABEL,
            ALL_ACTIVE_BINS_LABEL)
    }
}

Steps to Reproduce

class ActiveBinsMetric() {
    companion object {
        private const val EGG_4_5_BUCKET_LABEL = "4-5"
        private const val EGG_3_BUCKET_LABEL = "3"
        private const val EGG_OVER_10_BUCKET_LABEL = "10+"
        private const val EGG_7_9_BUCKET_LABEL = "7-9"
        private const val DELAY = 15000L // 15s
        private const val ACTIVE_BINS_METRIC_NAME = "c.concurrent.bins"
        private const val NUMBER_OF_EGGS_LABEL = "numberOfEggs"
        private const val ALL_ACTIVE_BINS_LABEL = "total"
        private const val EGG_2_BUCKET_LABEL = "2"
        private const val EGG_1_BUCKET_LABEL = "1"
        private val numberOfEggsBuckets = setOf(
            EGG_4_5_BUCKET_LABEL,
            EGG_2_BUCKET_LABEL,
            EGG_3_BUCKET_LABEL,
            EGG_7_9_BUCKET_LABEL,
            EGG_1_BUCKET_LABEL,
            EGG_OVER_10_BUCKET_LABEL,
            ALL_ACTIVE_BINS_LABEL)
    }
}