Showing 156 of 357 total issues
Avoid deeply nested control flow statements. Open
Open
if (secondJoin.criteria.where.and) {
baseChildTableQuery.criteria.where.and = baseChildTableQuery.criteria.where.and.concat(secondJoin.criteria.where.and);
}
else {
// Otherwise push the whole "where" clause in to the "and" array as a new conjunct.
Avoid deeply nested control flow statements. Open
Open
if (err) {
err = forgeAdapterError(err, omen, 'find', childTableModel.identity, orm);
return nextParentRecord(err);
}
Avoid deeply nested control flow statements. Open
Open
if (!OtherWLModel.attributes[attrDef.via]) {
throw new Error('Consistency violation: The referenced attribute (`'+attrName+'`, from model `'+modelIdentity+'`) is an association, because it declares a `collection`. But that association also specifies a `via` ('+attrDef.via+'`) which does not correspond with a recognized attribute on the other model (`'+attrDef.collection+'`)');
}
Function count
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
module.exports = function count( /* criteria?, explicitCbMaybe?, meta?, moreQueryKeys? */ ) {
// Verify `this` refers to an actual Sails/Waterline model.
verifyModelMethodContext(this);
- 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
Open
if (correspondingAttrDef.autoCreatedAt || correspondingAttrDef.autoUpdatedAt) {
// Ensure we are not trying to set it to empty string
// (this would never make sense.)
if (value === '') {
Avoid deeply nested control flow statements. Open
Open
if (!_.isString(correspondingAttrDef.type) || correspondingAttrDef.type === '') {
throw new Error('Consistency violation: There is no way this attribute (`'+supposedAttrName+'`) should have been allowed to be registered with neither a `type`, `model`, nor `collection`! Here is the attr def: '+util.inspect(correspondingAttrDef, {depth:5})+'');
}
Avoid deeply nested control flow statements. Open
Open
if (_.isUndefined(parentRecord[singleJoin.parentKey])) {
if (singleJoin.collection === true) {
parentRecord[alias] = [];
} else {
parentRecord[singleJoin.parentKey] = null;
Avoid deeply nested control flow statements. Open
Open
if (!_.isUndefined(singleJoin.criteria.select)) {
baseChildTableQuery.criteria.select = singleJoin.criteria.select;
}
Avoid deeply nested control flow statements. Open
Open
if (err) { return nextSetOfJoins(err); }
Avoid deeply nested control flow statements. Open
Open
if (isProvidingNullForIncompatibleOptionalAttr) {
throw flaverr({ code: 'E_TYPE', expectedType: correspondingAttrDef.type }, new Error(
'Specified value (`null`) is not a valid `'+supposedAttrName+'`. '+
'Even though this attribute is optional, it still does not allow `null` to '+
'be explicitly set, because `null` is not valid vs. the expected '+
Avoid deeply nested control flow statements. Open
Open
if (!_.isUndefined(singleJoin.criteria.sort)) {
baseChildTableQuery.criteria.sort = singleJoin.criteria.sort;
}
else {
baseChildTableQuery.criteria.sort = [];
Function stream
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
module.exports = function stream( /* criteria?, eachRecordFn?, explicitCbMaybe?, meta?, moreQueryKeys? */ ) {
// Verify `this` refers to an actual Sails/Waterline model.
verifyModelMethodContext(this);
- 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
Open
if (singleJoin.collection === true) {
parentRecord[alias] = childTableResults || [];
}
// Otherwise, if this is a to-one join, add the single result to the join key column
Avoid deeply nested control flow statements. Open
Open
if (correspondingAttrDef.required) {
// "" (empty string) is never allowed as a value for a required attribute.
if (value === '') {
throw flaverr('E_REQUIRED', new Error(
Avoid deeply nested control flow statements. Open
Open
if (_.keys(singleJoin.criteria.where).length > 0) {
// If the "where" clause has an "and" modifier already, just push it onto our "and".
if (singleJoin.criteria.where.and) {
baseChildTableQuery.criteria.where.and = baseChildTableQuery.criteria.where.and.concat(singleJoin.criteria.where.and);
} else {
Avoid deeply nested control flow statements. Open
Open
else if (modifierKind === '>') {
// If it matches a known attribute, verify that the attribute does not declare
// itself `type: 'boolean'` (it wouldn't make any sense to attempt that)
if (attrDef && attrDef.type === 'boolean'){
Avoid deeply nested control flow statements. Open
Open
if (!ThroughWLModel.attributes[attrDef.via]) {
throw new Error('Consistency violation: The referenced attribute (`'+attrName+'`, from model `'+modelIdentity+'`) is a "through" association, because it declares a `through`. But the association\'s specified `via` ('+attrDef.via+'`) does not correspond with a recognized attribute on the junction model (`'+attrDef.through+'`)');
}
Avoid deeply nested control flow statements. Open
Open
if (!_.isArray(modifier)) {
throw flaverr('E_CONSTRAINT_NOT_USABLE', new Error(
'A `nin` ("not in") modifier should always be provided as an array. '+
'But instead, for the `nin` modifier at `'+constraintTarget+'`, got: '+
util.inspect(modifier, {depth:5})+''
Avoid deeply nested control flow statements. Open
Open
if (!_.isUndefined(singleJoin.criteria.skip)) {
baseChildTableQuery.criteria.skip = singleJoin.criteria.skip;
} else {
baseChildTableQuery.criteria.skip = 0;
}
Avoid deeply nested control flow statements. Open
Open
if (!_.isUndefined(singleJoin.criteria.limit)) {
baseChildTableQuery.criteria.limit = singleJoin.criteria.limit;
} else {
baseChildTableQuery.criteria.limit = Number.MAX_SAFE_INTEGER||9007199254740991;
}