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');
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 = [];
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);
- Read upRead up
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 ?
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);
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';
Function Validator
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function Validator(schema, options, valManager) {
var defaults = {
context : {},
required : false,
sanitizers : [],
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';
- Read upRead up
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;
Avoid deeply nested control flow statements. Open
if (fun instanceof Function) {
pool.push(fun);
}
Function build
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Validator.prototype.build = function(data, where, options, parentDataObj, parentProp, parentTreeObj) {
Function addSanitizer
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Validator.prototype.addSanitizer = function(sanitizerProp, where, parentDataObj, parentProp, options) {
Function buildArrayCondition
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Validator.prototype.buildArrayCondition = function(prop, data, where, options, parentTreeObj) {
Function buildObjectCondition
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Validator.prototype.buildObjectCondition = function(prop, data, where, options, parentTreeObj) {
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';
- Read upRead up
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 ?
- Read upRead up
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;