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

New rule: Function paramater should not be nullable #4377

Closed
BraisGabin opened this issue Dec 16, 2021 · 2 comments
Closed

New rule: Function paramater should not be nullable #4377

BraisGabin opened this issue Dec 16, 2021 · 2 comments

Comments

@BraisGabin
Copy link
Member

Expected Behavior of the rule

Some times I found functions that allows a null parameter to then assert that it's not null. Those functions shouldn't accept a null parameter, they should force the caller to take the decission to force the non-null or don't cal it.

Non-compilant

fun foo(a: String?) {
  println(a!!)
}

This function should be declared like this:

fun foo(a: String) {
  println(a)
}

Context

This kind of errors are added with the java to kotlin translator. And some times after a few refactor you can end up with code like this.

@severn-everett
Copy link
Contributor

I'll add this in when PR #4379 is integrated, as it looks like it falls within the same purview of that rule.

@cortinico
Copy link
Member

Closed by #4431

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

No branches or pull requests

3 participants