Scribe-Android icon indicating copy to clipboard operation
Scribe-Android copied to clipboard

Replace Magic Numbers with Named Constants as identified by detekt

Open angrezichatterbox opened this issue 1 year ago • 4 comments

Terms

Description

Linting issues have been identified by Detekt due to Magic Numbers across the codebase. Magic numbers are when numbers are used in certain code lines within the definition of what that number means.

Example:

Before fixing:

fun isOverSpeeding(speed: Int): Boolean {
    return speed > 60  // Magic number 60 lacks clarity 
}

After fixing:

const val SPEED_LIMIT = 60  // Named constant provides context

fun isOverSpeeding(speed: Int): Boolean {
    return speed > SPEED_LIMIT
}

These can be identified across the code by the following steps:

  • Enable the MagicNumber detection from the detekt.yml file.
  • Run the command ./gradlew detekt
  • You would be able to see all the files where Linting issues are caused due to Magic Numbers

Contribution

I would love to work on this and am more than willing to help anyone solve this issue. 😄

angrezichatterbox avatar Sep 07 '24 08:09 angrezichatterbox

Could you assign this issue to me? The command returned around 500 errors, so resolving this issue might take some time.

Linfye avatar Sep 12 '24 01:09 Linfye

Yes, Feel free to work on this issue. If you have any questions, please don't hesitate to ask us. Do you think there is any need to break down this issue?

angrezichatterbox avatar Sep 12 '24 04:09 angrezichatterbox

That's OK. I can work on this and I will ask questions when necessary. 😊

Linfye avatar Sep 12 '24 05:09 Linfye

Thanks @Linfye and @angrezichatterbox! :)

andrewtavis avatar Sep 12 '24 06:09 andrewtavis

Closed by #234 🚀 Thanks for getting to all of these issues recently, @Linfye! Amazing work :)

andrewtavis avatar Oct 30 '24 22:10 andrewtavis