NaturalIntelligence/fast-xml-parser

View on GitHub
src/v5/XmlPartReader.js

Summary

Maintainability
F
4 days
Test Coverage

Function readStopNode has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

function readStopNode(xmlDoc, tagName, i){
    const startIndex = i;
    // Starting at 1 since we already have an open tag
    let openTagCount = 1;
  
Severity: Minor
Found in src/v5/XmlPartReader.js - About 4 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 readPiExp has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

function readPiExp(parser) {
  let inSingleQuotes = false;
  let inDoubleQuotes = false;
  let i;
  let EOE = false;
Severity: Minor
Found in src/v5/XmlPartReader.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 readStopNode has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function readStopNode(xmlDoc, tagName, i){
    const startIndex = i;
    // Starting at 1 since we already have an open tag
    let openTagCount = 1;
  
Severity: Minor
Found in src/v5/XmlPartReader.js - About 1 hr to fix

    Function readPiExp has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function readPiExp(parser) {
      let inSingleQuotes = false;
      let inDoubleQuotes = false;
      let i;
      let EOE = false;
    Severity: Minor
    Found in src/v5/XmlPartReader.js - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                  if (tagData) {
                    const openTagName = tagData && tagData.tagName;
                    if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length-1] !== "/") {
                      openTagCount++;
                    }
      Severity: Major
      Found in src/v5/XmlPartReader.js - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                      if (openTagCount === 0) {
                        return {
                          tagContent: xmlDoc.substring(startIndex, i),
                          i : closeIndex
                        }
        Severity: Major
        Found in src/v5/XmlPartReader.js - About 45 mins to fix

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

          function readTagExp(parser) {
            let inSingleQuotes = false;
            let inDoubleQuotes = false;
            let i;
            let EOE = false;
          Severity: Minor
          Found in src/v5/XmlPartReader.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 buildTagExpObj has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          function buildTagExpObj(exp, parser){
            const tagExp = {
              tagName: "",
              selfClosing: false
            };
          Severity: Minor
          Found in src/v5/XmlPartReader.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

          'substr' is not defined.
          Open

            throw new Error(`Unexpected end of source. Reading '${substr}'`);
          Severity: Minor
          Found in src/v5/XmlPartReader.js by eslint

          Disallow Undeclared Variables (no-undef)

          This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

          Rule Details

          Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

          Examples of incorrect code for this rule:

          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          Examples of correct code for this rule with global declaration:

          /*global someFunction b:true*/
          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          The b:true syntax in /*global */ indicates that assignment to b is correct.

          Examples of incorrect code for this rule with global declaration:

          /*global b*/
          /*eslint no-undef: "error"*/
          
          b = 10;

          By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

          Options

          • typeof set to true will warn for variables used inside typeof check (Default false).

          typeof

          Examples of correct code for the default { "typeof": false } option:

          /*eslint no-undef: "error"*/
          
          if (typeof UndefinedIdentifier === "undefined") {
              // do something ...
          }

          You can use this option if you want to prevent typeof check on a variable which has not been declared.

          Examples of incorrect code for the { "typeof": true } option:

          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Examples of correct code for the { "typeof": true } option with global declaration:

          /*global a*/
          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Environments

          For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

          browser

          Examples of correct code for this rule with browser environment:

          /*eslint no-undef: "error"*/
          /*eslint-env browser*/
          
          setTimeout(function() {
              alert("Hello");
          });

          node

          Examples of correct code for this rule with node environment:

          /*eslint no-undef: "error"*/
          /*eslint-env node*/
          
          var fs = require("fs");
          module.exports = function() {
              console.log(fs);
          };

          When Not To Use It

          If explicit declaration of global variables is not to your taste.

          Compatibility

          This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

          'findSubStrIndex' is not defined.
          Open

                      const closeIndex = findSubStrIndex(xmlDoc, "?>", i+1, "StopNode is not closed.")
          Severity: Minor
          Found in src/v5/XmlPartReader.js by eslint

          Disallow Undeclared Variables (no-undef)

          This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

          Rule Details

          Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

          Examples of incorrect code for this rule:

          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          Examples of correct code for this rule with global declaration:

          /*global someFunction b:true*/
          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          The b:true syntax in /*global */ indicates that assignment to b is correct.

          Examples of incorrect code for this rule with global declaration:

          /*global b*/
          /*eslint no-undef: "error"*/
          
          b = 10;

          By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

          Options

          • typeof set to true will warn for variables used inside typeof check (Default false).

          typeof

          Examples of correct code for the default { "typeof": false } option:

          /*eslint no-undef: "error"*/
          
          if (typeof UndefinedIdentifier === "undefined") {
              // do something ...
          }

          You can use this option if you want to prevent typeof check on a variable which has not been declared.

          Examples of incorrect code for the { "typeof": true } option:

          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Examples of correct code for the { "typeof": true } option with global declaration:

          /*global a*/
          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Environments

          For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

          browser

          Examples of correct code for this rule with browser environment:

          /*eslint no-undef: "error"*/
          /*eslint-env browser*/
          
          setTimeout(function() {
              alert("Hello");
          });

          node

          Examples of correct code for this rule with node environment:

          /*eslint no-undef: "error"*/
          /*eslint-env node*/
          
          var fs = require("fs");
          module.exports = function() {
              console.log(fs);
          };

          When Not To Use It

          If explicit declaration of global variables is not to your taste.

          Compatibility

          This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

          'findSubStrIndex' is not defined.
          Open

                      const closeIndex = findSubStrIndex(xmlDoc, ">", i, `${tagName} is not closed`);
          Severity: Minor
          Found in src/v5/XmlPartReader.js by eslint

          Disallow Undeclared Variables (no-undef)

          This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

          Rule Details

          Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

          Examples of incorrect code for this rule:

          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          Examples of correct code for this rule with global declaration:

          /*global someFunction b:true*/
          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          The b:true syntax in /*global */ indicates that assignment to b is correct.

          Examples of incorrect code for this rule with global declaration:

          /*global b*/
          /*eslint no-undef: "error"*/
          
          b = 10;

          By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

          Options

          • typeof set to true will warn for variables used inside typeof check (Default false).

          typeof

          Examples of correct code for the default { "typeof": false } option:

          /*eslint no-undef: "error"*/
          
          if (typeof UndefinedIdentifier === "undefined") {
              // do something ...
          }

          You can use this option if you want to prevent typeof check on a variable which has not been declared.

          Examples of incorrect code for the { "typeof": true } option:

          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Examples of correct code for the { "typeof": true } option with global declaration:

          /*global a*/
          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Environments

          For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

          browser

          Examples of correct code for this rule with browser environment:

          /*eslint no-undef: "error"*/
          /*eslint-env browser*/
          
          setTimeout(function() {
              alert("Hello");
          });

          node

          Examples of correct code for this rule with node environment:

          /*eslint no-undef: "error"*/
          /*eslint-env node*/
          
          var fs = require("fs");
          module.exports = function() {
              console.log(fs);
          };

          When Not To Use It

          If explicit declaration of global variables is not to your taste.

          Compatibility

          This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

          'findSubStrIndex' is not defined.
          Open

                      const closeIndex = findSubStrIndex(xmlDoc, "]]>", i, "StopNode is not closed.") - 2;
          Severity: Minor
          Found in src/v5/XmlPartReader.js by eslint

          Disallow Undeclared Variables (no-undef)

          This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

          Rule Details

          Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

          Examples of incorrect code for this rule:

          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          Examples of correct code for this rule with global declaration:

          /*global someFunction b:true*/
          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          The b:true syntax in /*global */ indicates that assignment to b is correct.

          Examples of incorrect code for this rule with global declaration:

          /*global b*/
          /*eslint no-undef: "error"*/
          
          b = 10;

          By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

          Options

          • typeof set to true will warn for variables used inside typeof check (Default false).

          typeof

          Examples of correct code for the default { "typeof": false } option:

          /*eslint no-undef: "error"*/
          
          if (typeof UndefinedIdentifier === "undefined") {
              // do something ...
          }

          You can use this option if you want to prevent typeof check on a variable which has not been declared.

          Examples of incorrect code for the { "typeof": true } option:

          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Examples of correct code for the { "typeof": true } option with global declaration:

          /*global a*/
          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Environments

          For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

          browser

          Examples of correct code for this rule with browser environment:

          /*eslint no-undef: "error"*/
          /*eslint-env browser*/
          
          setTimeout(function() {
              alert("Hello");
          });

          node

          Examples of correct code for this rule with node environment:

          /*eslint no-undef: "error"*/
          /*eslint-env node*/
          
          var fs = require("fs");
          module.exports = function() {
              console.log(fs);
          };

          When Not To Use It

          If explicit declaration of global variables is not to your taste.

          Compatibility

          This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

          'findSubStrIndex' is not defined.
          Open

                      const closeIndex = findSubStrIndex(xmlDoc, "-->", i+3, "StopNode is not closed.")
          Severity: Minor
          Found in src/v5/XmlPartReader.js by eslint

          Disallow Undeclared Variables (no-undef)

          This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

          Rule Details

          Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

          Examples of incorrect code for this rule:

          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          Examples of correct code for this rule with global declaration:

          /*global someFunction b:true*/
          /*eslint no-undef: "error"*/
          
          var a = someFunction();
          b = 10;

          The b:true syntax in /*global */ indicates that assignment to b is correct.

          Examples of incorrect code for this rule with global declaration:

          /*global b*/
          /*eslint no-undef: "error"*/
          
          b = 10;

          By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

          Options

          • typeof set to true will warn for variables used inside typeof check (Default false).

          typeof

          Examples of correct code for the default { "typeof": false } option:

          /*eslint no-undef: "error"*/
          
          if (typeof UndefinedIdentifier === "undefined") {
              // do something ...
          }

          You can use this option if you want to prevent typeof check on a variable which has not been declared.

          Examples of incorrect code for the { "typeof": true } option:

          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Examples of correct code for the { "typeof": true } option with global declaration:

          /*global a*/
          /*eslint no-undef: ["error", { "typeof": true }] */
          
          if(typeof a === "string"){}

          Environments

          For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

          browser

          Examples of correct code for this rule with browser environment:

          /*eslint no-undef: "error"*/
          /*eslint-env browser*/
          
          setTimeout(function() {
              alert("Hello");
          });

          node

          Examples of correct code for this rule with node environment:

          /*eslint no-undef: "error"*/
          /*eslint-env node*/
          
          var fs = require("fs");
          module.exports = function() {
              console.log(fs);
          };

          When Not To Use It

          If explicit declaration of global variables is not to your taste.

          Compatibility

          This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

          TODO found
          Open

              //TODO: use regex to verify attributes if not set to ignore
          Severity: Minor
          Found in src/v5/XmlPartReader.js by fixme

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

          function readStopNode(xmlDoc, tagName, i){
              const startIndex = i;
              // Starting at 1 since we already have an open tag
              let openTagCount = 1;
            
          Severity: Major
          Found in src/v5/XmlPartReader.js and 1 other location - About 2 days to fix
          src/xmlparser/OrderedObjParser.js on lines 540..582

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

          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

          const getAllMatches = function(string, regex) {
            const matches = [];
            let match = regex.exec(string);
            while (match) {
              const allmatches = [];
          Severity: Major
          Found in src/v5/XmlPartReader.js and 1 other location - About 6 hrs to fix
          src/util.js on lines 8..22

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

          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