wordnik/swagger-editor

View on GitHub
src/plugins/ast/ast.js

Summary

Maintainability
F
3 days
Test Coverage

Function getLineNumberForPath has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

export function getLineNumberForPath(yaml, path) {

  // Type check
  if (typeof yaml !== "string") {
    throw new TypeError("yaml should be a string")
Severity: Minor
Found in src/plugins/ast/ast.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 pathForPosition has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

export function pathForPosition(yaml, position) {

  // Type check
  if (typeof yaml !== "string") {
    throw new TypeError("yaml should be a string")
Severity: Minor
Found in src/plugins/ast/ast.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 positionRangeForPath has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

export function positionRangeForPath(yaml, path) {

  // Type check
  if (typeof yaml !== "string") {
    throw new TypeError("yaml should be a string")
Severity: Minor
Found in src/plugins/ast/ast.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 pathForPosition has 67 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function pathForPosition(yaml, position) {

  // Type check
  if (typeof yaml !== "string") {
    throw new TypeError("yaml should be a string")
Severity: Major
Found in src/plugins/ast/ast.js - About 2 hrs to fix

    Function positionRangeForPath has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function positionRangeForPath(yaml, path) {
    
      // Type check
      if (typeof yaml !== "string") {
        throw new TypeError("yaml should be a string")
    Severity: Major
    Found in src/plugins/ast/ast.js - About 2 hrs to fix

      Function find has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function find(astValue, astKeyValue) {
          if (astValue.tag === MAP_TAG) {
            for (i = 0; i < astValue.value.length; i++) {
              var pair = astValue.value[i]
              var key = pair[0]
      Severity: Minor
      Found in src/plugins/ast/ast.js - About 1 hr to fix

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

        export function getLineNumberForPath(yaml, path) {
        
          // Type check
          if (typeof yaml !== "string") {
            throw new TypeError("yaml should be a string")
        Severity: Minor
        Found in src/plugins/ast/ast.js - About 1 hr to fix

          Function find has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            function find(current) {
          
              // algorythm:
              // is current a promitive?
              //   // finish recursion without modifying the path
          Severity: Minor
          Found in src/plugins/ast/ast.js - About 1 hr to fix

            Function find has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              function find(current, path, last) {
                if(!current) {
                  // something has gone quite wrong
                  // return the last start_mark as a best-effort
                  if(last && last.start_mark)
            Severity: Minor
            Found in src/plugins/ast/ast.js - About 1 hr to fix

              Avoid too many return statements within this function.
              Open

                      return find(item, path.slice(1), current.value)
              Severity: Major
              Found in src/plugins/ast/ast.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                      return current.start_mark.line + 1
                Severity: Major
                Found in src/plugins/ast/ast.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return path
                  Severity: Major
                  Found in src/plugins/ast/ast.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return current.start_mark.line
                    Severity: Major
                    Found in src/plugins/ast/ast.js - About 30 mins to fix

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

                            range.key_end = {
                              line: astKeyValue.end_mark.line,
                              column: astKeyValue.end_mark.column,
                              pointer: astKeyValue.end_mark.pointer,
                            }
                      Severity: Major
                      Found in src/plugins/ast/ast.js and 2 other locations - About 50 mins to fix
                      src/standalone/topbar-insert/forms/components/InsertFormInput.jsx on lines 99..103
                      src/standalone/topbar-menu-edit-convert/components/convert-modal.jsx on lines 184..188

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

                      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

                            end: {
                              line: astValue.end_mark.line,
                              column: astValue.end_mark.column,
                              pointer: astValue.end_mark.pointer,
                            }
                      Severity: Minor
                      Found in src/plugins/ast/ast.js and 1 other location - About 30 mins to fix
                      src/plugins/ast/ast.js on lines 139..143

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

                      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

                            start: {
                              line: astValue.start_mark.line,
                              column: astValue.start_mark.column,
                              pointer: astValue.start_mark.pointer,
                            },
                      Severity: Minor
                      Found in src/plugins/ast/ast.js and 1 other location - About 30 mins to fix
                      src/plugins/ast/ast.js on lines 144..148

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

                      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