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

Behaviour of MultilineLambdaItParameter inconsistent with name #7148

Closed
emilydespas-faire opened this issue Apr 8, 2024 · 1 comment · Fixed by #7221
Closed

Behaviour of MultilineLambdaItParameter inconsistent with name #7148

emilydespas-faire opened this issue Apr 8, 2024 · 1 comment · Fixed by #7221
Labels

Comments

@emilydespas-faire
Copy link

Expected Behavior

A lambda that uses the implicit it parameter with a single statement spread over multiple lines should be reported by the MultilineLambdaItParameter rule

Observed Behavior

Nothing is reported

Steps to Reproduce

fun detektTest(strings: List<String>): List<String> {
  return strings
    .flatMap {
      it
        .reader()
        .readLines()
    }
}

Context

Based on the name of the rule, its reasonable to expect that any lambda with code spanning multiple lines should be flagged. I raised this in the kotlinlang discord here: https://kotlinlang.slack.com/archives/C88E12QH4/p1712167796864189

As mentioned there, this caused confusion in one of our PRs where code that we expected to fail the rule was passed and then had to be caught by a code reviewer. This behaviour was introduced in this PR and there was a comment thread in that PR asking similar questions about the behaviour not matching the rule name that doesn't have a conclusion.

Would appreciate some clarity around whether this rule intends to ban any multi-line lambda using an it parameter, or only multi statement lambdas

Your Environment

  • Version of detekt used: 1.23.4
  • Version of Gradle used (if applicable): 8.7
  • Gradle scan link (add --scan option when running the gradle task):
  • Operating System and version: MacOS 14.4.1
  • Link to your project (if it's a public repository):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants