resource-watch/document-adapter

View on GitHub

Showing 92 of 92 total issues

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

const checkPermissionModify = async (ctx, next) => {
    logger.debug('Checking if the user has permissions');
    const user = ctx.request.body.loggedUser;
    const { dataset } = ctx.request.body;
    if (!user) {
Severity: Minor
Found in app/src/routes/api/v1/dataset.router.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 init has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    async init(consume) {
        let retryAttempts = 10;
        let conn;

        while (typeof conn === 'undefined' && retryAttempts > 0) {
Severity: Minor
Found in app/src/services/queueService.js - About 1 hr to fix

    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

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

        async init(consume) {
            let retryAttempts = 10;
            let conn;
    
            while (typeof conn === 'undefined' && retryAttempts > 0) {
    Severity: Minor
    Found in app/src/services/queueService.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 (el[name]) {
                            target[currentSelectElement.alias] = el[name];
                        }
    Severity: Major
    Found in app/src/serializers/jsonSerializer.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if (exists) {
                                  node.value = exists.value;
                              }
      Severity: Major
      Found in app/src/services/queryService.js - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if (mapping[node.value] && mapping[node.value].type === 'text') {
                                    node.value = `${node.value}.keyword`;
                                }
        Severity: Major
        Found in app/src/services/queryService.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if (el[name]) {
                                  target[currentSelectElement.alias] = el[name];
                              }
          Severity: Major
          Found in app/src/serializers/csvSerializer.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if (node.arguments[j].type === 'literal' && mapping[node.arguments[j].value] && mapping[node.arguments[j].value].type === 'text') {
                                        node.arguments[j].value = `${node.arguments[j].value}.keyword`;
                                    }
            Severity: Major
            Found in app/src/services/queryService.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (key.match(stripESSuffix)) {
                                          sanitizedKey = key.toLowerCase().replace(stripESSuffix, '');
                                      }
              Severity: Major
              Found in app/src/serializers/jsonSerializer.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if (mapping[node.value] && mapping[node.value].type === 'text') {
                                            node.value = `${node.value}.keyword`;
                                        }
                Severity: Major
                Found in app/src/services/queryService.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          for (let j = 0; j < node.arguments.length; j += 1) {
                                              if (node.arguments[j].type === 'literal' && mapping[node.arguments[j].value] && mapping[node.arguments[j].value].type === 'text') {
                                                  node.arguments[j].value = `${node.arguments[j].value}.keyword`;
                                              }
                                          }
                  Severity: Major
                  Found in app/src/services/queryService.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if (buckets[i][keys[j]].value) {
                                            obj[keys[j]] = buckets[i][keys[j]].value;
                                        }
                    Severity: Major
                    Found in app/src/serializers/csvSerializer.js - About 45 mins to fix

                      Consider simplifying this complex logical expression.
                      Open

                              if (this.resultScroll.aggregations) {
                                  const data = Scroll.serialize(this.resultScroll, this.parsed, this.format);
                                  this.stream.write(this.convertDataToDownload(data, this.format, true, false, this.cloneUrl), 'binary');
                              } else {
                                  this.first = true;
                      Severity: Major
                      Found in app/src/services/scroll.js - About 40 mins to fix

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

                        const containApps = (apps1, apps2) => {
                            if (!apps1 || !apps2) {
                                return false;
                            }
                            for (let i = 0, { length } = apps1; i < length; i += 1) {
                        Severity: Minor
                        Found in app/src/routes/api/v1/dataset.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

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

                        const containApps = (apps1, apps2) => {
                            if (!apps1 || !apps2) {
                                return false;
                            }
                            for (let i = 0, { length } = apps1; i < length; i += 1) {
                        Severity: Minor
                        Found in app/src/routes/api/v1/query.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

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

                            static async query(ctx) {
                                logger.info('Do Query with dataset', ctx.request.body);
                                logger.debug('Checking if is delete or select');
                        
                                try {
                        Severity: Minor
                        Found in app/src/routes/api/v1/query.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

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

                            async append(data) {
                                const taskMessage = task.createMessage(task.MESSAGE_TYPES.TASK_APPEND, data);
                                await this.sendMessage(taskMessage);
                            }
                        Severity: Major
                        Found in app/src/services/taskQueueService.js and 6 other locations - About 35 mins to fix
                        app/src/services/taskQueueService.js on lines 29..32
                        app/src/services/taskQueueService.js on lines 34..37
                        app/src/services/taskQueueService.js on lines 39..42
                        app/src/services/taskQueueService.js on lines 49..52
                        app/src/services/taskQueueService.js on lines 54..57
                        app/src/services/taskQueueService.js on lines 59..62

                        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 46.

                        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 7 locations. Consider refactoring.
                        Open

                            async deleteIndex(data) {
                                const taskMessage = task.createMessage(task.MESSAGE_TYPES.TASK_DELETE_INDEX, data);
                                await this.sendMessage(taskMessage);
                            }
                        Severity: Major
                        Found in app/src/services/taskQueueService.js and 6 other locations - About 35 mins to fix
                        app/src/services/taskQueueService.js on lines 29..32
                        app/src/services/taskQueueService.js on lines 34..37
                        app/src/services/taskQueueService.js on lines 39..42
                        app/src/services/taskQueueService.js on lines 44..47
                        app/src/services/taskQueueService.js on lines 49..52
                        app/src/services/taskQueueService.js on lines 54..57

                        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 46.

                        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 7 locations. Consider refactoring.
                        Open

                            async concat(data) {
                                const taskMessage = task.createMessage(task.MESSAGE_TYPES.TASK_CONCAT, data);
                                await this.sendMessage(taskMessage);
                            }
                        Severity: Major
                        Found in app/src/services/taskQueueService.js and 6 other locations - About 35 mins to fix
                        app/src/services/taskQueueService.js on lines 29..32
                        app/src/services/taskQueueService.js on lines 34..37
                        app/src/services/taskQueueService.js on lines 44..47
                        app/src/services/taskQueueService.js on lines 49..52
                        app/src/services/taskQueueService.js on lines 54..57
                        app/src/services/taskQueueService.js on lines 59..62

                        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 46.

                        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

                        Severity
                        Category
                        Status
                        Source
                        Language