18F/analytics.usa.gov

View on GitHub

Showing 25 of 104 total issues

Function loadHtml has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    loadHtml: function () {

      this.dialogEl = document.createElement('div');
      this.dialogEl.setAttribute("hidden", true);
      this.dialogEl.setAttribute('class', 'fba-modal');
Severity: Minor
Found in js/lib/touchpoints.js - About 1 hr to fix

    Function block has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      const block = function (selection) {
        selection
          .each(load)
          .filter(function (d) {
            d.refresh = +this.getAttribute("data-refresh");
    Severity: Minor
    Found in js/lib/renderblock.js - About 1 hr to fix

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

          showValidationError: function (question, error) {
            var questionDiv = question.closest(".question");
            var label = questionDiv.querySelector(".usa-label") || questionDiv.querySelector(".usa-legend");
            var questionNum = label.innerText;
      
      
      Severity: Minor
      Found in js/lib/touchpoints.js - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                    if (errors.hasOwnProperty(err)) {
                      alertErrorElementBody.innerHTML += err;
                      alertErrorElementBody.innerHTML += " ";
                      alertErrorElementBody.innerHTML += errors[err];
                      alertErrorElementBody.innerHTML += "<br />";
        Severity: Major
        Found in js/lib/touchpoints.js - About 45 mins to fix

          Function openDefinitionAccordionForAnchor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          function openDefinitionAccordionForAnchor() {
            // Both /definitions and /definitions/ are required here because locally the
            // trailing slash is present for all links for some reason.
            if (
              (window.location.pathname != "/definitions" &&
          Severity: Minor
          Found in js/index.js - About 25 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