nanoexpress/nanoexpress

View on GitHub

Showing 49 of 55 total issues

Function send has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function send(result) {
  if (!result) {
    result = '';
  } else if (typeof result === 'object') {
    this.setHeader('Content-Type', 'application/json; charset=utf-8');
Severity: Minor
Found in src/response-proto/http/response-chunks/send.js - About 1 hr to fix

    Function onListenHandler has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          const onListenHandler = (token) => {
            if (typeof host === 'string') {
              config.host = host;
            } else {
              config.host = 'localhost';
    Severity: Minor
    Found in src/App.js - About 1 hr to fix

      Function upgrade has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async upgrade(res, req, context) {
            const secWsKey = req.getHeader('sec-websocket-key');
            const secWsProtocol = req.getHeader('sec-websocket-protocol');
            const secWsExtensions = req.getHeader('sec-websocket-extensions');
      
      
      Severity: Minor
      Found in src/Route.js - About 1 hr 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

        Function listen has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          listen(port, host) {
            const {
              _config: config,
              _app: app,
              _routeCalled,
        Severity: Minor
        Found in src/App.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

        Function modifyEnd has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export default function modifyEnd() {
          if (!this._modifiedEnd) {
            const _oldEnd = this.end;
        
            this.end = function modifiedEnd(chunk, encoding) {
        Severity: Minor
        Found in src/response-proto/http/response-chunks/modify-end.js - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                        if (
                          req.headers &&
                          ((!isRaw && bodyAllowedMethod && res.onData) ||
                            req.headers['transfer-encoding'] ||
                            (req.headers['content-length'] &&
          Severity: Major
          Found in src/Route.js - About 1 hr to fix

            Function exposeAppMethodHOC has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            const exposeAppMethodHOC = (method) =>
              function exposeAppMethod(path, ...fns) {
                const { _app, _route, _anyRouteCalled } = this;
            
                if (fns.length > 0) {
            Severity: Minor
            Found in src/App.js - About 55 mins 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

                      if (!value.schema) {
                        schema[typeName][httpCode].content[contentType] = { schema: value };
                      }
            Severity: Major
            Found in src/helpers/prepare-swagger-docs.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        if (_errors[type]) {
                          _errors[type].push(...validator.errors.map((err) => err.message));
                        } else {
                          _errors[type] = validator.errors.map((err) => err.message);
                        }
              Severity: Major
              Found in src/helpers/process-validation.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          if (value.description && !parent.description) {
                            parent.description = value.description;
                          }
                Severity: Major
                Found in src/helpers/prepare-swagger-docs.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                            if (!errors) {
                              errors = {
                                type: 'errors',
                                errors: { [type]: [`${type} is not missing`] }
                              };
                  Severity: Major
                  Found in src/helpers/process-validation.js - About 45 mins to fix

                    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 (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 deeply nested control flow statements.
                        Open

                                    if (middleware._middlewares !== _middlewares) {
                                      middleware._middlewares = _middlewares
                                        .concat(middleware._middlewares)
                                        .filter(
                                          (currentMiddleware, index, self) =>
                        Severity: Major
                        Found in src/Route.js - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                    if (code === _statusCode) {
                                      result = fastJsonFunc(result);
                                    } else if (code.indexOf('X') !== -1) {
                                      for (let i = 0; i < 3; i += 1) {
                                        if (code.charAt(i) === 'X') {
                          Severity: Major
                          Found in src/response-proto/http/response-chunks/send.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 (!valid) {
                                              ws.emit(
                                                'message',
                                                {
                                                  type: 'websocket.message',
                              Severity: Major
                              Found in src/Route.js - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                          if (!value.content) {
                                            schema[typeName][httpCode] = { content: { [contentType]: value } };
                                            parent = schema[typeName][httpCode];
                                            value = parent.content[contentType];
                                          }
                                Severity: Major
                                Found in src/helpers/prepare-swagger-docs.js - About 45 mins to fix

                                  Function applyHeadersAndStatus has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  export default function applyHeadersAndStatus() {
                                    const { _headers, statusCode } = this;
                                  
                                    if (typeof statusCode === 'string') {
                                      this.writeStatus(statusCode);
                                  Severity: Minor
                                  Found in src/response-proto/http/header-chunks/apply-headers-and-status.js - About 45 mins 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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language