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

MultilineLambdaItParameter: false positive for one-line statements with a lambda argument #5504

Closed
t-kameyama opened this issue Nov 4, 2022 · 1 comment · Fixed by #5505
Labels

Comments

@t-kameyama
Copy link
Contributor

Steps to Reproduce

@Nested
inner class `single parameter, single-line lambda` {
    @Test
    fun `does not report when statement has one-line lambda argument`() {
        val code = """
        fun f() {
            val digits = 1234.let {
                check(it > 0) { println(it) }
            }
        }
        """.trimIndent()
        val findings = subject.compileAndLintWithContext(env, code)
        assertThat(findings).isEmpty()
    }
}

Context

#5397 (comment)

@t-kameyama t-kameyama added the bug label Nov 4, 2022
@TWiStErRob
Copy link
Member

Agreed. I reproed using his code:

    @Test
    fun `example1`() {
        val code = """
            interface DeathStar {
                fun seekTieFighters(block: () -> Unit)
            }
            class ForegroundColorSpan(color: Int)
            fun List<DeathStar>?.f(colorLink: Int) {
                this?.map { it.seekTieFighters { ForegroundColorSpan(colorLink) } }
            }
        """.trimIndent()
        val findings = subject.compileAndLintWithContext(env, code)
        assertThat(findings).isEmpty()
    }

Expecting empty but was: [CodeSmell(issue=Issue(id='MultilineLambdaItParameter', severity=Style, debt=5min), entity=Entity(name=f, signature=Test.kt${ it.seekTieFighters { ForegroundColorSpan(colorLink) } }, location=Location(source=6:15, text=160:217, file=Test.kt, filePath=FilePath(absolutePath=Test.kt, basePath=null, relativePath=null)), ktElement=LAMBDA_EXPRESSION), message=The implicit it should not be used in a multiline lambda. Consider giving your parameter a readable and descriptive name., metrics=[], references=[], severity=WARNING, id='MultilineLambdaItParameter')]
at io.gitlab.arturbosch.detekt.rules.style.MultilineLambdaItParameterSpec.example1(MultilineLambdaItParameterSpec.kt:241)

in this one there's only one it, could be simplified further though.

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