packages/usa-file-input/src/index.js
File index.js
has 359 lines of code (exceeds 250 allowed). Consider refactoring. Open
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");
Function handleChange
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
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 = [];
Function preventInvalidFiles
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
Open
const preventInvalidFiles = (e, fileInputEl, instructions, dropTarget) => {
const acceptedFilesAttr = fileInputEl.getAttribute("accept");
dropTarget.classList.remove(INVALID_FILE_CLASS);
/**
- Read upRead up
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
Open
const preventInvalidFiles = (e, fileInputEl, instructions, dropTarget) => {
const acceptedFilesAttr = fileInputEl.getAttribute("accept");
dropTarget.classList.remove(INVALID_FILE_CLASS);
/**
Function handleChange
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
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 = [];
- Read upRead up
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
Open
reader.onloadend = function createFilePreview() {
const previewImage = document.getElementById(imageId);
if (fileName.indexOf(".pdf") > 0) {
previewImage.setAttribute(
"onerror",
Function init
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
init(root) {
selectOrMatches(DROPZONE, root).forEach((fileInputEl) => {
const { instructions, dropTarget } = enhanceFileInput(fileInputEl);
dropTarget.addEventListener(
Avoid deeply nested control flow statements. Open
Open
if (allFilesAllowed) {
TYPE_IS_VALID = true;
break;
}