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
519 stars 39 forks source link

False `MAGIC_NUMBER` for ranges #1826

Closed nulls closed 7 months ago

nulls commented 8 months ago

To reproduce:

@Suppress("MagicNumber")
private val tagLengthRange = 3..15

Diktat 2.0 generates:

D:/projects/save-cloud/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/validation/ValidationUtils.kt:16:30: [MAGIC_NUMBER] avoid using magic numbers, instead define constants with clear names describing what the magic number means: 3 (cannot be auto-corrected) (diktat-ruleset:magic-number)
D:/projects/save-cloud/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/validation/ValidationUtils.kt:16:33: [MAGIC_NUMBER] avoid using magic numbers, instead define constants with clear names describing what the magic number means: 15 (cannot be auto-corrected) (diktat-ruleset:magic-number)

Additionally:

val cia = mapOf(
    CiaType.HIGH.value to 0.56f,
    CiaType.LOW.value to 0.22f,
    CiaType.NONE.value to 0f,
)

Diktat 2.0 generates:

D:/projects/save-cloud/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/cvsscalculator/v3/WeightV3.kt:45:27: [MAGIC_NUMBER] avoid using magic numbers, instead define constants with clear names describing what the magic number means: 0.56f (cannot be auto-corrected) (diktat-ruleset:magic-number)
D:/projects/save-cloud/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/cvsscalculator/v3/WeightV3.kt:46:26: [MAGIC_NUMBER] avoid using magic numbers, instead define constants with clear names describing what the magic number means: 0.22f (cannot be auto-corrected) (diktat-ruleset:magic-number)
D:/projects/save-cloud/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/cvsscalculator/v3/WeightV3.kt:47:27: [MAGIC_NUMBER] avoid using magic numbers, instead define constants with clear names describing what the magic number means: 0f (cannot be auto-corrected) (diktat-ruleset:magic-number)