NaturalIntelligence/fast-xml-parser

View on GitHub
src/xmlparser/node2json.js

Summary

Maintainability
C
1 day
Test Coverage

Function compress has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

function compress(arr, options, jPath){
  let text;
  const compressedObj = {};
  for (let i = 0; i < arr.length; i++) {
    const tagObj = arr[i];
Severity: Minor
Found in src/xmlparser/node2json.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 compress has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function compress(arr, options, jPath){
  let text;
  const compressedObj = {};
  for (let i = 0; i < arr.length; i++) {
    const tagObj = arr[i];
Severity: Minor
Found in src/xmlparser/node2json.js - About 1 hr to fix

    Avoid deeply nested control flow statements.
    Open

            if(options.alwaysCreateTextNode) val[options.textNodeName] = "";
            else val = "";
    Severity: Major
    Found in src/xmlparser/node2json.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

              if (options.isArray(property, newJpath, isLeaf )) {
                compressedObj[property] = [val];
              }else{
                compressedObj[property] = val;
              }
      Severity: Major
      Found in src/xmlparser/node2json.js - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                if(!Array.isArray(compressedObj[property])) {
                    compressedObj[property] = [ compressedObj[property] ];
                }
        Severity: Major
        Found in src/xmlparser/node2json.js - About 45 mins to fix

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

          function assignAttributes(obj, attrMap, jpath, options){
            if (attrMap) {
              const keys = Object.keys(attrMap);
              const len = keys.length; //don't make it inline
              for (let i = 0; i < len; i++) {
          Severity: Minor
          Found in src/xmlparser/node2json.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

          TODO found
          Open

                  //TODO: if a node is not an array, then check if it should be an array
          Severity: Minor
          Found in src/xmlparser/node2json.js by fixme

          There are no issues that match your filters.

          Category
          Status