18F/web-design-standards

View on GitHub

Showing 67 of 368 total issues

Function compileJS has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  compileJS() {
    dutil.logMessage("javascript", "Compiling JavaScript");
    let packageName = dutil.pkg.name.replace("@uswds/", "");
    const streams = Object.entries({
      [packageName]: browserify({
Severity: Minor
Found in tasks/javascript.js - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

        } else if (
          (!isCharsetPresent && !isInt && matchesNumber) ||
          (isCharsetPresent &&
            ((matchesLetter && !isLet) || (matchesNumber && !isInt)))
        ) {
    Severity: Critical
    Found in packages/usa-input-mask/src/index.js - About 1 hr to fix

      Function handleCurrentValue has 33 lines of code (exceeds 25 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

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

        module.exports = (context, additionalKeyBindings = {}) => {
          const tabEventHandler = tabHandler(context);
          const bindings = additionalKeyBindings;
          const { Esc, Escape } = bindings;
        
        
        Severity: Minor
        Found in packages/uswds-core/src/js/utils/focus-trap.js - About 1 hr to fix

          Function toggleHtmlTag has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function toggleHtmlTag(isMobile) {
            const bigFooter = document.querySelector(SCOPE);
          
            if (!bigFooter) {
              return;
          Severity: Minor
          Found in packages/usa-footer/src/index.js - About 1 hr to fix

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

            const setUpAttributes = (tooltipTrigger) => {
              const tooltipID = `tooltip-${Math.floor(Math.random() * 900000) + 100000}`;
              const tooltipContent = tooltipTrigger.getAttribute("title");
              const wrapper = document.createElement("span");
              const tooltipBody = document.createElement("span");
            Severity: Minor
            Found in packages/usa-tooltip/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

                Function months has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  const months = MONTH_LABELS.map((month, index) => {
                    const monthToCheck = setMonth(calendarDate, index);
                
                    const isDisabled = isDatesMonthOutsideMinOrMax(
                      monthToCheck,
                Severity: Minor
                Found in packages/usa-date-picker/src/index.js - About 1 hr to fix

                  Function embed has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    function embed(parent, svg, target, use) {
                      // if the target exists
                      if (target) {
                        // create a document fragment to hold the contents of the target
                        var fragment = document.createDocumentFragment(),
                  Severity: Minor
                  Found in packages/uswds-core/src/js/polyfills/svg4everybody.js - About 1 hr to fix

                    Function getComboBoxContext has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const getComboBoxContext = (el) => {
                      const comboBoxEl = el.closest(COMBO_BOX);
                    
                      if (!comboBoxEl) {
                        throw new Error(`Element is missing outer ${COMBO_BOX}`);
                    Severity: Minor
                    Found in packages/usa-combo-box/src/index.js - About 1 hr to fix

                      Function enhanceDateRangePicker has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      const enhanceDateRangePicker = (el) => {
                        const dateRangePickerEl = el.closest(DATE_RANGE_PICKER);
                      
                        const [rangeStart, rangeEnd] = select(DATE_PICKER, dateRangePickerEl);
                      
                      
                      Severity: Minor
                      Found in packages/usa-date-range-picker/src/index.js - About 1 hr to fix

                        Function compileSass has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          compileSass() {
                            dutil.logMessage("sass", "Compiling Sass");
                            const pluginsProcess = [discardComments(), autoprefixer()];
                            const pluginsMinify = [csso({ forceMediaMerge: false })];
                        
                        
                        Severity: Minor
                        Found in tasks/sass.js - About 1 hr to fix

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

                          const isDateInputInvalid = (el) => {
                            const { externalInputEl, minDate, maxDate } = getDatePickerContext(el);
                          
                            const dateString = externalInputEl.value;
                            let isInvalid = false;
                          Severity: Minor
                          Found in packages/usa-date-picker/src/index.js - About 1 hr to fix

                            Function displayMonthSelection has a Cognitive Complexity of 9 (exceeds 5 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 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 enhanceDatePicker has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                            const enhanceDatePicker = (el) => {
                              const datePickerEl = el.closest(DATE_PICKER);
                              const { defaultValue } = datePickerEl.dataset;
                            
                              const internalInputEl = datePickerEl.querySelector(`input`);
                            Severity: Minor
                            Found in packages/usa-date-picker/src/index.js - About 45 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 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

                              Avoid deeply nested control flow statements.
                              Open

                                            if (url.length) {
                                              // get the cached xhr request
                                              var xhr = requests[url];
                                              // ensure the xhr request exists
                                              xhr ||
                              Severity: Major
                              Found in packages/uswds-core/src/js/polyfills/svg4everybody.js - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                          if (yearStr.length < 3) {
                                            const currentYear = today().getFullYear();
                                            const currentYearStub =
                                              currentYear - (currentYear % 10 ** yearStr.length);
                                            year = currentYearStub + parsed;
                                Severity: Major
                                Found in packages/usa-date-picker/src/index.js - About 45 mins to fix

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

                                  const compareFunction = (index, isAscending) => (thisRow, nextRow) => {
                                    // get values to compare from data attribute or cell content
                                    const value1 = getCellValue(isAscending ? thisRow : nextRow, index);
                                    const value2 = getCellValue(isAscending ? nextRow : thisRow, index);
                                  
                                  
                                  Severity: Minor
                                  Found in packages/usa-table/src/index.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

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

                                  module.exports = (context, additionalKeyBindings = {}) => {
                                    const tabEventHandler = tabHandler(context);
                                    const bindings = additionalKeyBindings;
                                    const { Esc, Escape } = bindings;
                                  
                                  
                                  Severity: Minor
                                  Found in packages/uswds-core/src/js/utils/focus-trap.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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language