fogine/json-inspector

View on GitHub
lib/validator.js

Summary

Maintainability
F
3 days
Test Coverage

File validator.js has 408 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var _                    = require('lodash');
var queryString          = require('qs');
var stringValidator      = require('validator');
var ValidatorError       = require('./error/validatorError.js');
var ValidationError      = require('./error/validationError.js');
Severity: Minor
Found in lib/validator.js - About 5 hrs to fix

    Function build has 112 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Validator.prototype.build = function(data, where, options, parentDataObj, parentProp, parentTreeObj) {
    
        var self = this;
    
        var pool = [];
    Severity: Major
    Found in lib/validator.js - About 4 hrs to fix

      Function filterData has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

      Validator.prototype.filterData = function(data, filter, callback) {
      
          if (_.isPlainObject(data)) {
              var allowedKeys = Object.keys(filter);
              var dataKeys = Object.keys(data);
      Severity: Minor
      Found in lib/validator.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

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

      Validator.prototype.validate = function(data, customSchema, options) {
          var self = this;
          options = options || {};
      
          this.error = null; //TODO ?
      Severity: Minor
      Found in lib/validator.js - About 1 hr to fix

        Function filterData has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Validator.prototype.filterData = function(data, filter, callback) {
        
            if (_.isPlainObject(data)) {
                var allowedKeys = Object.keys(filter);
                var dataKeys = Object.keys(data);
        Severity: Minor
        Found in lib/validator.js - About 1 hr to fix

          Function buildArrayCondition has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          Validator.prototype.buildArrayCondition = function(prop, data, where, options, parentTreeObj) {
              var andCondPool = [];
              var keywordPrefix = options.keywordPrefix;
              var requiredKeyword = keywordPrefix + 'required';
              var messageKeyword = keywordPrefix + 'message';
          Severity: Minor
          Found in lib/validator.js - About 1 hr to fix

            Function Validator has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function Validator(schema, options, valManager) {
                var defaults = {
                    context              : {},
                    required             : false,
                    sanitizers           : [],
            Severity: Minor
            Found in lib/validator.js - About 1 hr to fix

              Function buildArrayCondition has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

              Validator.prototype.buildArrayCondition = function(prop, data, where, options, parentTreeObj) {
                  var andCondPool = [];
                  var keywordPrefix = options.keywordPrefix;
                  var requiredKeyword = keywordPrefix + 'required';
                  var messageKeyword = keywordPrefix + 'message';
              Severity: Minor
              Found in lib/validator.js - 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

                      } else if (_.isPlainObject(where[prefixedProp]) )  {
              
                          var required = where.hasOwnProperty(requiredKeyword) ? where[requiredKeyword] : options.required;
                          var nullable = where.hasOwnProperty(nullableKeyword) ? where[nullableKeyword] : options.nullable;
              
              
              Severity: Major
              Found in lib/validator.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            if (fun instanceof Function) {
                                pool.push(fun);
                            }
                Severity: Major
                Found in lib/validator.js - About 45 mins to fix

                  Function build has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  Validator.prototype.build = function(data, where, options, parentDataObj, parentProp, parentTreeObj) {
                  Severity: Minor
                  Found in lib/validator.js - About 45 mins to fix

                    Function addSanitizer has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    Validator.prototype.addSanitizer = function(sanitizerProp, where, parentDataObj, parentProp, options) {
                    Severity: Minor
                    Found in lib/validator.js - About 35 mins to fix

                      Function buildArrayCondition has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      Validator.prototype.buildArrayCondition = function(prop, data, where, options, parentTreeObj) {
                      Severity: Minor
                      Found in lib/validator.js - About 35 mins to fix

                        Function buildObjectCondition has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        Validator.prototype.buildObjectCondition = function(prop, data, where, options, parentTreeObj) {
                        Severity: Minor
                        Found in lib/validator.js - About 35 mins to fix

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

                          Validator.prototype.buildObjectCondition = function(prop, data, where, options, parentTreeObj) {
                              var path = options.propPath ? options.propPath + '.' + prop : prop;
                              var keywordPrefix = options.keywordPrefix;
                              var requiredKeyword = keywordPrefix + 'required';
                              var messageKeyword = keywordPrefix + 'message';
                          Severity: Minor
                          Found in lib/validator.js - 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

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

                          Validator.prototype.validate = function(data, customSchema, options) {
                              var self = this;
                              options = options || {};
                          
                              this.error = null; //TODO ?
                          Severity: Minor
                          Found in lib/validator.js - 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;
                          Severity: Major
                          Found in lib/validator.js - About 30 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status