nanoexpress/nanoexpress

View on GitHub

Showing 55 of 55 total issues

Identical blocks of code found in 2 locations. Consider refactoring.
Open

            if (
              fetchUrl &&
              reqPathLength > 1 &&
              req.path.charAt(reqPathLength - 1) === '/'
            ) {
Severity: Major
Found in src/Route.js and 1 other location - About 1 hr to fix
src/Route.js on lines 306..312

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 69.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function http has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  prepared.http = async (res, req) => {
    // Allow waiting for request finishing
    let isAborted = false;
    res.onAborted(() => {
      isAborted = true;
Severity: Minor
Found in src/packed/defines/proxy.js - About 1 hr to fix

    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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      export default function getIP() {
        // Detect self
        const _self = this.send ? this : this.__response;
      
        return Buffer.from(_self.getProxiedRemoteAddressAsText()).toString();
      Severity: Major
      Found in src/response-proto/http/polyfill-chunks/get-proxied-ip.js and 1 other location - About 1 hr to fix
      src/response-proto/http/polyfill-chunks/get-response-ip.js on lines 3..8

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 60.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      export default function getIP() {
        // Detect self
        const _self = this.send ? this : this.__response;
      
        return Buffer.from(_self.getRemoteAddressAsText()).toString();
      Severity: Major
      Found in src/response-proto/http/polyfill-chunks/get-response-ip.js and 1 other location - About 1 hr to fix
      src/response-proto/http/polyfill-chunks/get-proxied-ip.js on lines 3..8

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 60.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      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
                              Severity
                              Category
                              Status
                              Source
                              Language