18F/web-design-standards

View on GitHub
packages/usa-file-input/src/index.js

Summary

Maintainability
D
2 days
Test Coverage

File index.js has 359 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const selectOrMatches = require("../../uswds-core/src/js/utils/select-or-matches");
const behavior = require("../../uswds-core/src/js/utils/behavior");
const Sanitizer = require("../../uswds-core/src/js/utils/sanitizer");
const { prefix: PREFIX } = require("../../uswds-core/src/js/config");

Severity: Minor
Found in packages/usa-file-input/src/index.js - About 4 hrs to fix

    Function handleChange has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const handleChange = (e, fileInputEl, instructions, dropTarget) => {
      const fileNames = e.target.files;
      const inputParent = dropTarget.closest(`.${DROPZONE_CLASS}`);
      const statusElement = inputParent.querySelector(`.${SR_ONLY_CLASS}`);
      const fileStore = [];
    Severity: Major
    Found in packages/usa-file-input/src/index.js - About 2 hrs to fix

      Function preventInvalidFiles has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      const preventInvalidFiles = (e, fileInputEl, instructions, dropTarget) => {
        const acceptedFilesAttr = fileInputEl.getAttribute("accept");
        dropTarget.classList.remove(INVALID_FILE_CLASS);
      
        /**
      Severity: Minor
      Found in packages/usa-file-input/src/index.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 preventInvalidFiles has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const preventInvalidFiles = (e, fileInputEl, instructions, dropTarget) => {
        const acceptedFilesAttr = fileInputEl.getAttribute("accept");
        dropTarget.classList.remove(INVALID_FILE_CLASS);
      
        /**
      Severity: Minor
      Found in packages/usa-file-input/src/index.js - About 1 hr to fix

        Function handleChange has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        const handleChange = (e, fileInputEl, instructions, dropTarget) => {
          const fileNames = e.target.files;
          const inputParent = dropTarget.closest(`.${DROPZONE_CLASS}`);
          const statusElement = inputParent.querySelector(`.${SR_ONLY_CLASS}`);
          const fileStore = [];
        Severity: Minor
        Found in packages/usa-file-input/src/index.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 createFilePreview has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            reader.onloadend = function createFilePreview() {
              const previewImage = document.getElementById(imageId);
              if (fileName.indexOf(".pdf") > 0) {
                previewImage.setAttribute(
                  "onerror",
        Severity: Minor
        Found in packages/usa-file-input/src/index.js - About 1 hr to fix

          Function init has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              init(root) {
                selectOrMatches(DROPZONE, root).forEach((fileInputEl) => {
                  const { instructions, dropTarget } = enhanceFileInput(fileInputEl);
          
                  dropTarget.addEventListener(
          Severity: Minor
          Found in packages/usa-file-input/src/index.js - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                      if (allFilesAllowed) {
                        TYPE_IS_VALID = true;
                        break;
                      }
            Severity: Major
            Found in packages/usa-file-input/src/index.js - About 45 mins to fix

              There are no issues that match your filters.

              Category
              Status