nanoexpress/nanoexpress

View on GitHub
src/compilers/route.js

Summary

Maintainability
F
3 days
Test Coverage

Function compileRoute has a Cognitive Complexity of 115 (exceeds 5 allowed). Consider refactoring.
Open

export default function compileRoute(fn, params) {
  const content = babelCompilerManipulationNormalize(fn.toString().trim());
  const preparedParams = convertParams(params);

  // Don't parse dummy functions
Severity: Minor
Found in src/compilers/route.js - About 2 days to fix

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

export default function compileRoute(fn, params) {
  const content = babelCompilerManipulationNormalize(fn.toString().trim());
  const preparedParams = convertParams(params);

  // Don't parse dummy functions
Severity: Major
Found in src/compilers/route.js - About 7 hrs to fix

    Function babelCompilerManipulationNormalize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    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';
    Severity: Minor
    Found in src/compilers/route.js - About 1 hr to fix

    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

          } 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(
    Severity: Major
    Found in src/compilers/route.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                if (line.charAt(headerKeyIndex + 11) === '.') {
                  contentLines += line.replace(
                    `req.headers.${headerKey}`,
                    `req.getHeader('${headerKey}')`
                  );
      Severity: Major
      Found in src/compilers/route.js - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                if (paramKeyIndex !== -1) {
                  const paramKey = line
                    .substr(paramKeyIndex + 11)
                    .replace(HEADER_PARAM_KEY_REGEX, '');
                  const paramIndex = preparedParams[paramKey];
        Severity: Major
        Found in src/compilers/route.js - About 45 mins to fix

          Avoid too many return statements within this function.
          Open

                      return null;
          Severity: Major
          Found in src/compilers/route.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              return compiled;
            Severity: Major
            Found in src/compilers/route.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return null;
              Severity: Major
              Found in src/compilers/route.js - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status