ditto/mappers/map.js
Function map
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
Open
async function map(document, mappings, plugins) {
/**
* @function processMappings
*
- 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 map
has 123 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async function map(document, mappings, plugins) {
/**
* @function processMappings
*
Function processMappings
has 118 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function processMappings(mappings, document, result, parentKey) {
_.each(mappings, function(path, key) {
key = parentKey ? `${parentKey}.${key}` : key;
Function getValue
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function getValue(path, subDocument) {
if (!path) return;
if (path === '!') return document;
Function parseMappings
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
function parseMappings(result, innerResult, path, key, $value, $key) {
Avoid deeply nested control flow statements. Open
Open
if (!!path.prerequisite) {
if (!!eval(path.prerequisite)) _.set(result, fullPath, innerResult);
} else _.set(result, fullPath, innerResult);
Avoid deeply nested control flow statements. Open
Open
if (!!path.prerequisite) {
if (!!eval(path.prerequisite)) _.updateWith(result, key, function(theArray){ theArray.push(innerResult); return theArray }, []);
} else _.updateWith(result, key, function(theArray){ theArray.push(innerResult); return theArray }, []);
Avoid too many return
statements within this function. Open
Open
return _.isPlainObject(subDocument) ? _.get(subDocument, path) : _.get(document, path);
Avoid too many return
statements within this function. Open
Open
return plugins[functionCall].apply(null, paramteresValues);
Avoid too many return
statements within this function. Open
Open
} else return getValue(path, $value);
Avoid too many return
statements within this function. Open
Open
return isValidValue ? applyTransformation(null, parameters.targetValue, null, subDocument) : null;
Avoid too many return
statements within this function. Open
Open
return getValue(pathWithDefault[0], subDocument) || getValue(`${pathWithDefault[1]}`);