18F/analytics.usa.gov

View on GitHub
js/lib/touchpoints.js

Summary

Maintainability
F
1 wk
Test Coverage

Function FBAform has 535 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function FBAform(d, N) {
  return {
    formId: "15ca967f",
    formComponent: function () {
      return document.querySelector("[data-touchpoints-form-id='" + this.formId + "']")
Severity: Major
Found in js/lib/touchpoints.js - About 2 days to fix

    Function FBAform has a Cognitive Complexity of 129 (exceeds 5 allowed). Consider refactoring.
    Open

    function FBAform(d, N) {
      return {
        formId: "15ca967f",
        formComponent: function () {
          return document.querySelector("[data-touchpoints-form-id='" + this.formId + "']")
    Severity: Minor
    Found in js/lib/touchpoints.js - About 2 days 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

    File touchpoints.js has 544 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /*
      This JS is included directly from the touchpoints app.  Included here to
      avoid writing unsafe content security policy allowances just for touchpoints.
      Minor changes were made to the original source to avoid inline styles.
    
    
    Severity: Major
    Found in js/lib/touchpoints.js - About 1 day to fix

      `` has 37 functions (exceeds 20 allowed). Consider refactoring.
      Open

        return {
          formId: "15ca967f",
          formComponent: function () {
            return document.querySelector("[data-touchpoints-form-id='" + this.formId + "']")
          },
      Severity: Minor
      Found in js/lib/touchpoints.js - About 4 hrs to fix

        Function pagination has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            pagination: function () {
              var previousButtons = document.getElementsByClassName("previous-section");
              var nextButtons = document.getElementsByClassName("next-section");
        
              var self = this;
        Severity: Minor
        Found in js/lib/touchpoints.js - About 1 hr to fix

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

              formSuccess: function (e) {
                // Clear the alert box
                var formComponent = this.formComponent();
                var alertElement = formComponent.querySelector(".fba-alert");
                var alertElementBody = formComponent.getElementsByClassName("usa-alert__text")[0];
          Severity: Minor
          Found in js/lib/touchpoints.js - About 1 hr to fix

            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 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

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      checkPhone: function (form) {
                        var phoneItems = form.querySelectorAll('input[type="tel"]');
                        var questions = {};
                        // Build a dictionary of questions which require an answer
                        Array.prototype.forEach.call(phoneItems, function (item) { questions[item.name] = item });
                  Severity: Major
                  Found in js/lib/touchpoints.js and 1 other location - About 1 day to fix
                  js/lib/touchpoints.js on lines 254..272

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 212.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      checkEmail: function (form) {
                        var emailItems = form.querySelectorAll('input[type="email"]');
                        var questions = {};
                        // Build a dictionary of questions which require an answer
                        Array.prototype.forEach.call(emailItems, function (item) { questions[item.name] = item });
                  Severity: Major
                  Found in js/lib/touchpoints.js and 1 other location - About 1 day to fix
                  js/lib/touchpoints.js on lines 273..291

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 212.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        textareas.forEach(function (textarea) {
                          if (textarea.getAttribute("maxlength") != '0' && textarea.getAttribute("maxlength") != '10000') {
                            textarea.addEventListener("keyup", self.textCounter);
                          }
                        });
                  Severity: Major
                  Found in js/lib/touchpoints.js and 1 other location - About 1 hr to fix
                  js/lib/touchpoints.js on lines 69..73

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 68.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        textFields.forEach(function (textField) {
                          if (textField.getAttribute("maxlength") != '0' && textField.getAttribute("maxlength") != '10000') {
                            textField.addEventListener("keyup", self.textCounter);
                          }
                        });
                  Severity: Major
                  Found in js/lib/touchpoints.js and 1 other location - About 1 hr to fix
                  js/lib/touchpoints.js on lines 62..66

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 68.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                            if (document.getElementsByClassName("fba-modal")[0]) {
                              document.getElementsByClassName("fba-modal")[0].scrollTo(0, 0);
                            } else {
                              window.scrollTo(0, 0);
                            }
                  Severity: Major
                  Found in js/lib/touchpoints.js and 1 other location - About 1 hr to fix
                  js/lib/touchpoints.js on lines 579..583

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 61.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                            if (document.getElementsByClassName("fba-modal")[0]) {
                              document.getElementsByClassName("fba-modal")[0].scrollTo(0, 0);
                            } else {
                              window.scrollTo(0, 0);
                            }
                  Severity: Major
                  Found in js/lib/touchpoints.js and 1 other location - About 1 hr to fix
                  js/lib/touchpoints.js on lines 603..607

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 61.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        for (var i = 0; i < phoneElements.length; i++) {
                          phoneElements[i].addEventListener('keyup', this.handlePhoneInput.bind(this), false);
                        }
                  Severity: Major
                  Found in js/lib/touchpoints.js and 1 other location - About 1 hr to fix
                  js/lib/touchpoints.js on lines 87..89

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 56.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        for (var i = 0; i < otherElements.length; i++) {
                          otherElements[i].addEventListener('keyup', this.handleOtherOption.bind(this), false);
                        }
                  Severity: Major
                  Found in js/lib/touchpoints.js and 1 other location - About 1 hr to fix
                  js/lib/touchpoints.js on lines 91..93

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 56.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                            Array.prototype.forEach.call(submitButtons, function (submitButton) {
                              submitButton.addEventListener('click', that.handleSubmitClick.bind(that), false);
                            })
                  Severity: Minor
                  Found in js/lib/touchpoints.js and 1 other location - About 45 mins to fix
                  js/lib/touchpoints.js on lines 106..108

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 50.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                          Array.prototype.forEach.call(submitButtons, function (submitButton) {
                            submitButton.addEventListener('click', that.handleYesNoSubmitClick.bind(that), false);
                          })
                  Severity: Minor
                  Found in js/lib/touchpoints.js and 1 other location - About 45 mins to fix
                  js/lib/touchpoints.js on lines 111..113

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 50.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                          if (formElement.querySelector('.touchpoints-form-body')) {
                            var formBody = formElement.querySelector('.touchpoints-form-body');
                            if (formBody) {
                              formBody.setAttribute("hidden", true);
                            }
                  Severity: Minor
                  Found in js/lib/touchpoints.js and 1 other location - About 40 mins to fix
                  js/lib/touchpoints.js on lines 427..432

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 49.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        if (instructions) {
                          if (this.currentPageNumber == 1) {
                            instructions.removeAttribute("hidden");
                          } else {
                            instructions.setAttribute("hidden", true);
                  Severity: Minor
                  Found in js/lib/touchpoints.js and 1 other location - About 40 mins to fix
                  js/lib/touchpoints.js on lines 550..556

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 49.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                          if (formComponent.querySelector('.touchpoints-form-disclaimer')) {
                            var formDisclaimer = formComponent.querySelector('.touchpoints-form-disclaimer');
                            if (formDisclaimer) {
                              formDisclaimer.setAttribute("hidden", true);
                            }
                  Severity: Minor
                  Found in js/lib/touchpoints.js and 1 other location - About 40 mins to fix
                  js/lib/touchpoints.js on lines 421..426

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 49.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                        if (requiredQuestionsNotice) {
                          if (this.currentPageNumber == 1) {
                            requiredQuestionsNotice.removeAttribute("hidden");
                          } else {
                            requiredQuestionsNotice.setAttribute("hidden", true);
                  Severity: Minor
                  Found in js/lib/touchpoints.js and 1 other location - About 40 mins to fix
                  js/lib/touchpoints.js on lines 541..547

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 49.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status