department-of-veterans-affairs/vets-website

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

Summary

Maintainability
F
5 days
Test Coverage

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

import { dropRight, merge } from 'lodash';
import { getDefaultFormState } from '@department-of-veterans-affairs/react-jsonschema-form/lib/utils';
import dataGet from '../../../../utilities/data/get';
import set from '../../../../utilities/data/set';
import unset from '../../../../utilities/data/unset';
Severity: Major
Found in src/platform/forms-system/src/js/state/helpers.js - About 1 day to fix

    Function updateRequiredFields has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    export function updateRequiredFields(schema, uiSchema, formData, index = null) {
      if (!uiSchema) {
        return schema;
      }
    
    
    Severity: Minor
    Found in src/platform/forms-system/src/js/state/helpers.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 setHiddenFields has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    export function setHiddenFields(schema, uiSchema, formData, path = []) {
      if (!uiSchema) {
        return schema;
      }
    
    
    Severity: Minor
    Found in src/platform/forms-system/src/js/state/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 updateSchemaFromUiSchema has 76 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function updateSchemaFromUiSchema(
      schema,
      uiSchema,
      formData,
      index = null,
    Severity: Major
    Found in src/platform/forms-system/src/js/state/helpers.js - About 3 hrs to fix

      Function updateSchemaFromUiSchema has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

      export function updateSchemaFromUiSchema(
        schema,
        uiSchema,
        formData,
        index = null,
      Severity: Minor
      Found in src/platform/forms-system/src/js/state/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 setHiddenFields has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function setHiddenFields(schema, uiSchema, formData, path = []) {
        if (!uiSchema) {
          return schema;
        }
      
      
      Severity: Major
      Found in src/platform/forms-system/src/js/state/helpers.js - About 2 hrs to fix

        Function createInitialState has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function createInitialState(formConfig) {
          let initialState = {
            submission: {
              status: false,
              errorMessage: false,
        Severity: Major
        Found in src/platform/forms-system/src/js/state/helpers.js - About 2 hrs to fix

          Function updateRequiredFields has 56 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function updateRequiredFields(schema, uiSchema, formData, index = null) {
            if (!uiSchema) {
              return schema;
            }
          
          
          Severity: Major
          Found in src/platform/forms-system/src/js/state/helpers.js - About 2 hrs to fix

            Function updateItemsSchema has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function updateItemsSchema(schema, fieldData = null) {
              if (schema.type === 'array') {
                let newSchema = schema;
            
                // This happens the first time this function is called when
            Severity: Minor
            Found in src/platform/forms-system/src/js/state/helpers.js - About 1 hr to fix

              Function replaceRefSchemas has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function replaceRefSchemas(schema, definitions, path = '') {
                // this can happen if you import a field that doesn’t exist from a schema
                if (!schema) {
                  throw new Error(`Schema is undefined at ${path}`);
                }
              Severity: Minor
              Found in src/platform/forms-system/src/js/state/helpers.js - About 1 hr to fix

                Function recalculateSchemaAndData has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function recalculateSchemaAndData(initialState) {
                  return Object.keys(initialState.pages).reduce((state, pageKey) => {
                    // on each data change, we need to do the following steps
                    // Recalculate any required fields, based on the new data
                    const page = state.pages[pageKey];
                Severity: Minor
                Found in src/platform/forms-system/src/js/state/helpers.js - About 1 hr to fix

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

                  export function updateItemsSchema(schema, fieldData = null) {
                    if (schema.type === 'array') {
                      let newSchema = schema;
                  
                      // This happens the first time this function is called when
                  Severity: Minor
                  Found in src/platform/forms-system/src/js/state/helpers.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 updateUiSchema has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function updateUiSchema(schema, uiSchema, formData) {
                    if (!uiSchema) {
                      return uiSchema;
                    }
                  
                  
                  Severity: Minor
                  Found in src/platform/forms-system/src/js/state/helpers.js - About 1 hr to fix

                    Function replaceRefSchemas has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export function replaceRefSchemas(schema, definitions, path = '') {
                      // this can happen if you import a field that doesn’t exist from a schema
                      if (!schema) {
                        throw new Error(`Schema is undefined at ${path}`);
                      }
                    Severity: Minor
                    Found in src/platform/forms-system/src/js/state/helpers.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 removeHiddenData has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function removeHiddenData(schema, data) {
                      // null is necessary here because Rails 4 will convert empty arrays to null
                      // In the forms, there's no difference between an empty array and null or undefined
                      if (isHiddenField(schema) || typeof data === 'undefined' || data === null) {
                        return undefined;
                    Severity: Minor
                    Found in src/platform/forms-system/src/js/state/helpers.js - About 1 hr to fix

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

                          (state, page) => {
                            const definitions = {
                              ...(formConfig.defaultDefinitions || {}),
                              ...page.schema.definitions,
                            };
                      Severity: Minor
                      Found in src/platform/forms-system/src/js/state/helpers.js - About 1 hr to fix

                        Function updateUiSchema has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                        export function updateUiSchema(schema, uiSchema, formData) {
                          if (!uiSchema) {
                            return uiSchema;
                          }
                        
                        
                        Severity: Minor
                        Found in src/platform/forms-system/src/js/state/helpers.js - About 55 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 updateSchemaFromUiSchema has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          schema,
                          uiSchema,
                          formData,
                          index = null,
                          path = [],
                        Severity: Minor
                        Found in src/platform/forms-system/src/js/state/helpers.js - About 35 mins to fix

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

                          export function removeHiddenData(schema, data) {
                            // null is necessary here because Rails 4 will convert empty arrays to null
                            // In the forms, there's no difference between an empty array and null or undefined
                            if (isHiddenField(schema) || typeof data === 'undefined' || data === null) {
                              return undefined;
                          Severity: Minor
                          Found in src/platform/forms-system/src/js/state/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 schema;
                          Severity: Major
                          Found in src/platform/forms-system/src/js/state/helpers.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

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

                              There are no issues that match your filters.

                              Category
                              Status