Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
0x6675636b796f75676974687562 opened this issue Jun 19, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@0x6675636b796f75676974687562
Copy link
Member

0x6675636b796f75676974687562 commented Jun 19, 2024

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

  • diktat version: 2.0.0
  • build tool: Maven
  • how is diktat run: plugin
  • kotlin version: 1.7.22
  • operating system: Any
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added bug Something isn't working good first issue Good for newcomers labels Jun 19, 2024
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added this to the 2.1.0 milestone Jun 19, 2024
@rubenquadros
Copy link

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

@orchestr7
Copy link
Member

orchestr7 commented Oct 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants