resource-watch/dataset

View on GitHub

Showing 60 of 122 total issues

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

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

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

    const validationMiddleware = async (ctx, next) => {
        logger.info(`[DatasetRouter] Validating`);
        if (ctx.request.body.dataset) {
            ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.dataset);
            delete ctx.request.body.dataset;
    Severity: Minor
    Found in src/routes/api/v1/dataset.router.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 notifyAdapterCreate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        static async notifyAdapterCreate(ctx, dataset) {
            const { connectorType, provider } = dataset;
            const clonedDataset = { ...dataset.toObject() };
    
            clonedDataset.id = dataset._id;
    Severity: Minor
    Found in src/routes/api/v1/dataset.router.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

    const init: () => Promise<IInit> = async (): Promise<IInit> => {
        return new Promise((resolve, reject) => {
            async function onDbReady(err: Error): Promise<void> {
                if (err) {
                    if (retries >= 0) {
    Severity: Minor
    Found in src/app.ts - 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 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 delete has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        static async delete(dataset, user, apiKey, applicationBasedDelete = true) {
            logger.debug(`[DatasetService]: Getting dataset with id: ${dataset.id}`);
            logger.info(`[DBACCESS-FIND]: dataset.id: ${dataset.id}`);
            const id = dataset.id;
            if (!dataset) {
    Severity: Minor
    Found in src/services/dataset.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

    Avoid deeply nested control flow statements.
    Open

                            } else if (Object.keys(result).indexOf(el.attributes.dataset) < 0) {
                                result[el.attributes.dataset] = [el];
                            } else {
                                result[el.attributes.dataset].push(el);
                            }
    Severity: Major
    Found in src/services/relationships.service.js - About 45 mins to fix

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

          static getTableName(dataset) {
              try {
                  if (dataset.provider === 'cartodb' && dataset.connectorUrl) {
                      if (dataset.connectorUrl.indexOf('/tables/') >= 0) {
                          return new URL(dataset.connectorUrl).pathname.split('/tables/')[1].split('/')[0];
      Severity: Minor
      Found in src/services/dataset.service.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

      Avoid deeply nested control flow statements.
      Open

                                  if (isAdmin) {
                                      result[el._id] = el;
                                  }
      Severity: Major
      Found in src/services/relationships.service.js - About 45 mins to fix

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

            static async notifyAdapter(ctx, dataset) {
                const { connectorType, provider } = dataset;
                const clonedDataset = { ...dataset.toObject() };
                clonedDataset.id = dataset._id;
                clonedDataset.connector_url = dataset.connectorUrl;
        Severity: Minor
        Found in 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 getAll has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            static async getAll(apiKey, query = {}, isAdmin = false) {
                logger.debug(`[DatasetService]: Getting all datasets`);
                const sort = query.sort || '';
                const page = query['page[number]'] ? parseInt(query['page[number]'], 10) : 1;
                const limit = query['page[size]'] ? parseInt(query['page[size]'], 10) : 10;
        Severity: Minor
        Found in src/services/dataset.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

        Avoid too many return statements within this function.
        Open

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

          Avoid too many return statements within this function.
          Open

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

            Avoid too many return statements within this function.
            Open

                        return dataset.tableName;
            Severity: Major
            Found in src/services/dataset.service.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

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

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

                    static async create(ctx) {
                        logger.info(`[DatasetRouter] Creating dataset with name: ${ctx.request.body.name}`);
                        try {
                            const user = DatasetRouter.getUser(ctx);
                            const dataset = await DatasetService.create(ctx.request.body, user, ctx.request.headers['x-api-key']);
                Severity: Minor
                Found in src/routes/api/v1/dataset.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 getFilteredQuery has a Cognitive Complexity of 6 (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 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

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

                    static async get(ctx) {
                        const id = ctx.params.dataset;
                        logger.info(`[DatasetRouter] Getting dataset with id: ${id}`);
                        const user = DatasetRouter.getUser(ctx);
                        const { query } = ctx;
                Severity: Minor
                Found in src/routes/api/v1/dataset.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 getFields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    static async getFields(filePath, provider) {
                        logger.debug('Obtaining fields');
                        let fields = null;
                        try {
                            switch (provider) {
                Severity: Minor
                Found in src/services/fileDataService.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 checkSync has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    static checkSync(sync) {
                        if (DatasetValidator.isObject(sync)) {
                            try {
                                cronParser.parseExpression(sync.cronPattern);
                                if (['concat', 'overwrite'].indexOf(sync.action) >= 0 && DatasetValidator.validUrl(sync.url)) {
                Severity: Minor
                Found in src/validators/dataset.validator.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