widgets/client/utils.ts

Summary

Maintainability
F
6 days
Test Coverage

Function checkLogicFulfilled has a Cognitive Complexity of 122 (exceeds 5 allowed). Consider refactoring.
Open

export const checkLogicFulfilled = (logics: LogicParams[]) => {
  const values: { [key: string]: boolean } = {};
  
  for (const logic of logics) {
    const { fieldId, operator, logicValue, fieldValue, validation, type } = logic;
Severity: Minor
Found in widgets/client/utils.ts - 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

Function checkLogicFulfilled has 128 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const checkLogicFulfilled = (logics: LogicParams[]) => {
  const values: { [key: string]: boolean } = {};
  
  for (const logic of logics) {
    const { fieldId, operator, logicValue, fieldValue, validation, type } = logic;
Severity: Major
Found in widgets/client/utils.ts - About 5 hrs to fix

    File utils.ts has 360 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import * as dayjs from 'dayjs';
    import e = require('express');
    import T from 'i18n-react';
    import { FieldValue } from './form/types';
    import { ENV, IBrowserInfo, IRule } from './types';
    Severity: Minor
    Found in widgets/client/utils.ts - About 4 hrs to fix

      Function checkRule has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const checkRule = async (rule: IRule, browserInfo: IBrowserInfo) => {
        const { language, url, city, country } = browserInfo || ({} as IBrowserInfo);
        const { value, kind, condition } = rule;
        const ruleValue: any = value;
      
      
      Severity: Major
      Found in widgets/client/utils.ts - About 2 hrs to fix

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

        export const checkRule = async (rule: IRule, browserInfo: IBrowserInfo) => {
          const { language, url, city, country } = browserInfo || ({} as IBrowserInfo);
          const { value, kind, condition } = rule;
          const ruleValue: any = value;
        
        
        Severity: Minor
        Found in widgets/client/utils.ts - 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

        Avoid deeply nested control flow statements.
        Open

                  if (fieldValue.includes(logicValue)) {
                    values[key] = true;
                  } else {
                    values[key] = false;
                  }
        Severity: Major
        Found in widgets/client/utils.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    if (!fieldValue.includes(logicValue)) {
                      values[key] = true;
                    } else {
                      values[key] = false;
                    }
          Severity: Major
          Found in widgets/client/utils.ts - About 45 mins to fix

            Avoid too many return statements within this function.
            Open

                return false;
            Severity: Major
            Found in widgets/client/utils.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return false;
              Severity: Major
              Found in widgets/client/utils.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return false;
                Severity: Major
                Found in widgets/client/utils.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return false;
                  Severity: Major
                  Found in widgets/client/utils.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return false;
                    Severity: Major
                    Found in widgets/client/utils.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                        return true;
                      Severity: Major
                      Found in widgets/client/utils.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return false;
                        Severity: Major
                        Found in widgets/client/utils.ts - About 30 mins to fix

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

                          export const postMessage = (source: string, message: string, postData = {}) => {
                            window.parent.postMessage(
                              {
                                fromErxes: true,
                                source,
                          Severity: Major
                          Found in widgets/client/utils.ts and 1 other location - About 1 hr to fix
                          widgets/client/widgetUtils.ts on lines 105..115

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

                          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

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

                            return text.replace(urlRegex, (url) => {
                              if (url.startsWith('http')) {
                                return `<a href="${url}" target="_blank">${url}</a>`;
                              }
                          
                          
                          Severity: Major
                          Found in widgets/client/utils.ts and 1 other location - About 1 hr to fix
                          ui/src/modules/inbox/utils.ts on lines 79..85

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

                          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 (operator === 'startsWith') {
                                  if (String(fieldValue).startsWith(logicValue)) {
                                    values[key] = true;
                                  } else {
                                    values[key] = false;
                          Severity: Major
                          Found in widgets/client/utils.ts and 1 other location - About 1 hr to fix
                          widgets/client/utils.ts on lines 349..355

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

                          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 (operator === 'contains') {
                                  if (String(fieldValue).includes(logicValue)) {
                                    values[key] = true;
                                  } else {
                                    values[key] = false;
                          Severity: Major
                          Found in widgets/client/utils.ts and 1 other location - About 1 hr to fix
                          widgets/client/utils.ts on lines 367..373

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

                          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 (operator === 'is') {
                                if (logicValue === fieldValue) {
                                  values[key] = true;
                                } else {
                                  values[key] = false;
                          Severity: Minor
                          Found in widgets/client/utils.ts and 1 other location - About 50 mins to fix
                          widgets/client/utils.ts on lines 391..397

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

                          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 (operator === 'dateGreaterThan') {
                                  if (dateValueToCheck > logicDateValue) {
                                    values[key] = true;
                                  } else {
                                    values[key] = false;
                          Severity: Minor
                          Found in widgets/client/utils.ts and 1 other location - About 50 mins to fix
                          widgets/client/utils.ts on lines 310..316

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

                          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 (operator === 'doesNotContain') {
                                  if (!String(fieldValue).includes(logicValue)) {
                                    values[key] = true;
                                  } else {
                                    values[key] = false;
                          Severity: Minor
                          Found in widgets/client/utils.ts and 1 other location - About 50 mins to fix
                          widgets/client/utils.ts on lines 376..382

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

                          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 (operator === 'endsWith') {
                                  if (!String(fieldValue).endsWith(logicValue)) {
                                    values[key] = true;
                                  } else {
                                    values[key] = false;
                          Severity: Minor
                          Found in widgets/client/utils.ts and 1 other location - About 50 mins to fix
                          widgets/client/utils.ts on lines 358..364

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

                          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 (operator === 'dateLessThan') {
                                  if (logicDateValue > dateValueToCheck) {
                                    values[key] = true;
                                  } else {
                                    values[key] = false;
                          Severity: Minor
                          Found in widgets/client/utils.ts and 1 other location - About 45 mins to fix
                          widgets/client/utils.ts on lines 319..325

                          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 (operator === 'isNot') {
                                if (logicValue !== fieldValue) {
                                  values[key] = true;
                                } else {
                                  values[key] = false;
                          Severity: Minor
                          Found in widgets/client/utils.ts and 1 other location - About 45 mins to fix
                          widgets/client/utils.ts on lines 400..406

                          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 (operator === 'lessThan' && fieldValue) {
                                  if (Number(fieldValue) < Number(logicValue)) {
                                    values[key] = true;
                                  } else {
                                    values[key] = false;
                          Severity: Minor
                          Found in widgets/client/utils.ts and 1 other location - About 40 mins to fix
                          widgets/client/utils.ts on lines 329..335

                          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 (operator === 'greaterThan' && fieldValue) {
                                  if (Number(fieldValue) > Number(logicValue)) {
                                    values[key] = true;
                                  } else {
                                    values[key] = false;
                          Severity: Minor
                          Found in widgets/client/utils.ts and 1 other location - About 40 mins to fix
                          widgets/client/utils.ts on lines 338..344

                          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