CollageLabs/collagelabs.org

View on GitHub

Showing 46 of 46 total issues

Function handler has 244 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.handler = async (event) => {
  let serverErrorMessage;
  const headers = {
    'Content-Type': 'application/json',
  };
Severity: Major
Found in lambda/frontpage-contact-form.js - About 1 day to fix

    File frontpage-contact-form.js has 510 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const { google } = require('googleapis');
    const querystring = require('querystring');
    const axios = require('axios');
    var crypto = require('crypto');
    
    
    Severity: Major
    Found in lambda/frontpage-contact-form.js - About 1 day to fix

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

        if (field.type === 'radio' && field.name) {
          var group = field.form.querySelectorAll('[name="' + field.name + '"]');
          if (group.length > 0) {
            for (var i = 0; i < group.length; i++) {
              group[i].classList.remove('error');
      Severity: Major
      Found in _src/lib/form-functions.js and 1 other location - About 5 hrs to fix
      _src/lib/form-functions.js on lines 68..76

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

      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 (field.type === 'radio' && field.name) {
          var group = field.form.querySelectorAll('[name="' + field.name + '"]');
          if (group.length > 0) {
            for (var i = 0; i < group.length; i++) {
              group[i].classList.add('error');
      Severity: Major
      Found in _src/lib/form-functions.js and 1 other location - About 5 hrs to fix
      _src/lib/form-functions.js on lines 157..165

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

      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

      Consider simplifying this complex logical expression.
      Open

        if (!(SENDGRID_API_KEY && SENDGRID_WELCOME_SENDER_EMAIL &&
              SENDGRID_WELCOME_SENDER_NAME && SENDGRID_WELCOME_TEMPLATE_ID &&
              SENDGRID_COMPANY_LIST_EMAIL && SENDGRID_COMPANY_SENDER_EMAIL &&
              SENDGRID_COMPANY_SENDER_NAME && SENDGRID_COMPANY_TEMPLATE_ID &&
              SENDGRID_API_BASE_URL && SENDGRID_LIST_ID && MAILCHIMP_API_KEY &&
      Severity: Critical
      Found in lambda/frontpage-contact-form.js - About 4 hrs to fix

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

          if (!isUserOnSendgridList) {
            await addUserSendgrid(
              SENDGRID_API_BASE_URL,
              SENDGRID_API_KEY,
              SENDGRID_LIST_ID,
        Severity: Major
        Found in lambda/frontpage-contact-form.js and 1 other location - About 3 hrs to fix
        lambda/frontpage-contact-form.js on lines 437..457

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

        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 (!isUserOnMailchimpList) {
            await addUserMailchimp(
              MAILCHIMP_API_BASE_URL,
              MAILCHIMP_API_KEY,
              MAILCHIMP_LIST_ID,
        Severity: Major
        Found in lambda/frontpage-contact-form.js and 1 other location - About 3 hrs to fix
        lambda/frontpage-contact-form.js on lines 415..435

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

        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

          const isUserOnSendgridList = await checkUserOnSendgridList(
            SENDGRID_API_BASE_URL,
            SENDGRID_API_KEY,
            SENDGRID_LIST_ID,
            CONTACT_EMAIL).catch((error) => {
        Severity: Major
        Found in lambda/frontpage-contact-form.js and 1 other location - About 3 hrs to fix
        lambda/frontpage-contact-form.js on lines 396..413

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

        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

          const isUserOnMailchimpList = await checkUserOnMailchimpList(
            MAILCHIMP_API_BASE_URL,
            MAILCHIMP_API_KEY,
            MAILCHIMP_LIST_ID,
            CONTACT_EMAIL).catch((error) => {
        Severity: Major
        Found in lambda/frontpage-contact-form.js and 1 other location - About 3 hrs to fix
        lambda/frontpage-contact-form.js on lines 377..394

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

        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

          await addSpreadsheetRow(
            GOOGLE_CLIENT_EMAIL,
            GOOGLE_PRIVATE_KEY,
            GOOGLE_SPREADSHEET_ID,
            GOOGLE_SPREADSHEET_NAME,
        Severity: Major
        Found in lambda/frontpage-contact-form.js and 1 other location - About 3 hrs to fix
        lambda/frontpage-contact-form.js on lines 460..480

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

        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

            await sendWelcomeEmail(
              SENDGRID_API_BASE_URL,
              SENDGRID_API_KEY,
              CONTACT_EMAIL,
              CONTACT_NAME,
        Severity: Major
        Found in lambda/frontpage-contact-form.js and 1 other location - About 3 hrs to fix
        lambda/frontpage-contact-form.js on lines 507..527

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

        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

        Function hasErrorContactForm has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        window.hasErrorContactForm = function (field) {
        
          // Don't validate submits, buttons, file and reset inputs, and disabled fields
          if (field.disabled || field.type === 'file' || field.type === 'reset' || field.type === 'submit' || field.type === 'button') return;
        
        
        Severity: Minor
        Found in _src/lib/form-functions.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 showErrorContactForm has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        window.showErrorContactForm = function (field, error) {
        
          // Add error class to field
          field.classList.add('error');
          
        Severity: Minor
        Found in _src/lib/form-functions.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 sendCompanyEmail has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        async function sendCompanyEmail(apiUrl, apiKey, toEmail, replyToEmail, replyToName,
                                        senderEmail, senderName, senderMessage,
                                        templateId) {
          try {
            console.log(`[sendCompanyEmail] Sending message from ${senderEmail} to company list`);
        Severity: Minor
        Found in lambda/frontpage-contact-form.js - About 1 hr to fix

          Function sendWelcomeEmail has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          async function sendWelcomeEmail(apiUrl, apiKey, toEmail, toName,
                                          senderEmail, senderName, templateId) {
            try {
              console.log(`[sendWelcomeEmail] Sending welcome email to user ${toEmail}`);
              const data = {
          Severity: Minor
          Found in lambda/frontpage-contact-form.js - About 1 hr to fix

            Function getValidityState has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              var getValidityState = function (field) {
            
                // Variables
                var type = field.getAttribute('type') || field.nodeName.toLowerCase();
                var isNum = type === 'number' || type === 'range';
            Severity: Minor
            Found in _src/lib/validity-polyfill.js - About 1 hr to fix

              Function submitContactForm has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              window.submitContactForm = function (form) {
              
                // Get the Submit URL
                var url = form.getAttribute('action');
                var email = document.getElementById('contact-email').value;
              Severity: Minor
              Found in _src/lib/form-functions.js - About 1 hr to fix

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

                    const response = await axios({
                      method: 'POST',
                      url: `${apiUrl}/v3/mail/send`,
                      headers: {
                        'Content-Type': 'application/json',
                Severity: Major
                Found in lambda/frontpage-contact-form.js and 3 other locations - About 1 hr to fix
                lambda/frontpage-contact-form.js on lines 15..23
                lambda/frontpage-contact-form.js on lines 73..81
                lambda/frontpage-contact-form.js on lines 197..205

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

                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 4 locations. Consider refactoring.
                Open

                    const response = await axios({
                      method: 'POST',
                      url: `${apiUrl}/v3/marketing/contacts/search`,
                      headers: {
                        'Content-Type': 'application/json',
                Severity: Major
                Found in lambda/frontpage-contact-form.js and 3 other locations - About 1 hr to fix
                lambda/frontpage-contact-form.js on lines 73..81
                lambda/frontpage-contact-form.js on lines 146..154
                lambda/frontpage-contact-form.js on lines 197..205

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

                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 4 locations. Consider refactoring.
                Open

                    const response = await axios({
                      method: 'POST',
                      url: `${apiUrl}/v3/mail/send`,
                      headers: {
                        'Content-Type': 'application/json',
                Severity: Major
                Found in lambda/frontpage-contact-form.js and 3 other locations - About 1 hr to fix
                lambda/frontpage-contact-form.js on lines 15..23
                lambda/frontpage-contact-form.js on lines 73..81
                lambda/frontpage-contact-form.js on lines 146..154

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

                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

                Severity
                Category
                Status
                Source
                Language