goruby/goruby

View on GitHub
parser/parser.go

Summary

Maintainability
F
6 days
Test Coverage

File parser.go has 1337 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package parser

import (
    "fmt"
    gotoken "go/token"
Severity: Major
Found in parser/parser.go - About 2 days to fix

    parser has 66 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type parser struct {
        file   *gotoken.File
        l      *lexer.Lexer
        errors []error
    
    
    Severity: Major
    Found in parser/parser.go - About 1 day to fix

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

      func (p *parser) parseFunctionLiteral() ast.Expression {
          if p.trace {
              defer un(trace(p, "parseFunctionLiteral"))
          }
          lit := &ast.FunctionLiteral{Token: p.curToken}
      Severity: Minor
      Found in parser/parser.go - About 3 hrs 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 parser.init has 77 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (p *parser) init(fset *gotoken.FileSet, filename string, src []byte, mode Mode) {
          p.file = fset.AddFile(filename, -1, len(src))
      
          p.l = lexer.New(string(src))
          p.errors = []error{}
      Severity: Major
      Found in parser/parser.go - About 2 hrs to fix

        Method parser.parseFunctionLiteral has 74 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (p *parser) parseFunctionLiteral() ast.Expression {
            if p.trace {
                defer un(trace(p, "parseFunctionLiteral"))
            }
            lit := &ast.FunctionLiteral{Token: p.curToken}
        Severity: Minor
        Found in parser/parser.go - About 1 hr to fix

          Method parser.parseParameters has 59 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (p *parser) parseParameters(startToken, endToken token.Type) []*ast.FunctionParameter {
              if p.trace {
                  defer un(trace(p, "parseParameters"))
              }
              hasDelimiters := false
          Severity: Minor
          Found in parser/parser.go - About 1 hr to fix

            Method parser.parseFunctionLiteral has 8 return statements (exceeds 4 allowed).
            Open

            func (p *parser) parseFunctionLiteral() ast.Expression {
                if p.trace {
                    defer un(trace(p, "parseFunctionLiteral"))
                }
                lit := &ast.FunctionLiteral{Token: p.curToken}
            Severity: Major
            Found in parser/parser.go - About 50 mins to fix

              Method parser.parseParameters has 7 return statements (exceeds 4 allowed).
              Open

              func (p *parser) parseParameters(startToken, endToken token.Type) []*ast.FunctionParameter {
                  if p.trace {
                      defer un(trace(p, "parseParameters"))
                  }
                  hasDelimiters := false
              Severity: Major
              Found in parser/parser.go - About 45 mins to fix

                Method parser.parseContextCallExpression has 6 return statements (exceeds 4 allowed).
                Open

                func (p *parser) parseContextCallExpression(context ast.Expression) ast.Expression {
                    if p.trace {
                        defer un(trace(p, "parseContextCallExpression"))
                    }
                    contextCallExpression := &ast.ContextCallExpression{Token: p.curToken, Context: context}
                Severity: Major
                Found in parser/parser.go - About 40 mins to fix

                  Method parser.parseReturnStatement has 5 return statements (exceeds 4 allowed).
                  Open

                  func (p *parser) parseReturnStatement() *ast.ReturnStatement {
                      if p.trace {
                          defer un(trace(p, "parseReturnStatement"))
                      }
                      stmt := &ast.ReturnStatement{Token: p.curToken}
                  Severity: Major
                  Found in parser/parser.go - About 35 mins to fix

                    Method parser.parseExpression has 5 return statements (exceeds 4 allowed).
                    Open

                    func (p *parser) parseExpression(precedence int) ast.Expression {
                        if p.trace {
                            defer un(trace(p, "parseExpression"))
                        }
                        prefix := p.prefixParseFns[p.curToken.Type]
                    Severity: Major
                    Found in parser/parser.go - About 35 mins to fix

                      Method parser.parseParameters has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                      Open

                      func (p *parser) parseParameters(startToken, endToken token.Type) []*ast.FunctionParameter {
                          if p.trace {
                              defer un(trace(p, "parseParameters"))
                          }
                          hasDelimiters := false
                      Severity: Minor
                      Found in parser/parser.go - About 35 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 parser.parseHash has 5 return statements (exceeds 4 allowed).
                      Open

                      func (p *parser) parseHash() ast.Expression {
                          hash := &ast.HashLiteral{Token: p.curToken, Map: make(map[ast.Expression]ast.Expression)}
                          if p.trace {
                              defer un(trace(p, "parseHash"))
                          }
                      Severity: Major
                      Found in parser/parser.go - About 35 mins to fix

                        Method parser.parseMethodCall has 5 return statements (exceeds 4 allowed).
                        Open

                        func (p *parser) parseMethodCall(context ast.Expression) ast.Expression {
                            if p.trace {
                                defer un(trace(p, "parseMethodCall"))
                            }
                            contextCallExpression := &ast.ContextCallExpression{Token: p.curToken, Context: context}
                        Severity: Major
                        Found in parser/parser.go - About 35 mins to fix

                          Method parser.parseAssignment has 5 return statements (exceeds 4 allowed).
                          Open

                          func (p *parser) parseAssignment(left ast.Expression) ast.Expression {
                              if p.trace {
                                  defer un(trace(p, "parseAssignment"))
                              }
                          
                          
                          Severity: Major
                          Found in parser/parser.go - About 35 mins to fix

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

                                if p.peekTokenIs(token.LPAREN) {
                                    p.accept(token.LPAREN)
                                    p.nextToken()
                                    contextCallExpression.Arguments = p.parseExpressionList(token.RPAREN)
                                    if p.peekTokenOneOf(token.LBRACE, token.DO) {
                            Severity: Major
                            Found in parser/parser.go and 1 other location - About 1 hr to fix
                            parser/parser.go on lines 1253..1262

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

                            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 p.peekTokenIs(token.LPAREN) {
                                    p.accept(token.LPAREN)
                                    p.nextToken()
                                    contextCallExpression.Arguments = p.parseExpressionList(token.RPAREN)
                                    if p.peekTokenOneOf(token.LBRACE, token.DO) {
                            Severity: Major
                            Found in parser/parser.go and 1 other location - About 1 hr to fix
                            parser/parser.go on lines 1306..1315

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

                            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 (p *parser) peekError(t ...token.Type) {
                                epos := p.file.Position(p.pos)
                                err := &unexpectedTokenError{
                                    Pos:            epos,
                                    expectedTokens: t,
                            Severity: Minor
                            Found in parser/parser.go and 1 other location - About 40 mins to fix
                            parser/parser.go on lines 304..312

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

                            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 (p *parser) expectError(t ...token.Type) {
                                epos := p.file.Position(p.pos)
                                err := &unexpectedTokenError{
                                    Pos:            epos,
                                    expectedTokens: t,
                            Severity: Minor
                            Found in parser/parser.go and 1 other location - About 40 mins to fix
                            parser/parser.go on lines 294..302

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

                            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