src/compilers/route.js
Function compileRoute
has a Cognitive Complexity of 115 (exceeds 5 allowed). Consider refactoring. Open
Open
export default function compileRoute(fn, params) {
const content = babelCompilerManipulationNormalize(fn.toString().trim());
const preparedParams = convertParams(params);
// Don't parse dummy functions
- 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 compileRoute
has 183 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
export default function compileRoute(fn, params) {
const content = babelCompilerManipulationNormalize(fn.toString().trim());
const preparedParams = convertParams(params);
// Don't parse dummy functions
Function babelCompilerManipulationNormalize
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
const babelCompilerManipulationNormalize = (content) => {
if (content.includes('const {\n') || content.includes('let {\n')) {
return content.split('\n').reduce((all, currLine, index) => {
if (currLine.includes('{') && index > 0) {
all += '\n';
- 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
} else if (line.includes('setHeader')) {
contentLines += line.replace('setHeader', 'writeHeader');
} else if (line.includes('status(')) {
const statusPrepare = line.substr(line.indexOf('status(') + 7);
const code = parseInt(
Avoid deeply nested control flow statements. Open
Open
if (line.charAt(headerKeyIndex + 11) === '.') {
contentLines += line.replace(
`req.headers.${headerKey}`,
`req.getHeader('${headerKey}')`
);
Avoid deeply nested control flow statements. Open
Open
if (paramKeyIndex !== -1) {
const paramKey = line
.substr(paramKeyIndex + 11)
.replace(HEADER_PARAM_KEY_REGEX, '');
const paramIndex = preparedParams[paramKey];
Avoid too many return
statements within this function. Open
Open
return null;
Avoid too many return
statements within this function. Open
Open
return compiled;
Avoid too many return
statements within this function. Open
Open
return null;