saveourtool / diktat

Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs
https://diktat.saveourtool.com
MIT License
525 stars 39 forks source link

[PARAMETER_NAME_IN_OUTER_LAMBDA] False positive findings #1880

Closed nulls closed 9 months ago

nulls commented 9 months ago

Describe the bug

False positive findings when lambda operation at the same level:

@Suppress("PARAMETER_NAME_IN_OUTER_LAMBDA")
overrideFunctions.forEach {
    functionNameMap.compute(it.getIdentifierName()!!.text) { _, oldValue -> (oldValue ?: 0) + 1 }
}
    private fun isCheckNeeded(whiteSpace: PsiWhiteSpace) =
        whiteSpace.parent
            .node
            .elementType
            .let { it == VALUE_PARAMETER_LIST || it == VALUE_ARGUMENT_LIST } &&
                whiteSpace.siblings(forward = false, withItself = false).none { it is PsiWhiteSpace && it.textContains('\n') } &&
                @Suppress("PARAMETER_NAME_IN_OUTER_LAMBDA")
                // no need to trigger when there are no more parameters in the list
                whiteSpace.siblings(forward = true, withItself = false).any {
                    it.node.elementType.run { this == VALUE_ARGUMENT || this == VALUE_PARAMETER }
                }
    @Suppress("PARAMETER_NAME_IN_OUTER_LAMBDA")
    private fun checkBlankLineAfterKdoc(node: ASTNode) {
        commentType.forEach {
            val kdoc = node.getFirstChildWithType(it)
            kdoc?.treeNext?.let { nodeAfterKdoc ->
                if (nodeAfterKdoc.elementType == WHITE_SPACE && nodeAfterKdoc.numNewLines() > 1) {
                    WRONG_NEWLINES_AROUND_KDOC.warnAndFix(configRules, emitWarn, isFixMode, "redundant blank line after ${kdoc.text}", nodeAfterKdoc.startOffset, nodeAfterKdoc) {
                        nodeAfterKdoc.leaveOnlyOneNewLine()
                    }
                }
            }
        }
    }
        private fun KSAnnotation.getArgumentValue(argumentName: String): String = arguments
            .singleOrNull { it.name?.asString() == argumentName }
            .let {
                requireNotNull(it) {
                    "Not found $argumentName in $this"
                }
            }
            .value
            ?.let { it as? String }
            .let {
                requireNotNull(it) {
                    "Not found a value for $argumentName in $this"
                }
            }

Expected behavior

Do not trigger when inner lambda has no it in the code

Observed behavior

Remove suppressing in diktat

Steps to Reproduce

Environment information