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

Add rule to replace function body with single expression by an expression body #2150

Closed
paul-dingemans opened this issue Jul 24, 2023 · 0 comments · Fixed by #2151
Closed

Comments

@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Jul 24, 2023

Kotlin Coding Conventions:

Prefer using an expression body for functions with the body consisting of a single expression.

fun foo(): Int {     // bad
    return 1
}

fun foo() = 1        // good

Android Kotlin styleguide:

When a function contains only a single expression it can be represented as an [expression function]

override fun toString(): String {
    return "Hey"
}

override fun toString(): String = "Hey"
@paul-dingemans paul-dingemans added this to the 1.0 (Yeah!) milestone Jul 24, 2023
@paul-dingemans paul-dingemans self-assigned this Jul 24, 2023
paul-dingemans added a commit that referenced this issue Jul 25, 2023
This rule rewrites function bodies only contain a `return` or `throw` expression to an expression body.

Closes #2150
paul-dingemans added a commit that referenced this issue Jul 28, 2023
This rule rewrites function bodies only containining a `return` or `throw` expression to an expression body.

Closes #2150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant