lib/types/composite_type.js
Function wrapField
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
Open
function wrapField(field, value) {
if (value instanceof ForcedType) return value;
if (value === undefined || value === null) {
if (field.mandatory) throw new Error('missing mandatory field: ' + field.name);
if (field.hasOwnProperty('default')) return wrapField(field, field.default);
- 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 defineComposite
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
Open
function defineComposite(Base, definition) {
if (definition === undefined) {
definition = Base;
Base = Object;
}
- 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 defineComposite
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function defineComposite(Base, definition) {
if (definition === undefined) {
definition = Base;
Base = Object;
}
Function wrapField
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function wrapField(field, value) {
if (value instanceof ForcedType) return value;
if (value === undefined || value === null) {
if (field.mandatory) throw new Error('missing mandatory field: ' + field.name);
if (field.hasOwnProperty('default')) return wrapField(field, field.default);
Avoid too many return
statements within this function. Open
Open
return new ForcedType(field.type, value);
Avoid too many return
statements within this function. Open
Open
if (field.type === '*') return value;
Avoid too many return
statements within this function. Open
Open
return new field.requires(value);
Avoid too many return
statements within this function. Open
Open
if (value.toDescribedType && typeof value.toDescribedType === 'function') return value;
Avoid too many return
statements within this function. Open
Open
if (value.length === 0) return new ForcedType(field.type, null);
Avoid too many return
statements within this function. Open
Open
return new ForcedType(field.type, field.requires(value));
Avoid too many return
statements within this function. Open
Open
else if (value.length === 1) return new ForcedType(field.type, value[0]);
Avoid too many return
statements within this function. Open
Open
return new ForcedType('list', values);