Ryzii74/scheme-validator

View on GitHub
index.js

Summary

Maintainability
C
1 day
Test Coverage

Function check has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

function check(field, data, key) {
    if (!field) return;

    if (!Required(field, data, key)) return error(key, 'Field is required!');
    if (field.structure) {
Severity: Minor
Found in index.js - About 4 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

Avoid too many return statements within this function.
Open

        if (result && !result.success) return error(key + '.' + i, result.error.text);
Severity: Major
Found in index.js - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

        if (!Value(field, data, key)) return error(key, 'Value is not equal!');
    Severity: Major
    Found in index.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  if (!result.success) return error(key + '.' + result.error.key, result.error.text);
      Severity: Major
      Found in index.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            if (!CustomValidator(field, data, key)) return error(key, 'Validator detected wrong data!');
        Severity: Major
        Found in index.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              if (field.enum && field.enum.constructor && field.enum.constructor !== Array) return error(key, 'Wrong data for enum!');
          Severity: Major
          Found in index.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                if (field.validator && typeof field.validator !== "function") return error(key, 'Wrong data for validator!');
            Severity: Major
            Found in index.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  if (!Enum(field, data, key)) return error(key, 'Value is not part of enum!');
              Severity: Major
              Found in index.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    if (!Type(field, data, key)) return error(key, 'Wrong type of field!');
                Severity: Major
                Found in index.js - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status