compiler_nodes.go

Summary

Maintainability
F
4 days
Test Coverage

File compiler_nodes.go has 955 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Copyright (c) 2020-2023 Ozan Hacıbekiroğlu.
// Use of this source code is governed by a MIT License
// that can be found in the LICENSE file.

package ugo
Severity: Major
Found in compiler_nodes.go - About 1 day to fix

    Compiler has 34 methods (exceeds 20 allowed). Consider refactoring.
    Open

    func (c *Compiler) compileIfStmt(node *parser.IfStmt) error {
        // open new symbol table for the statement
        c.symbolTable = c.symbolTable.Fork(true)
        defer func() {
            c.symbolTable = c.symbolTable.Parent(false)
    Severity: Minor
    Found in compiler_nodes.go - About 4 hrs to fix

      Method Compiler.compileImportExpr has 66 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (c *Compiler) compileImportExpr(node *parser.ImportExpr) error {
          moduleName := node.ModuleName
          if moduleName == "" {
              return c.errorf(node, "empty module name")
          }
      Severity: Minor
      Found in compiler_nodes.go - About 1 hr to fix

        Method Compiler.compileDeclValue has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
        Wontfix

        func (c *Compiler) compileDeclValue(node *parser.GenDecl) error {
            var (
                isConst  bool
                lastExpr parser.Expr
            )
        Severity: Minor
        Found in compiler_nodes.go - About 1 hr to fix

        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 Compiler.compileForInStmt has 54 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (c *Compiler) compileForInStmt(stmt *parser.ForInStmt) error {
            c.symbolTable = c.symbolTable.Fork(true)
            defer func() {
                c.symbolTable = c.symbolTable.Parent(false)
            }()
        Severity: Minor
        Found in compiler_nodes.go - About 1 hr to fix

          Method Compiler.compileImportExpr has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
          Wontfix

          func (c *Compiler) compileImportExpr(node *parser.ImportExpr) error {
              moduleName := node.ModuleName
              if moduleName == "" {
                  return c.errorf(node, "empty module name")
              }
          Severity: Minor
          Found in compiler_nodes.go - About 1 hr to fix

          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 Compiler.compileForInStmt has 6 return statements (exceeds 4 allowed).
          Open

          func (c *Compiler) compileForInStmt(stmt *parser.ForInStmt) error {
              c.symbolTable = c.symbolTable.Fork(true)
              defer func() {
                  c.symbolTable = c.symbolTable.Parent(false)
              }()
          Severity: Major
          Found in compiler_nodes.go - About 40 mins to fix

            Method Compiler.compileDefineAssign has 6 return statements (exceeds 4 allowed).
            Open

            func (c *Compiler) compileDefineAssign(
                node parser.Node,
                lhs parser.Expr,
                keyword token.Token,
                op token.Token,
            Severity: Major
            Found in compiler_nodes.go - About 40 mins to fix

              Method Compiler.compileCondExpr has 6 return statements (exceeds 4 allowed).
              Open

              func (c *Compiler) compileCondExpr(node *parser.CondExpr) error {
                  if v, ok := node.Cond.(*parser.BoolLit); ok {
                      if v.Value {
                          return c.Compile(node.True)
                      }
              Severity: Major
              Found in compiler_nodes.go - About 40 mins to fix

                Method Compiler.compileIfStmt has 6 return statements (exceeds 4 allowed).
                Open

                func (c *Compiler) compileIfStmt(node *parser.IfStmt) error {
                    // open new symbol table for the statement
                    c.symbolTable = c.symbolTable.Fork(true)
                    defer func() {
                        c.symbolTable = c.symbolTable.Parent(false)
                Severity: Major
                Found in compiler_nodes.go - About 40 mins to fix

                  Method Compiler.checkAssignment has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      node parser.Node,
                      lhs []parser.Expr,
                      rhs []parser.Expr,
                      keyword token.Token,
                      op token.Token,
                  Severity: Minor
                  Found in compiler_nodes.go - About 35 mins to fix

                    Method Compiler.compileDefineAssign has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        node parser.Node,
                        lhs parser.Expr,
                        keyword token.Token,
                        op token.Token,
                        allowRedefine bool,
                    Severity: Minor
                    Found in compiler_nodes.go - About 35 mins to fix

                      Method Compiler.compileDestructuring has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          node parser.Node,
                          lhs []parser.Expr,
                          tempArrSymbol *Symbol,
                          keyword token.Token,
                          op token.Token,
                      Severity: Minor
                      Found in compiler_nodes.go - About 35 mins to fix

                        Method Compiler.compileAssignStmt has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            node parser.Node,
                            lhs []parser.Expr,
                            rhs []parser.Expr,
                            keyword token.Token,
                            op token.Token,
                        Severity: Minor
                        Found in compiler_nodes.go - About 35 mins to fix

                          Method Compiler.compileImportExpr has 5 return statements (exceeds 4 allowed).
                          Open

                          func (c *Compiler) compileImportExpr(node *parser.ImportExpr) error {
                              moduleName := node.ModuleName
                              if moduleName == "" {
                                  return c.errorf(node, "empty module name")
                              }
                          Severity: Major
                          Found in compiler_nodes.go - About 35 mins to fix

                            Method Compiler.compileAssignStmt has 5 return statements (exceeds 4 allowed).
                            Open

                            func (c *Compiler) compileAssignStmt(
                                node parser.Node,
                                lhs []parser.Expr,
                                rhs []parser.Expr,
                                keyword token.Token,
                            Severity: Major
                            Found in compiler_nodes.go - About 35 mins to fix

                              Method Compiler.compileForStmt has 5 return statements (exceeds 4 allowed).
                              Open

                              func (c *Compiler) compileForStmt(stmt *parser.ForStmt) error {
                                  c.symbolTable = c.symbolTable.Fork(true)
                                  defer func() {
                                      c.symbolTable = c.symbolTable.Parent(false)
                                  }()
                              Severity: Major
                              Found in compiler_nodes.go - About 35 mins to fix

                                Method Compiler.compileCallExpr has 5 return statements (exceeds 4 allowed).
                                Confirmed

                                func (c *Compiler) compileCallExpr(node *parser.CallExpr) error {
                                    var op = OpCall
                                    var selExpr *parser.SelectorExpr
                                    var isSelector bool
                                    if node.Func != nil {
                                Severity: Major
                                Found in compiler_nodes.go - About 35 mins to fix

                                  Method Compiler.compileIfStmt has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func (c *Compiler) compileIfStmt(node *parser.IfStmt) error {
                                      // open new symbol table for the statement
                                      c.symbolTable = c.symbolTable.Fork(true)
                                      defer func() {
                                          c.symbolTable = c.symbolTable.Parent(false)
                                  Severity: Minor
                                  Found in compiler_nodes.go - About 25 mins to fix

                                  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 Compiler.compileTryStmt has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func (c *Compiler) compileTryStmt(node *parser.TryStmt) error {
                                      /*
                                          // create a single symbol table for try-catch-finally
                                          // any `return` statement in finally block ignores already thrown error.
                                          try {
                                  Severity: Minor
                                  Found in compiler_nodes.go - About 25 mins to fix

                                  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

                                      case token.Break:
                                          curLoop := c.currentLoop()
                                          if curLoop == nil {
                                              return c.errorf(node, "break not allowed outside loop")
                                          }
                                  Severity: Major
                                  Found in compiler_nodes.go and 1 other location - About 1 hr to fix
                                  compiler_nodes.go on lines 599..612

                                  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 140.

                                  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

                                      case token.Continue:
                                          curLoop := c.currentLoop()
                                          if curLoop == nil {
                                              return c.errorf(node, "continue not allowed outside loop")
                                          }
                                  Severity: Major
                                  Found in compiler_nodes.go and 1 other location - About 1 hr to fix
                                  compiler_nodes.go on lines 585..598

                                  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 140.

                                  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

                                  func (c *Compiler) compileIndexExpr(node *parser.IndexExpr) error {
                                      expr, indexes := resolveIndexExprs(node)
                                      if err := c.Compile(expr); err != nil {
                                          return err
                                      }
                                  Severity: Major
                                  Found in compiler_nodes.go and 1 other location - About 1 hr to fix
                                  compiler_nodes.go on lines 931..943

                                  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 132.

                                  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

                                  func (c *Compiler) compileSelectorExpr(node *parser.SelectorExpr) error {
                                      expr, selectors := resolveSelectorExprs(node)
                                      if err := c.Compile(expr); err != nil {
                                          return err
                                      }
                                  Severity: Major
                                  Found in compiler_nodes.go and 1 other location - About 1 hr to fix
                                  compiler_nodes.go on lines 954..966

                                  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 132.

                                  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 stmt.Value.Name != "_" {
                                          valueSymbol, exists := c.symbolTable.DefineLocal(stmt.Value.Name)
                                          if exists {
                                              return c.errorf(stmt, "%q redeclared in this block", stmt.Value.Name)
                                          }
                                  Severity: Minor
                                  Found in compiler_nodes.go and 1 other location - About 55 mins to fix
                                  compiler_nodes.go on lines 769..778

                                  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 126.

                                  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 stmt.Key.Name != "_" {
                                          keySymbol, exists := c.symbolTable.DefineLocal(stmt.Key.Name)
                                          if exists {
                                              return c.errorf(stmt, "%q redeclared in this block", stmt.Key.Name)
                                          }
                                  Severity: Minor
                                  Found in compiler_nodes.go and 1 other location - About 55 mins to fix
                                  compiler_nodes.go on lines 781..790

                                  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 126.

                                  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

                                  func resolveSelectorExprs(node parser.Expr) (expr parser.Expr, selectors []parser.Expr) {
                                      expr = node
                                      if v, ok := node.(*parser.SelectorExpr); ok {
                                          expr, selectors = resolveIndexExprs(v.Expr)
                                          selectors = append(selectors, v.Sel)
                                  Severity: Minor
                                  Found in compiler_nodes.go and 1 other location - About 30 mins to fix
                                  compiler_nodes.go on lines 968..975

                                  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 100.

                                  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

                                  func resolveIndexExprs(node parser.Expr) (expr parser.Expr, indexes []parser.Expr) {
                                      expr = node
                                      if v, ok := node.(*parser.IndexExpr); ok {
                                          expr, indexes = resolveIndexExprs(v.Expr)
                                          indexes = append(indexes, v.Index)
                                  Severity: Minor
                                  Found in compiler_nodes.go and 1 other location - About 30 mins to fix
                                  compiler_nodes.go on lines 945..952

                                  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 100.

                                  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