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

`MAGIC_NUMBER` false positive when `Long` constants are used together with `kotlin.time.Duration` extensions #1934

Open 0x6675636b796f75676974687562 opened 4 months ago

0x6675636b796f75676974687562 commented 4 months ago

Describe the bug

The following constant declarations trigger the MAGIC_NUMBER false positive:

import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

val fooTimeout = 10L.seconds

val barTimeout = 10L.minutes

Environment information

rubenquadros commented 1 month ago

How would you solve this? Just check for .seconds, .minutes and .hours from the nodeText?

orchestr7 commented 1 month ago

How would you solve this? Just check for .seconds, .minutes and .hours from the nodeText?

Yes, need to check that the syntax of the constant is the following:

val a = (some constant).(any method) . And if the expression really fits this pattern, then not to raise a warning in the code of diktat.

This is a really easy fix