Skip to content

Replace Magic Numbers with Named Constants as identified by detekt #90

@angrezichatterbox

Description

@angrezichatterbox

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. 😄

Metadata

Metadata

Assignees

Labels

featureNew feature or requestgood first issueGood for newcomershacktoberfestIncluded as a part of Hacktoberfesthelp wantedExtra attention is neededrefactorRefactor code to improve quality

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions