Showing 13 of 13 total issues
Function convertByDataType
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
function convertByDataType(datatype, input, fieldDef) {
if (datatype === String) {
const testMinMax = function testMinMax(inpValue) {
const minLength = fieldDef.minLength || inpValue.length;
const maxLength = fieldDef.maxLength || inpValue.length;
- 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 convertBySchemaDefinition
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
convertBySchemaDefinition(SchemaModel, inputObj, errors, method = TYPE_ANY) {
const targetObj = {};
const schemaInstance = new SchemaModel();
const restMethod = method.toLowerCase();
Function convertByDataType
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
function convertByDataType(datatype, input, fieldDef) {
if (datatype === String) {
const testMinMax = function testMinMax(inpValue) {
const minLength = fieldDef.minLength || inpValue.length;
const maxLength = fieldDef.maxLength || inpValue.length;
Function convertPrimitiveDataType
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
function convertPrimitiveDataType(options) {
// normal cases
/**
* Result:
* - { valid : false } when could not convert input value because of wrong datatype validating
- 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
Consider simplifying this complex logical expression. Open
else if (result === undefined &&
(
options.fieldDef.required
|| (options.fieldDef.requiredUpdate && TYPE_UPDATE_VALIDATOR.indexOf(options.restMethod) >= 0)
|| (options.fieldDef.requiredPut && options.restMethod === METHOD_PUT)
Consider simplifying this complex logical expression. Open
else if (
fieldDef.required
|| (fieldDef.requiredUpdate && TYPE_UPDATE_VALIDATOR.indexOf(restMethod) >= 0)
|| (fieldDef.requiredPut && restMethod === METHOD_PUT)
|| (fieldDef.requiredPatch && restMethod === METHOD_PATCH)
Function canMatchType
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function canMatchType(sourceField, type) {
return (
(type === TYPE_ANY) ||
(type === METHOD_FIND && sourceField.canFind !== false) ||
(type === METHOD_GET && sourceField.canGet !== false) ||
- 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
if (!fieldType) {
throw new Error(`Could not detect model type of ${fieldName}`);
}
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return ret;
Avoid too many return
statements within this function. Open
return undefined;
Avoid too many return
statements within this function. Open
return undefined;
Avoid too many return
statements within this function. Open
return (input === null || input === undefined) ? undefined : input;