rofrischmann/elodin

View on GitHub
core/parser/src/Parser.js

Summary

Maintainability
F
1 wk
Test Coverage

File Parser.js has 670 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import tokenize from 'tokenize-sync'
import color from 'color'

import validateDeclaration from './validateDeclaration'
import validateFunction from './validateFunction'
Severity: Major
Found in core/parser/src/Parser.js - About 1 day to fix

    Function parseDeclaration has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

      parseDeclaration() {
        if (this.currentToken.type === 'identifier') {
          const propertyToken = this.currentToken
          const property = propertyToken.value
          const isRawDeclaration = property.substr(0, 2) === '__'
    Severity: Minor
    Found in core/parser/src/Parser.js - About 5 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

    Function parseDeclaration has 104 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      parseDeclaration() {
        if (this.currentToken.type === 'identifier') {
          const propertyToken = this.currentToken
          const property = propertyToken.value
          const isRawDeclaration = property.substr(0, 2) === '__'
    Severity: Major
    Found in core/parser/src/Parser.js - About 4 hrs to fix

      Function parse has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        parse(input) {
          this.tokens = tokenize(input.trim(), ruleMap, 'unknown').filter(
            (token) => token.type !== 'whitespace'
          )
      
      
      Severity: Major
      Found in core/parser/src/Parser.js - About 3 hrs to fix

        Parser has 22 functions (exceeds 20 allowed). Consider refactoring.
        Open

        export default class Parser {
          constructor(config = {}) {
            this.config = config
            this.context = config.context || {}
          }
        Severity: Minor
        Found in core/parser/src/Parser.js - About 2 hrs to fix

          Function parseCondition has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            parseCondition() {
              const property = this.parseIdentifier() || this.parseVariable()
          
              if (property) {
                this.updateCurrentToken(1)
          Severity: Major
          Found in core/parser/src/Parser.js - About 2 hrs to fix

            Function parseCondition has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

              parseCondition() {
                const property = this.parseIdentifier() || this.parseVariable()
            
                if (property) {
                  this.updateCurrentToken(1)
            Severity: Minor
            Found in core/parser/src/Parser.js - About 2 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

            Function parseVariantBody has 49 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              parseVariantBody() {
                const body = []
            
                if (
                  this.currentToken.type === 'curly_bracket' &&
            Severity: Minor
            Found in core/parser/src/Parser.js - About 1 hr to fix

              Function parseVariant has 45 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                parseVariant() {
                  if (
                    this.currentToken.type === 'identifier' &&
                    this.currentToken.value === 'variant'
                  ) {
              Severity: Minor
              Found in core/parser/src/Parser.js - About 1 hr to fix

                Function parseStyle has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  parseStyle() {
                    if (
                      this.currentToken.type === 'identifier' &&
                      this.currentToken.value === 'style'
                    ) {
                Severity: Minor
                Found in core/parser/src/Parser.js - About 1 hr to fix

                  Function parseStyleBody has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    parseStyleBody() {
                      const body = []
                  
                      if (
                        this.currentToken.type === 'curly_bracket' &&
                  Severity: Minor
                  Found in core/parser/src/Parser.js - About 1 hr to fix

                    Function parseConditional has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      parseConditional() {
                        if (
                          this.currentToken.type === 'square_bracket' &&
                          this.currentToken.value === '['
                        ) {
                    Severity: Minor
                    Found in core/parser/src/Parser.js - About 1 hr to fix

                      Function parseVariantBody has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                        parseVariantBody() {
                          const body = []
                      
                          if (
                            this.currentToken.type === 'curly_bracket' &&
                      Severity: Minor
                      Found in core/parser/src/Parser.js - 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

                      Function parseNumber has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        parseNumber(isNegative = false) {
                          if (this.currentToken.type === 'number') {
                            const integer = this.currentToken.value
                      
                            const nextToken = this.getNextToken(1)
                      Severity: Minor
                      Found in core/parser/src/Parser.js - About 1 hr to fix

                        Function parseIdentifier has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          parseIdentifier() {
                            if (this.currentToken.type === 'identifier') {
                              const ident = this.currentToken.value
                              const nextToken = this.getNextToken(1)
                              if (nextToken.type === 'round_bracket' && nextToken.value === '(') {
                        Severity: Minor
                        Found in core/parser/src/Parser.js - About 1 hr to fix

                          Function parseStyleBody has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                          Open

                            parseStyleBody() {
                              const body = []
                          
                              if (
                                this.currentToken.type === 'curly_bracket' &&
                          Severity: Minor
                          Found in core/parser/src/Parser.js - 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

                          Function parse has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                            parse(input) {
                              this.tokens = tokenize(input.trim(), ruleMap, 'unknown').filter(
                                (token) => token.type !== 'whitespace'
                              )
                          
                          
                          Severity: Minor
                          Found in core/parser/src/Parser.js - About 45 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

                          Function parseVariant has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                            parseVariant() {
                              if (
                                this.currentToken.type === 'identifier' &&
                                this.currentToken.value === 'variant'
                              ) {
                          Severity: Minor
                          Found in core/parser/src/Parser.js - About 45 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

                          Avoid deeply nested control flow statements.
                          Open

                                      if (validation.type === 'property') {
                                        this.addError(
                                          {
                                            type: errorTypes.INVALID_PROPERTY,
                                            property: property,
                          Severity: Major
                          Found in core/parser/src/Parser.js - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                        if (
                                          validation.type === 'value' &&
                                          value.type !== 'Variable' &&
                                          value.type !== 'RawValue'
                                        ) {
                            Severity: Major
                            Found in core/parser/src/Parser.js - About 45 mins to fix

                              Function parseConditional has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                                parseConditional() {
                                  if (
                                    this.currentToken.type === 'square_bracket' &&
                                    this.currentToken.value === '['
                                  ) {
                              Severity: Minor
                              Found in core/parser/src/Parser.js - 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

                              Function parseStyle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                                parseStyle() {
                                  if (
                                    this.currentToken.type === 'identifier' &&
                                    this.currentToken.value === 'style'
                                  ) {
                              Severity: Minor
                              Found in core/parser/src/Parser.js - 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

                              Function parseNumber has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                parseNumber(isNegative = false) {
                                  if (this.currentToken.type === 'number') {
                                    const integer = this.currentToken.value
                              
                                    const nextToken = this.getNextToken(1)
                              Severity: Minor
                              Found in core/parser/src/Parser.js - 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

                              Function parseIdentifier has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                parseIdentifier() {
                                  if (this.currentToken.type === 'identifier') {
                                    const ident = this.currentToken.value
                                    const nextToken = this.getNextToken(1)
                                    if (nextToken.type === 'round_bracket' && nextToken.value === '(') {
                              Severity: Minor
                              Found in core/parser/src/Parser.js - 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

                                                  property +
                                                  ': ' +
                                                  value.value +
                                                  '\n' +
                                                  ' '.repeat(property.length + 2) +
                              Severity: Major
                              Found in core/parser/src/Parser.js and 1 other location - About 2 hrs to fix
                              core/parser/src/Parser.js on lines 448..466

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

                              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

                                                  property +
                                                  ': ' +
                                                  value.value +
                                                  '\n^-------\n' +
                                                  'The property ' +
                              Severity: Major
                              Found in core/parser/src/Parser.js and 1 other location - About 2 hrs to fix
                              core/parser/src/Parser.js on lines 485..506

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

                              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 (name && name.charAt(0).toUpperCase() !== name.charAt(0)) {
                                      this.addError(
                                        {
                                          type: errorTypes.SYNTAX_ERROR,
                                          message: 'Variant names must begin with an uppercase letter.',
                              Severity: Major
                              Found in core/parser/src/Parser.js and 1 other location - About 1 hr to fix
                              core/parser/src/Parser.js on lines 204..213

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

                              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 (name && name.charAt(0).toUpperCase() !== name.charAt(0)) {
                                      this.addError(
                                        {
                                          type: errorTypes.SYNTAX_ERROR,
                                          message: 'A style name must begin with an uppercase letter.',
                              Severity: Major
                              Found in core/parser/src/Parser.js and 1 other location - About 1 hr to fix
                              core/parser/src/Parser.js on lines 315..324

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

                              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