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

FP of LOCAL_VARIABLE_EARLY_DECLARATION with other variables and a loop #581

Closed
petertrr opened this issue Nov 27, 2020 · 0 comments · Fixed by #635
Closed

FP of LOCAL_VARIABLE_EARLY_DECLARATION with other variables and a loop #581

petertrr opened this issue Nov 27, 2020 · 0 comments · Fixed by #635
Assignees
Labels
bug Something isn't working

Comments

@petertrr
Copy link
Member

Describe the bug

    private fun collectAllExtensionFunctions(node: ASTNode): SimilarSignatures {
        val extensionFunctionList = node.findAllNodesWithSpecificType(FUN).filter { it.hasChildOfType(TYPE_REFERENCE) && it.hasChildOfType(DOT) }
        val distinctFunctionSignatures = mutableMapOf<FunctionSignature, ASTNode>()  // maps function signatures on node it is used by
        val extensionFunctionsPairs = mutableListOf<Pair<ExtensionFunction, ExtensionFunction>>()  // pairs extension functions with same signature

        extensionFunctionList.forEach { func ->
            val functionName = (func.psi as KtNamedFunction).name!!
            // List<String> is used to show param names in warning
            val params = (func.getFirstChildWithType(VALUE_PARAMETER_LIST)!!.psi as KtParameterList).parameters.map { it.name!! }
            val returnType = func.findChildAfter(COLON, TYPE_REFERENCE)?.text
            val className = func.findChildBefore(DOT, TYPE_REFERENCE)!!.text
            val signature = FunctionSignature(functionName, params, returnType)

            if (distinctFunctionSignatures.contains(signature)) {
                val secondFuncClassName = distinctFunctionSignatures[signature]!!.findChildBefore(DOT, TYPE_REFERENCE)!!.text
                extensionFunctionsPairs.add(Pair(
                    ExtensionFunction(secondFuncClassName, signature, distinctFunctionSignatures[signature]!!),
                    ExtensionFunction(className, signature, func)))
            } else {
                distinctFunctionSignatures[signature] = func
            }
        }

        return extensionFunctionsPairs
    }

=>

ExtensionFunctionsSameNameRule.kt:82:9: [LOCAL_VARIABLE_EARLY_DECLARATION] local variables should be declared close to the line where they are first used: <distinctFunctionSignatures> is declared on line <82> and is used for the first time on line <85>

Environment information

  • diktat version: 0.1.5
@petertrr petertrr added the bug Something isn't working label Nov 27, 2020
@aktsay6 aktsay6 self-assigned this Dec 10, 2020
aktsay6 added a commit that referenced this issue Dec 10, 2020
### What's done:
 * Fixed bugs
 * Added tests
aktsay6 added a commit that referenced this issue Dec 10, 2020
### What's done:
 * Fixed bugs
 * Added tests
aktsay6 added a commit that referenced this issue Dec 11, 2020
### What's done:
 * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 11, 2020
### What's done:
 * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 11, 2020
### What's done:
 * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 11, 2020
### What's done:
 * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 11, 2020
### What's done:
 * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 11, 2020
### What's done:
 * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 11, 2020
### What's done:
 * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 11, 2020
### What's done:
 * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 14, 2020
### What's done:
  * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 14, 2020
### What's done:
  * Fixed bugs
aktsay6 added a commit that referenced this issue Dec 14, 2020
…nd a loop (#635)

* bugfix/local-variable-loops(#581)

### What's done:
 * Fixed bugs
 * Added tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants