KarrLab/datanator_frontend

View on GitHub
src/utils/utils.js

Summary

Maintainability
D
3 days
Test Coverage
A
92%

Function replaceNanWithNull has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

function replaceNanWithNull(value) {
  if (Number.isNaN(value)) {
    return null;
  }

Severity: Minor
Found in src/utils/utils.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

File utils.js has 286 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from "react";

function matchAll(string, regex) {
  const matches = [];
  string.replace(regex, function () {
Severity: Minor
Found in src/utils/utils.js - About 2 hrs to fix

    Function dictOfArraysToArrayOfDicts has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    function dictOfArraysToArrayOfDicts(dictOfArrays) {
      const arrayOfDicts = [];
      for (const key in dictOfArrays) {
        if (Array.isArray(dictOfArrays[key])) {
          for (let iEl = 0; iEl < dictOfArrays[key].length; iEl++) {
    Severity: Minor
    Found in src/utils/utils.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 replaceNanWithNull has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function replaceNanWithNull(value) {
      if (Number.isNaN(value)) {
        return null;
      }
    
    
    Severity: Minor
    Found in src/utils/utils.js - About 1 hr to fix

      Function formatScientificNotation has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      function formatScientificNotation(
        value,
        sciMagUpThresh = 1,
        sciMagDownThresh = 1,
        sciDecimals = 1,
      Severity: Minor
      Found in src/utils/utils.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 formatScientificNotation has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        value,
        sciMagUpThresh = 1,
        sciMagDownThresh = 1,
        sciDecimals = 1,
        fixedDeminals = 1,
      Severity: Major
      Found in src/utils/utils.js - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                for (const key in val) {
                  const v = val[key];
                  if (Number.isNaN(v)) {
                    val[key] = null;
                  } else if (
        Severity: Major
        Found in src/utils/utils.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    if (Number.isNaN(v)) {
                      val[i] = null;
                    } else if (
                      v != null &&
                      v !== undefined &&
          Severity: Major
          Found in src/utils/utils.js - About 45 mins to fix

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

            function parseHistoryLocationPathname(history) {
              const pathRegex = /^(\/(.*?)(\/(.*?)(\/(.*?))?)?)?\/?$/;
              const match = history.location.pathname.match(pathRegex);
              let route = null;
              let query = null;
            Severity: Minor
            Found in src/utils/utils.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 formatChemicalFormula has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            function formatChemicalFormula(formula) {
              if (!formula) {
                return null;
              }
            
            
            Severity: Minor
            Found in src/utils/utils.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

            Avoid too many return statements within this function.
            Open

                return value.toFixed(decimals);
            Severity: Major
            Found in src/utils/utils.js - About 30 mins to fix

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

              function removeDuplicates(array, keyFunc = null) {
                const uniqueKeyVals = {};
              
                for (const el of array) {
                  let key;
              Severity: Minor
              Found in src/utils/utils.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 castToArray has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              function castToArray(obj) {
                if (Array.isArray(obj)) {
                  return obj;
                } else {
                  if (obj == null || obj === undefined) {
              Severity: Minor
              Found in src/utils/utils.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 isEmpty has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              function isEmpty(element) {
                if (element instanceof Array) {
                  if (element.length === 0) {
                    return true;
                  }
              Severity: Minor
              Found in src/utils/utils.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

                      for (let i = 0; i < val.length; i++) {
                        const v = val[i];
                        if (Number.isNaN(v)) {
                          val[i] = null;
                        } else if (
              Severity: Major
              Found in src/utils/utils.js and 1 other location - About 3 hrs to fix
              src/utils/utils.js on lines 274..285

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

              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

                      for (const key in val) {
                        const v = val[key];
                        if (Number.isNaN(v)) {
                          val[key] = null;
                        } else if (
              Severity: Major
              Found in src/utils/utils.js and 1 other location - About 3 hrs to fix
              src/utils/utils.js on lines 261..272

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

              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