resource-watch/dataset

View on GitHub

Showing 122 of 122 total issues

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 src/loader.js - About 1 hr to fix

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

                            if (pathApi) {
                                app.use(mount(pathApi, require(newPath).middleware()));
                            } else {
                                app.use(require(newPath).middleware());
                            }
    Severity: Major
    Found in src/loader.js and 1 other location - About 1 hr to fix
    src/loader.js on lines 42..46

    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

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

                if (pathApi) {
                    app.use(mount(pathApi, require(newPath).middleware()));
                } else {
                    app.use(require(newPath).middleware());
                }
    Severity: Major
    Found in src/loader.js and 1 other location - About 1 hr to fix
    src/loader.js on lines 25..29

    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 update has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        static async update(ctx) {
            const id = ctx.params.dataset;
            logger.info(`[DatasetRouter] Updating dataset with id: ${id}`);
            try {
                const user = DatasetRouter.getUser(ctx);
    Severity: Minor
    Found in 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 getFields has 27 lines of code (exceeds 25 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 1 hr to fix

      Function updateEnv has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async updateEnv(datasetId, env, apiKey) {
              logger.debug('Updating env of all resources of dataset', datasetId, 'with env ', env);
              try {
                  logger.debug('Updating widgets');
                  await RWAPIMicroservice.requestToMicroservice({
      Severity: Minor
      Found in src/services/dataset.service.js - About 1 hr to fix

        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

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

                      const widgets = await RWAPIMicroservice.requestToMicroservice({
                          uri: `/v1/dataset/${id}/widget?protected=true`,
                          method: 'GET',
                          json: true,
                          headers: {
          Severity: Major
          Found in src/services/dataset.service.js and 3 other locations - About 55 mins to fix
          src/services/dataset.service.js on lines 543..550
          src/services/relationships.service.js on lines 197..204
          src/services/sync.service.js on lines 62..69

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

          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

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

                          ctx.query.ids = ctx.query.ids.length > 0 ? ctx.query.ids.join(',') : '';
          Severity: Minor
          Found in src/routes/api/v1/dataset.router.js and 1 other location - About 55 mins to fix
          src/routes/api/v1/dataset.router.js on lines 392..392

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

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

                  const result = await RWAPIMicroservice.requestToMicroservice({
                      uri: `/v1/dataset/vocabulary/find${vocabularyQuery}`,
                      method: 'GET',
                      json: true,
                      headers: {
          Severity: Major
          Found in src/services/relationships.service.js and 3 other locations - About 55 mins to fix
          src/services/dataset.service.js on lines 543..550
          src/services/dataset.service.js on lines 560..567
          src/services/sync.service.js on lines 62..69

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

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

                      const layers = await RWAPIMicroservice.requestToMicroservice({
                          uri: `/v1/dataset/${id}/layer?protected=true`,
                          method: 'GET',
                          json: true,
                          headers: {
          Severity: Major
          Found in src/services/dataset.service.js and 3 other locations - About 55 mins to fix
          src/services/dataset.service.js on lines 560..567
          src/services/relationships.service.js on lines 197..204
          src/services/sync.service.js on lines 62..69

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

          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

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

                          ctx.query.ids = ctx.query.ids.length > 0 ? ctx.query.ids.join(',') : '';
          Severity: Minor
          Found in src/routes/api/v1/dataset.router.js and 1 other location - About 55 mins to fix
          src/routes/api/v1/dataset.router.js on lines 382..382

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

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

                      const response = await RWAPIMicroservice.requestToMicroservice({
                          uri: `/v1/task/sync-dataset/by-dataset/${id}`,
                          method: 'DELETE',
                          json: true,
                          headers: {
          Severity: Major
          Found in src/services/sync.service.js and 3 other locations - About 55 mins to fix
          src/services/dataset.service.js on lines 543..550
          src/services/dataset.service.js on lines 560..567
          src/services/relationships.service.js on lines 197..204

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

          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

                                  if (query[param].indexOf('@') >= 0) {
                                      query[param] = {
                                          $all: query[param].split('@').map((elem) => elem.trim())
                                      };
                                  } else {
          Severity: Minor
          Found in src/services/dataset.service.js and 1 other location - About 50 mins to fix
          src/services/dataset.service.js on lines 135..139

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

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

                  let dataset = await Dataset.findById(id).exec() || await Dataset.findOne({
                      slug: id
                  }).exec();
          Severity: Major
          Found in src/services/dataset.service.js and 4 other locations - About 50 mins to fix
          src/services/dataset.service.js on lines 375..377
          src/services/dataset.service.js on lines 578..580
          src/services/dataset.service.js on lines 720..722
          src/services/dataset.service.js on lines 789..791

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

          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