department-of-veterans-affairs/vets-website

View on GitHub
src/applications/appeals/shared/components/FileField.jsx

Summary

Maintainability
F
1 wk
Test Coverage

Function FileField has 490 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const FileField = props => {
  const {
    errorSchema,
    formContext,
    formData = [],
Severity: Major
Found in src/applications/appeals/shared/components/FileField.jsx - About 2 days to fix

    Function FileField has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
    Open

    const FileField = props => {
      const {
        errorSchema,
        formContext,
        formData = [],
    Severity: Minor
    Found in src/applications/appeals/shared/components/FileField.jsx - About 1 day 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 FileField.jsx has 552 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import PropTypes from 'prop-types';
    import React, { useEffect, useState, useRef } from 'react';
    import classNames from 'classnames';
    import { VaModal } from '@department-of-veterans-affairs/component-library/dist/react-bindings';
    
    
    Severity: Major
    Found in src/applications/appeals/shared/components/FileField.jsx - About 1 day to fix

      Function onAddFile has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        const onAddFile = async (event, index = null, password) => {
          if (event.target?.files?.length) {
            // Only upload the first file; when va-file-input v3 supports multiple
            // files, we'll need to update this entire component
            const currentFile = event.target.files[0];
      Severity: Major
      Found in src/applications/appeals/shared/components/FileField.jsx - About 2 hrs to fix

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

                        {!hasVisibleError &&
                          !showPasswordInput &&
                          get('properties.attachmentId', itemSchema) && (
                            <Tag className="schemaform-file-attachment review">
                              <SchemaField
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 3 other locations - About 6 hrs to fix
        src/applications/pre-need/components/FileField.jsx on lines 563..582
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 568..587
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 577..596

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

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

                        {!hasVisibleError &&
                          !showPasswordInput &&
                          uiOptions.attachmentName && (
                            <Tag className="schemaform-file-attachment review">
                              <SchemaField
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 3 other locations - About 6 hrs to fix
        src/applications/pre-need/components/FileField.jsx on lines 583..602
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 588..607
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 597..616

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

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

          const removeFile = (index, focusAddButton = true) => {
            const newFileList = props.formData.filter((__, idx) => index !== idx);
            if (!newFileList.length) {
              props.onChange();
            } else {
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 3 other locations - About 4 hrs to fix
        src/applications/pre-need/components/FileField.jsx on lines 345..363
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 357..375
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 344..362

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

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

          const closeRemoveModal = ({ remove = false } = {}) => {
            const idx = removeIndex;
            setRemoveIndex(null);
            setShowRemoveModal(false);
            if (remove) {
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 3 other locations - About 3 hrs to fix
        src/applications/pre-need/components/FileField.jsx on lines 370..385
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 382..397
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 369..384

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

        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

                  <input
                    type="file"
                    ref={fileInputRef}
                    accept={uiOptions.fileTypes.map(item => `.${item}`).join(',')}
                    className="vads-u-display--none"
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 1 other location - About 2 hrs to fix
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 688..696

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

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

                        {!file.uploading && (
                          <>
                            <strong
                              id={fileNameId}
                              className="dd-privacy-hidden"
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 3 other locations - About 2 hrs to fix
        src/applications/pre-need/components/FileField.jsx on lines 550..561
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 552..563
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 561..572

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

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

          const onAttachmentNameChange = (index, value) => {
            if (!value) {
              props.onChange(unset([index, 'name'], props.formData));
            } else {
              props.onChange(set([index, 'name'], value, props.formData));
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 7 other locations - About 1 hr to fix
        src/applications/appeals/shared/components/FileField.jsx on lines 281..287
        src/applications/pre-need/components/FileField.jsx on lines 329..335
        src/applications/pre-need/components/FileField.jsx on lines 337..343
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 341..347
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 349..355
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 328..334
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 336..342

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

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

          const onAttachmentIdChange = (index, value) => {
            if (!value) {
              props.onChange(unset([index, 'attachmentId'], props.formData));
            } else {
              props.onChange(set([index, 'attachmentId'], value, props.formData));
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 7 other locations - About 1 hr to fix
        src/applications/appeals/shared/components/FileField.jsx on lines 289..295
        src/applications/pre-need/components/FileField.jsx on lines 329..335
        src/applications/pre-need/components/FileField.jsx on lines 337..343
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 341..347
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 349..355
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 328..334
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 336..342

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

        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

                        {showPasswordInput && (
                          <ShowPdfPassword
                            file={file.file}
                            index={index}
                            onSubmitPassword={onSubmitPassword}
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 1 other location - About 1 hr to fix
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 614..622

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

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

          const onSubmitPassword = (file, index, password) => {
            if (file && password) {
              onAddFile({ target: { files: [file] } }, index, password);
            }
          };
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 2 other locations - About 40 mins to fix
        src/applications/simple-forms/40-0247/components/FileField.jsx on lines 335..339
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 322..326

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

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

                    const getUiSchema = innerUiSchema =>
                      typeof innerUiSchema === 'function'
                        ? innerUiSchema({
                            fileId: fileNameId,
                            index,
        Severity: Major
        Found in src/applications/appeals/shared/components/FileField.jsx and 2 other locations - About 40 mins to fix
        src/applications/pre-need/components/FileField.jsx on lines 505..512
        src/platform/forms-system/src/js/fields/FileField.jsx on lines 516..523

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

        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