phodal/chapi

View on GitHub
chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt

Summary

Maintainability
F
5 days
Test Coverage

File TypeScriptFullIdentListener.kt has 818 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package chapi.ast.typescriptast

import chapi.ast.antlr.TypeScriptParser
import chapi.ast.antlr.TypeScriptParser.IdentifierExpressionContext
import chapi.ast.antlr.TypeScriptParser.ParenthesizedExpressionContext

    Class TypeScriptFullIdentListener has 49 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class TypeScriptFullIdentListener(val node: TSIdentify) : TypeScriptAstListener() {
        private var hasHtmlElement: Boolean = false
        private var filePath: String = node.filePath
    
        private var exitArrowCount: Int = 0

      Method handleClassBodyElements has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
      Open

          private fun handleClassBodyElements(classTailCtx: TypeScriptParser.ClassBodyContext) {
              for (clzElementCtx in classTailCtx.classMemberList().classMember()) {
                  val childCtx = clzElementCtx.getChild(0) ?: continue
                  when (childCtx) {
                      is TypeScriptParser.ConstructorDeclarationContext -> {

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method handleClassBodyElements has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private fun handleClassBodyElements(classTailCtx: TypeScriptParser.ClassBodyContext) {
              for (clzElementCtx in classTailCtx.classMemberList().classMember()) {
                  val childCtx = clzElementCtx.getChild(0) ?: continue
                  when (childCtx) {
                      is TypeScriptParser.ConstructorDeclarationContext -> {

        Method enterVariableDeclaration has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            /**
             *     create local var when new object
             */
            override fun enterVariableDeclaration(ctx: TypeScriptParser.VariableDeclarationContext?) {
                if (ctx == null) {

          Method enterFromBlock has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              override fun enterFromBlock(ctx: TypeScriptParser.FromBlockContext?) {
                  val imp = unQuote(ctx!!.StringLiteral().text)
                  val codeImport = CodeImport(
                      Source = imp
                  )

            Method enterArrowFunctionDeclaration has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                // see also in function declaration
                override fun enterArrowFunctionDeclaration(ctx: TypeScriptParser.ArrowFunctionDeclarationContext?) {
                    isCallbackOrAnonymousFunction = false
            
                    when (val grad = ctx?.parent?.parent) {

              Method parseArguments has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private fun parseArguments(argument: TypeScriptParser.ArgumentsExpressionContext): List<CodeProperty> {
                      var params = listOf<CodeProperty>()
              
                      // for: `axios<Module[]>({parameter}).then`
                      // create then and update parameter

                Method enterVariableStatement has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    override fun enterVariableStatement(ctx: VariableStatementContext?) {
                        val isExport = ctx!!.parent.parent.getChild(0).text == "export"
                
                        if (!isExport && ctx.variableDeclarationList() != null) {
                            defaultNode.Fields = variableToFields(ctx.variableDeclarationList())

                  Method enterClassDeclaration has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      override fun enterClassDeclaration(ctx: TypeScriptParser.ClassDeclarationContext?) {
                          val nodeName = ctx!!.identifierName().text
                  
                          hasEnterClass = true
                          currentNode = CodeDataStruct(

                    Method variableToField has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private fun variableToField(
                            it: TypeScriptParser.VariableDeclarationContext,
                            modifiers: List<String>
                        ): CodeField {
                            val key = it.getChild(0).text

                      Method parseParenthesizedExpression has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private fun parseParenthesizedExpression(context: ParenthesizedExpressionContext): List<CodeProperty> {
                              return context.expressionSequence().singleExpression().map { subSingle ->
                                  var parameter = CodeProperty(TypeValue = "", TypeType = "object")
                      
                                  when (subSingle) {

                        Method enterFromBlock has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                        Open

                            override fun enterFromBlock(ctx: TypeScriptParser.FromBlockContext?) {
                                val imp = unQuote(ctx!!.StringLiteral().text)
                                val codeImport = CodeImport(
                                    Source = imp
                                )

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                    } else {
                                        codeImport.UsageName += importNamespace.identifierName()[0].text
                                        if (importNamespace.As() != null) {
                                            codeImport.AsName += importNamespace.identifierName()[1].text
                                        }
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 398..403

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 103.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                        if (nameContext.identifierName().isNotEmpty()) {
                                            codeImport.UsageName += nameContext.identifierName()[0].text
                                            if (nameContext.As() != null) {
                                                codeImport.AsName += nameContext.identifierName()[1].text
                                            }
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 420..425

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 103.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                } else if (fieldOnly) {
                                    defaultNode.NodeName = "default"
                                    defaultNode.FilePath = codeContainer.FullName
                                    defaultNode.Package = codeContainer.PackageName
                                    codeContainer.DataStructures += defaultNode
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 1070..1075

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 80.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                if (functionOnly) {
                                    defaultNode.NodeName = "default"
                                    defaultNode.FilePath = codeContainer.FullName
                                    defaultNode.Package = codeContainer.PackageName
                                    codeContainer.DataStructures += defaultNode
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 1075..1080

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 80.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                if (argText.startsWith("(")) {
                                    // axios("/demo")
                                    val args = parseArguments(argument)
                                    currentFunc.FunctionCalls += CodeCall("", CallType.FUNCTION, "", currentExprIdent, args)
                                } else {
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 144..147
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 677..680

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 69.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                    is ParenthesizedExpressionContext -> {
                                        val parameters = parseParenthesizedExpression(ctx)
                                        currentFunc.FunctionCalls += CodeCall("", CallType.FUNCTION, "", currentExprIdent, parameters)
                                    }
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 144..147
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 695..699

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 69.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                        is TypeScriptParser.ParenthesizedExpressionContext -> {
                                            val parameters = parseParenthesizedExpression(singleExpr)
                                            field.Calls += CodeCall("", CallType.FIELD, "", funcName, parameters)
                                        }
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 677..680
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 695..699

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 69.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                        if (ctx.formalParameterList() != null) {
                                            currentFunc.Parameters = this.buildParameters(ctx.formalParameterList())
                                        }
                        chapi-ast-python/src/main/kotlin/chapi/ast/pythonast/PythonAstBaseListener.kt on lines 64..66
                        chapi-ast-python/src/main/kotlin/chapi/ast/pythonast/PythonFullIdentListener.kt on lines 97..99

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 68.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                if (ctx.formalParameterList() != null) {
                                    codeFunction.Parameters += buildParameters(ctx.formalParameterList())
                                }
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 503..505
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 601..603

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 61.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                        if (ctx.typeAnnotation() != null) {
                                            currentFunc.MultipleReturns += buildReturnTypeByType(ctx.typeAnnotation())
                                        }
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 288..290
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 503..505

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 61.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                        if (ctx.typeAnnotation() != null) {
                                            func.MultipleReturns += buildReturnTypeByType(ctx.typeAnnotation())
                                        }
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 288..290
                        chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt on lines 601..603

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 61.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        There are no issues that match your filters.

                        Category
                        Status