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

Fix linting issues caused due to methods with too many return statements #92

Open
2 tasks done
angrezichatterbox opened this issue Sep 7, 2024 · 2 comments
Open
2 tasks done
Assignees
Labels
feature New feature or request good first issue Good for newcomers hacktoberfest Included as a part of Hacktoberfest help wanted Extra attention is needed refactor Refactor code to improve quality

Comments

@angrezichatterbox
Copy link
Member

Terms

Description

Methods with too many return statements can be hard to read. Aim to have a single point of exit from a method, which makes the code more understandable and easier to debug.

Before fixing:

fun getDiscount(category: String): Int {
    if (category == "A") return 10
    if (category == "B") return 20
    if (category == "C") return 30
    return 0
}

After fixing:

fun getDiscount(category: String): Int {
    return when (category) {
        "A" -> 10
        "B" -> 20
        "C" -> 30
        else -> 0
    }
}

More about this can be read from the docs

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

  • Enable the ReturnCount rule in detekt.yml.
  • Run ./gradlew detekt to identify methods with too many return statements.
  • Refactor methods to reduce the number of return statements.

Contribution

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

@angrezichatterbox angrezichatterbox added feature New feature or request good first issue Good for newcomers help wanted Extra attention is needed refactor Refactor code to improve quality labels Sep 7, 2024
@andrewtavis andrewtavis added the hacktoberfest Included as a part of Hacktoberfest label Sep 30, 2024
@KesharwaniArpita
Copy link
Contributor

Can I be assigned to fix this issue?

@angrezichatterbox
Copy link
Member Author

Can I be assigned to fix this issue?

Assigned :) Thanks for taking up the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request good first issue Good for newcomers hacktoberfest Included as a part of Hacktoberfest help wanted Extra attention is needed refactor Refactor code to improve quality
Projects
Status: Todo
Development

No branches or pull requests

3 participants