18F/web-design-standards

View on GitHub

Showing 67 of 368 total issues

Function createInPageNav has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const createInPageNav = (inPageNavEl) => {
  const inPageNavTitleText = Sanitizer.escapeHTML`${
    inPageNavEl.dataset.titleText || IN_PAGE_NAV_TITLE_TEXT
  }`;
  const inPageNavTitleHeadingLevel = Sanitizer.escapeHTML`${
Severity: Major
Found in packages/usa-in-page-navigation/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 transformTimePicker has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const transformTimePicker = (el) => {
      const timePickerEl = el.closest(TIME_PICKER);
    
      const initialInputEl = timePickerEl.querySelector(`input`);
    
    
    Severity: Major
    Found in packages/usa-time-picker/src/index.js - About 2 hrs to fix

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

      const parseDateString = (
        dateString,
        dateFormat = INTERNAL_DATE_FORMAT,
        adjustDate = false
      ) => {
      Severity: Major
      Found in packages/usa-date-picker/src/index.js - About 2 hrs to fix

        Function enhanceDatePicker has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const enhanceDatePicker = (el) => {
          const datePickerEl = el.closest(DATE_PICKER);
          const { defaultValue } = datePickerEl.dataset;
        
          const internalInputEl = datePickerEl.querySelector(`input`);
        Severity: Major
        Found in packages/usa-date-picker/src/index.js - About 2 hrs to fix

          File usa-icons.config.js has 254 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          const config = {
            material: [
              "accessibility_new",
              "accessible_forward",
              "account_balance",
          Severity: Minor
          Found in packages/usa-icon/src/usa-icons.config.js - About 2 hrs to fix

            Function oninterval has 52 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function oninterval() {
                  // if all <use>s in the array are being bypassed, don't proceed.
                  if (
                    numberOfSvgUseElementsToBypass &&
                    uses.length - numberOfSvgUseElementsToBypass <= 0
            Severity: Major
            Found in packages/uswds-core/src/js/polyfills/svg4everybody.js - About 2 hrs to fix

              Function displayMonthSelection has 49 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const displayMonthSelection = (el, monthToDisplay) => {
                const { calendarEl, statusEl, calendarDate, minDate, maxDate } =
                  getDatePickerContext(el);
              
                const selectedMonth = calendarDate.getMonth();
              Severity: Minor
              Found in packages/usa-date-picker/src/index.js - About 1 hr to fix

                Function handleCurrentValue has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                const handleCurrentValue = (el) => {
                  const isCharsetPresent = el.dataset.charset;
                  const placeholder = isCharsetPresent || el.dataset.placeholder;
                  const { value } = el;
                  const len = placeholder.length;
                Severity: Minor
                Found in packages/usa-input-mask/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 enhanceComboBox has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                const enhanceComboBox = (_comboBoxEl) => {
                  const comboBoxEl = _comboBoxEl.closest(COMBO_BOX);
                
                  if (comboBoxEl.dataset.enhanced) return;
                
                
                Severity: Minor
                Found in packages/usa-combo-box/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 getDatePickerContext has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const getDatePickerContext = (el) => {
                  const datePickerEl = el.closest(DATE_PICKER);
                
                  if (!datePickerEl) {
                    throw new Error(`Element is missing outer ${DATE_PICKER}`);
                Severity: Minor
                Found in packages/usa-date-picker/src/index.js - About 1 hr to fix

                  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 validate has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    module.exports = function validate(el) {
                      const id = el.dataset.validationElement;
                      const checkList =
                        id.charAt(0) === "#"
                          ? document.querySelector(id)
                    Severity: Minor
                    Found in packages/uswds-core/src/js/utils/validate-input.js - About 1 hr to fix

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

                      const tabHandler = (focusable) => {
                        const getFocusableContext = (el) => {
                          const { calendarEl } = getDatePickerContext(el);
                          const focusableElements = select(focusable, calendarEl);
                      
                      
                      Severity: Minor
                      Found in packages/usa-date-picker/src/index.js - About 1 hr to fix

                        Function highlightOption has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                        const highlightOption = (el, nextEl, { skipFocus, preventScroll } = {}) => {
                          const { inputEl, listEl, focusedOptionEl } = getComboBoxContext(el);
                        
                          if (focusedOptionEl) {
                            focusedOptionEl.classList.remove(LIST_OPTION_FOCUSED_CLASS);
                        Severity: Minor
                        Found in packages/usa-combo-box/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 resetSelection has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                        Open

                        const resetSelection = (el) => {
                          const { comboBoxEl, selectEl, inputEl } = getComboBoxContext(el);
                        
                          const selectValue = selectEl.value;
                          const inputValue = (inputEl.value || "").toLowerCase();
                        Severity: Minor
                        Found in packages/usa-combo-box/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 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 displayYearSelection has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                        Open

                        const displayYearSelection = (el, yearToDisplay) => {
                          const { calendarEl, statusEl, calendarDate, minDate, maxDate } =
                            getDatePickerContext(el);
                        
                          const selectedYear = calendarDate.getFullYear();
                        Severity: Minor
                        Found in packages/usa-date-picker/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 buildFileObj has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function buildFileObj(dir, file, dataFile){
                            const templateFile = file
                            const dataFilePath = `${dir}/${dataFile}`
                            const name = !dataFile
                              ? `${file.substr(file.lastIndexOf('/') + 1).replace('.twig', '.html')}`
                          Severity: Minor
                          Found in webpack.twig.config.js - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language