resource-watch/control-tower

View on GitHub

Showing 19 of 21 total issues

Function dispatch has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
Open

    static async dispatch(ctx) {
        logger.info(`Dispatch url ${ctx.request.url} and method ${ctx.request.method}`);
        try {
            logger.debug('Obtaining config request');
            const infoRequest = await DispatcherService.getRequest(ctx);
Severity: Minor
Found in app/src/routes/dispatcher.js - About 1 day 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 getRequest has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

    static async getRequest(ctx) {
        logger.info(`[DispatcherService - getRequest] Searching endpoint where redirect url ${ctx.request.url}
            and method ${ctx.request.method}`);
        const parsedUrl = url.parse(ctx.request.url);
        const endpoint = await Dispatcher.getEndpoint(parsedUrl.pathname, ctx.request.method);
Severity: Minor
Found in app/src/services/dispatcher.service.js - About 7 hrs 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 getRequest has 106 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async getRequest(ctx) {
        logger.info(`[DispatcherService - getRequest] Searching endpoint where redirect url ${ctx.request.url}
            and method ${ctx.request.method}`);
        const parsedUrl = url.parse(ctx.request.url);
        const endpoint = await Dispatcher.getEndpoint(parsedUrl.pathname, ctx.request.method);
Severity: Major
Found in app/src/services/dispatcher.service.js - About 4 hrs to fix

    Function dispatch has 92 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async dispatch(ctx) {
            logger.info(`Dispatch url ${ctx.request.url} and method ${ctx.request.method}`);
            try {
                logger.debug('Obtaining config request');
                const infoRequest = await DispatcherService.getRequest(ctx);
    Severity: Major
    Found in app/src/routes/dispatcher.js - About 3 hrs to fix

      Function exports has 91 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      module.exports = (grunt) => {
      
          grunt.file.setBase('..');
      
          // eslint-disable-next-line import/no-extraneous-dependencies
      Severity: Major
      Found in app/Gruntfile.js - About 3 hrs to fix

        Function init has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        async function init() {
            return new Promise((resolve, reject) => {
                async function onDbReady(err) {
                    if (err) {
                        if (retries >= 0) {
        Severity: Major
        Found in app/src/app.js - About 2 hrs to fix

          Function onDbReady has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  async function onDbReady(err) {
                      if (err) {
                          if (retries >= 0) {
                              // eslint-disable-next-line no-plusplus
                              retries--;
          Severity: Major
          Found in app/src/app.js - About 2 hrs to fix

            Function saveEndpoint has 53 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async saveEndpoint(endpoint, microservice) {
                    logger.info(`[MicroserviceService] Saving endpoint ${endpoint.path}`);
                    logger.debug(`[MicroserviceService] Searching if path ${endpoint.path} exists in endpoints`);
                    endpoint.redirect.url = microservice.url;
                    // searching
            Severity: Major
            Found in app/src/services/microservice.service.js - About 2 hrs to fix

              Function saveEndpoint has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  static async saveEndpoint(endpoint, microservice) {
                      logger.info(`[MicroserviceService] Saving endpoint ${endpoint.path}`);
                      logger.debug(`[MicroserviceService] Searching if path ${endpoint.path} exists in endpoints`);
                      endpoint.redirect.url = microservice.url;
                      // searching
              Severity: Minor
              Found in app/src/services/microservice.service.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 serialize has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  static serialize(data, link = null) {
                      const result = {};
                      if (data && Array.isArray(data) && data.length === 0) {
                          result.data = [];
                          return result;
              Severity: Minor
              Found in app/src/serializers/microservice.serializer.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 register has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static async register(name, url, endpoints) {
                      try {
                          logger.info(`[MicroserviceRouter] Registering new microservice with name ${name} and url ${url}`);
                          logger.debug('[MicroserviceRouter] Search if microservice already exist');
                          const existingMicroservice = await MicroserviceModel.findOne({
              Severity: Minor
              Found in app/src/services/microservice.service.js - About 1 hr to fix

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

                function loadAPI(app, routersPath, pathApi) {
                    const routesFiles = fs.readdirSync(routersPath);
                    let existIndexRouter = false;
                    routesFiles.forEach((file) => {
                        const newPath = routersPath ? `${routersPath}/${file}` : file;
                Severity: Minor
                Found in app/src/loader.js - About 1 hr to fix

                  Function serialize has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      static serialize(data, link = null) {
                          const result = {};
                          if (data && Array.isArray(data) && data.length === 0) {
                              result.data = [];
                              return result;
                  Severity: Minor
                  Found in app/src/serializers/microservice.serializer.js - About 1 hr to fix

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

                    const getLoggedUser = async (ctx, next) => {
                        logger.debug('[getLoggedUser] Obtaining loggedUser for token');
                        if (!ctx.request.header.authorization) {
                            logger.debug('[getLoggedUser] No authorization header found, returning');
                            ctx.throw(401, 'Not authenticated');
                    Severity: Minor
                    Found in app/src/services/getUserFromToken.service.js - About 1 hr to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if (configRequest.body[key] !== null && configRequest.body[key] !== undefined) {
                                                  if (typeof configRequest.body[key] === 'object') {
                                                      body[key] = JSON.stringify(configRequest.body[key]);
                                                  } else {
                                                      body[key] = configRequest.body[key];
                      Severity: Major
                      Found in app/src/services/dispatcher.service.js - About 45 mins to fix

                        Function register has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            static async register(name, url, endpoints) {
                                try {
                                    logger.info(`[MicroserviceRouter] Registering new microservice with name ${name} and url ${url}`);
                                    logger.debug('[MicroserviceRouter] Search if microservice already exist');
                                    const existingMicroservice = await MicroserviceModel.findOne({
                        Severity: Minor
                        Found in app/src/services/microservice.service.js - About 35 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

                        Function getLoggedUser has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            static getLoggedUser(ctx) {
                                if (ctx.state) {
                                    if (ctx.state.user) {
                                        return ctx.state.user;
                                    }
                        Severity: Minor
                        Found in app/src/routes/dispatcher.js - About 35 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 too many return statements within this function.
                        Open

                                        return;
                        Severity: Major
                        Found in app/src/routes/dispatcher.js - About 30 mins to fix

                          Function loadAPI has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function loadAPI(app, routersPath, pathApi) {
                              const routesFiles = fs.readdirSync(routersPath);
                              let existIndexRouter = false;
                              routesFiles.forEach((file) => {
                                  const newPath = routersPath ? `${routersPath}/${file}` : file;
                          Severity: Minor
                          Found in app/src/loader.js - About 25 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