resource-watch/widget

View on GitHub

Showing 37 of 77 total issues

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

    static async clone(id, widget, userId, apiKey) {
        logger.debug(`[WidgetService]: Getting widget with id: ${id}`);
        logger.debug(`[WidgetService]: New user id: ${userId}`);
        const currentWidget = await Widget.findById(id).exec() || await Widget.findOne({
            slug: id
Severity: Minor
Found in app/src/services/widget.service.js - About 1 hr to fix

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

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

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

          static serializeElement(el) {
              return {
                  id: el._id,
                  type: 'widget',
                  attributes: {
      Severity: Minor
      Found in app/src/serializers/widget.serializer.js - About 1 hr to fix

        Function validationMiddleware has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const validationMiddleware = async (ctx, next) => {
            logger.debug(`[WidgetRouter] Validating the widget`);
            if (ctx.request.body.widget) {
                ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.widget);
                delete ctx.request.body.widget;
        Severity: Minor
        Found in app/src/routes/api/v1/widget.router.js - About 1 hr to fix

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

              static async getAll(user, apiKey, query = {}, dataset = null) {
                  const sort = query.sort || '';
                  const page = query['page[number]'] ? parseInt(query['page[number]'], 10) : 1;
                  logger.debug(`pageNumber param: ${page}`);
                  const limit = query['page[size]'] ? parseInt(query['page[size]'], 10) : 10;
          Severity: Minor
          Found in app/src/services/widget.service.js - About 1 hr to fix

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

                static serialize(data, link = null) {
                    const result = {};
                    if (data) {
                        if (data.docs) {
                            result.data = data.docs.map((el) => WidgetSerializer.serializeElement(el));
            Severity: Minor
            Found in app/src/serializers/widget.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 get has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                static async get(id, dataset, apiKey, includes = [], user = null) {
                    logger.debug(`[WidgetService]: Getting widget with id: ${id}`);
                    const widget = await Widget.findById(id).exec();
                    if (widget) {
                        if (dataset && dataset !== widget.dataset) {
            Severity: Minor
            Found in app/src/services/widget.service.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

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

            module.exports = (() => {
            
                const loadAPI = (app, path, pathApi) => {
                    const routesFiles = fs.readdirSync(path);
                    let existIndexRouter = false;
            Severity: Minor
            Found in app/src/loader.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 (widget.widgetConfig.data.url.indexOf('?') >= 0) {
                                    widget.widgetConfig.data.url += `&${params}`;
                                } else {
                                    widget.widgetConfig.data.url += `?${params}`;
                                }
            Severity: Major
            Found in app/src/routes/api/v1/widget.router.js - About 45 mins to fix

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

                  static getFilteredQuery(query, ids = []) {
                      const { collection, favourite } = query;
                      if (!query.application && query.app) {
                          query.application = query.app;
                          if (favourite) {
              Severity: Minor
              Found in app/src/services/widget.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 validationMiddleware has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              const validationMiddleware = async (ctx, next) => {
                  logger.debug(`[WidgetRouter] Validating the widget`);
                  if (ctx.request.body.widget) {
                      ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.widget);
                      delete ctx.request.body.widget;
              Severity: Minor
              Found in app/src/routes/api/v1/widget.router.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/api/v1/widget.router.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return;
                Severity: Major
                Found in app/src/routes/api/v1/widget.router.js - About 30 mins to fix

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

                      static async getByDataset(resource) {
                          logger.debug(`[WidgetService] Getting widgets for datasets with ids ${resource.ids}`);
                          if (resource.app) {
                              if (resource.app.indexOf('@') >= 0) {
                                  resource.app = {
                  Severity: Minor
                  Found in app/src/services/widget.service.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

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

                      static async delete(ctx) {
                          const id = ctx.params.widget;
                          logger.info(`[WidgetRouter] Deleting widget with id: ${id}`);
                          try {
                              let { dataset } = ctx.params;
                  Severity: Minor
                  Found in app/src/routes/api/v1/widget.router.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

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

                      static async getAll(user, apiKey, query = {}, dataset = null) {
                          const sort = query.sort || '';
                          const page = query['page[number]'] ? parseInt(query['page[number]'], 10) : 1;
                          logger.debug(`pageNumber param: ${page}`);
                          const limit = query['page[size]'] ? parseInt(query['page[size]'], 10) : 10;
                  Severity: Minor
                  Found in app/src/services/widget.service.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

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

                      static async checkDataset(ctx) {
                          if (ctx.params.dataset || ctx.request.body.dataset) {
                              const datasetId = ctx.params.dataset || ctx.request.body.dataset;
                              logger.info(`[DatasetService] Validating presence of dataset with id: ${datasetId}`);
                  
                  
                  Severity: Minor
                  Found in app/src/services/dataset.service.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