department-of-veterans-affairs/vets-website

View on GitHub
src/platform/forms-system/src/js/helpers.js

Summary

Maintainability
F
4 days
Test Coverage

File helpers.js has 606 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { useEffect, useRef } from 'react';
import moment from 'moment';
import { intersection, matches, merge, uniq } from 'lodash';
import shouldUpdate from 'recompose/shouldUpdate';
import { deepEquals } from '@department-of-veterans-affairs/react-jsonschema-form/lib/utils';
Severity: Major
Found in src/platform/forms-system/src/js/helpers.js - About 1 day to fix

    Function checkValidSchema has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    export function checkValidSchema(schema, errors = [], path = ['root']) {
      if (typeof schema.type !== 'string') {
        errors.push(`Missing type in ${path.join('.')} schema.`);
      }
    
    
    Severity: Minor
    Found in src/platform/forms-system/src/js/helpers.js - About 3 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 getNonArraySchema has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    export function getNonArraySchema(schema, uiSchema = {}) {
      if (
        schema.type === 'array' &&
        !get('ui:options.keepInPageOnReview', uiSchema)
      ) {
    Severity: Minor
    Found in src/platform/forms-system/src/js/helpers.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 createStringifyFormReplacer has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    export function createStringifyFormReplacer(options) {
      const replacerFn = (key, value) => {
        if (!options?.allowPartialAddress && isPartialAddress(value)) {
          return undefined;
        }
    Severity: Minor
    Found in src/platform/forms-system/src/js/helpers.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 getNonArraySchema has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function getNonArraySchema(schema, uiSchema = {}) {
      if (
        schema.type === 'array' &&
        !get('ui:options.keepInPageOnReview', uiSchema)
      ) {
    Severity: Major
    Found in src/platform/forms-system/src/js/helpers.js - About 2 hrs to fix

      Function checkValidSchema has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function checkValidSchema(schema, errors = [], path = ['root']) {
        if (typeof schema.type !== 'string') {
          errors.push(`Missing type in ${path.join('.')} schema.`);
        }
      
      
      Severity: Major
      Found in src/platform/forms-system/src/js/helpers.js - About 2 hrs to fix

        Function expandArrayPages has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function expandArrayPages(pageList, data) {
          const result = pageList.reduce(
            (acc, nextPage) => {
              const { lastArrayPath, arrayPages, currentList } = acc;
              // If we see an array page and we’re starting a section or in the middle of one, just add it
        Severity: Minor
        Found in src/platform/forms-system/src/js/helpers.js - About 1 hr to fix

          Function createStringifyFormReplacer has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function createStringifyFormReplacer(options) {
            const replacerFn = (key, value) => {
              if (!options?.allowPartialAddress && isPartialAddress(value)) {
                return undefined;
              }
          Severity: Minor
          Found in src/platform/forms-system/src/js/helpers.js - About 1 hr to fix

            Function showReviewField has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              propName,
              schema,
              uiSchema,
              formData,
              formContext,
            Severity: Minor
            Found in src/platform/forms-system/src/js/helpers.js - About 35 mins to fix

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

              export function hideFormTitle(formConfig, pathName) {
                if (
                  !formConfig?.chapters ||
                  typeof formConfig.chapters !== 'object' ||
                  formConfig.chapters.length === 0
              Severity: Minor
              Found in src/platform/forms-system/src/js/helpers.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 parseISODate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              export function parseISODate(dateString) {
                if (typeof dateString === 'string') {
                  const [year = 'XXXX', month = 'XX', day = 'XX'] = dateString.split('-', 3);
              
                  return {
              Severity: Minor
              Found in src/platform/forms-system/src/js/helpers.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 getArrayFields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              export function getArrayFields(data) {
                const fields = [];
                const findArrays = (obj, ui, path = []) => {
                  if (
                    obj.type === 'array' &&
              Severity: Minor
              Found in src/platform/forms-system/src/js/helpers.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 expandArrayPages has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              export function expandArrayPages(pageList, data) {
                const result = pageList.reduce(
                  (acc, nextPage) => {
                    const { lastArrayPath, arrayPages, currentList } = acc;
                    // If we see an array page and we’re starting a section or in the middle of one, just add it
              Severity: Minor
              Found in src/platform/forms-system/src/js/helpers.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 newValues.length > 0 ? newValues : undefined;
              Severity: Major
              Found in src/platform/forms-system/src/js/helpers.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return value;
                Severity: Major
                Found in src/platform/forms-system/src/js/helpers.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return newData;
                  Severity: Major
                  Found in src/platform/forms-system/src/js/helpers.js - About 30 mins to fix

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

                    function formatDayMonth(val) {
                      if (val) {
                        const dayOrMonth = val.toString();
                        if (Number(dayOrMonth) && dayOrMonth.length === 1) {
                          return `0${val}`;
                    Severity: Minor
                    Found in src/platform/forms-system/src/js/helpers.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

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

                    export function isActivePage(page, data) {
                      if (typeof page.depends === 'function') {
                        return page.depends(data, page.index);
                      }
                    
                    
                    Severity: Major
                    Found in src/platform/forms-system/src/js/helpers.js and 1 other location - About 4 hrs to fix
                    src/platform/forms/helpers.js on lines 76..86

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

                    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

                        if (year.length > 4) {
                          year = dateString.substring(0, 4);
                          month = dateString.substring(4, 6);
                          day = dateString.substring(6, 8);
                        }
                    Severity: Major
                    Found in src/platform/forms-system/src/js/helpers.js and 1 other location - About 1 hr to fix
                    src/applications/accredited-representative-portal/accreditation/21a/pages/helpers/formatReviewDate.js on lines 33..37

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

                    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 3 locations. Consider refactoring.
                    Open

                        trimmedPathname.endsWith('introduction') ||
                        trimmedPathname.endsWith('confirmation') ||
                        trimmedPathname.endsWith('form-saved') ||
                        trimmedPathname.endsWith('error')
                    Severity: Minor
                    Found in src/platform/forms-system/src/js/helpers.js and 2 other locations - About 30 mins to fix
                    src/applications/claims-status/utils/page.js on lines 32..35
                    src/applications/vaos/scripts/gherkin.js on lines 38..41

                    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