Ryzii74/scheme-validator

View on GitHub

Showing 10 of 10 total issues

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 (!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 (!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 (!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 (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 (!Type(field, data, key)) return error(key, 'Wrong type of field!');
          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 (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

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

                  module.exports = function (field, data, key) {
                      if (!data.hasOwnProperty(key)) return true;
                  
                      if (field.array) {
                          return data[key].constructor && data[key].constructor === Array;
                  Severity: Minor
                  Found in lib/type.js - 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

                  Severity
                  Category
                  Status
                  Source
                  Language