Enterprise-CMCS/macpro-mako

View on GitHub
react-app/src/components/RHF/utils/validator.ts

Summary

Maintainability
D
2 days
Test Coverage
F
5%

Function slotValidator has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

  (data: any) =>
  (ACC: ERROR, SLOT: RHFSlotProps): ERROR => {
    const optionValidator = (OPT: RHFOption) => {
      if (OPT.form) OPT.form.reduce(formGroupValidator(data), ACC);
      if (OPT.slots) {
Severity: Minor
Found in react-app/src/components/RHF/utils/validator.ts - About 7 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 validateInput has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

export const validateInput = (inputValue: any, rules?: RegisterOptions) => {
  const isEmpty =
    isUndefined(inputValue) ||
    inputValue === "" ||
    (Array.isArray(inputValue) && !inputValue.length);
Severity: Minor
Found in react-app/src/components/RHF/utils/validator.ts - About 6 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

Consider simplifying this complex logical expression.
Open

  if (
    (rules?.maxLength || rules?.minLength) &&
    !isEmpty &&
    isString(inputValue)
  ) {
Severity: Major
Found in react-app/src/components/RHF/utils/validator.ts - About 40 mins to fix

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

    export const documentValidator = (document: FormSchema) => (data: any) => {
      return document.sections.reduce((ACC, SEC) => {
        if (SEC.dependency) {
          const depMatch = dependencyCheck(SEC.dependency, data);
          if (!depMatch) return ACC;
    Severity: Minor
    Found in react-app/src/components/RHF/utils/validator.ts - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid too many return statements within this function.
    Open

          return message;
    Severity: Major
    Found in react-app/src/components/RHF/utils/validator.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          if (exceedMin) return minLengthOutput.message;
      Severity: Major
      Found in react-app/src/components/RHF/utils/validator.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

          return "";
        Severity: Major
        Found in react-app/src/components/RHF/utils/validator.ts - About 30 mins to fix

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

          export const dependencyCheck = (dep: DependencyRule, data: any) => {
            const conditionMatched = dep.conditions.every((DC) => {
              if (DC.type === "valueNotExist") return !data[DC.name];
              if (DC.type === "expectedValue") {
                return data[DC.name] === DC.expectedValue;
          Severity: Minor
          Found in react-app/src/components/RHF/utils/validator.ts - 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

          There are no issues that match your filters.

          Category
          Status