resource-watch/dataset

View on GitHub

Showing 122 of 122 total issues

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

class DatasetProtected extends Error {

    constructor(message) {
        super(message);
        this.name = 'DatasetProtected';
Severity: Major
Found in src/errors/datasetProtected.error.js and 6 other locations - About 35 mins to fix
src/errors/connectorUrlNotValid.error.js on lines 1..9
src/errors/datasetDuplicated.error.js on lines 1..9
src/errors/datasetNotFound.error.js on lines 1..9
src/errors/forbiddenRequest.error.js on lines 1..9
src/errors/invalidRequest.error.js on lines 1..9
src/errors/sync.error.js on lines 1..9

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

class InvalidRequest extends Error {

    constructor(message) {
        super(message);
        this.name = 'ConnectorUrlNotValid';
Severity: Major
Found in src/errors/invalidRequest.error.js and 6 other locations - About 35 mins to fix
src/errors/connectorUrlNotValid.error.js on lines 1..9
src/errors/datasetDuplicated.error.js on lines 1..9
src/errors/datasetNotFound.error.js on lines 1..9
src/errors/datasetProtected.error.js on lines 1..9
src/errors/forbiddenRequest.error.js on lines 1..9
src/errors/sync.error.js on lines 1..9

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

class SyncError extends Error {

    constructor(message) {
        super(message);
        this.name = 'SyncError';
Severity: Major
Found in src/errors/sync.error.js and 6 other locations - About 35 mins to fix
src/errors/connectorUrlNotValid.error.js on lines 1..9
src/errors/datasetDuplicated.error.js on lines 1..9
src/errors/datasetNotFound.error.js on lines 1..9
src/errors/datasetProtected.error.js on lines 1..9
src/errors/forbiddenRequest.error.js on lines 1..9
src/errors/invalidRequest.error.js on lines 1..9

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

class DatasetDuplicated extends Error {

    constructor(message) {
        super(message);
        this.name = 'DatasetDuplicated';
Severity: Major
Found in src/errors/datasetDuplicated.error.js and 6 other locations - About 35 mins to fix
src/errors/connectorUrlNotValid.error.js on lines 1..9
src/errors/datasetNotFound.error.js on lines 1..9
src/errors/datasetProtected.error.js on lines 1..9
src/errors/forbiddenRequest.error.js on lines 1..9
src/errors/invalidRequest.error.js on lines 1..9
src/errors/sync.error.js on lines 1..9

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

class ConnectorUrlNotValid extends Error {

    constructor(message) {
        super(message);
        this.name = 'ConnectorUrlNotValid';
Severity: Major
Found in src/errors/connectorUrlNotValid.error.js and 6 other locations - About 35 mins to fix
src/errors/datasetDuplicated.error.js on lines 1..9
src/errors/datasetNotFound.error.js on lines 1..9
src/errors/datasetProtected.error.js on lines 1..9
src/errors/forbiddenRequest.error.js on lines 1..9
src/errors/invalidRequest.error.js on lines 1..9
src/errors/sync.error.js on lines 1..9

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

        koaObj.checkBody('mainDateField').optional().check((mainDateField) => mainDateField === null || DatasetValidator.isString(mainDateField), 'must be a string');
Severity: Minor
Found in src/validators/dataset.validator.js and 1 other location - About 35 mins to fix
src/validators/dataset.validator.js on lines 285..285

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

class ForbiddenRequest extends Error {

    constructor(message) {
        super(message);
        this.name = 'ForbiddenRequest';
Severity: Major
Found in src/errors/forbiddenRequest.error.js and 6 other locations - About 35 mins to fix
src/errors/connectorUrlNotValid.error.js on lines 1..9
src/errors/datasetDuplicated.error.js on lines 1..9
src/errors/datasetNotFound.error.js on lines 1..9
src/errors/datasetProtected.error.js on lines 1..9
src/errors/invalidRequest.error.js on lines 1..9
src/errors/sync.error.js on lines 1..9

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

        koaObj.checkBody('dataLastUpdated').optional().check((dataLastUpdated) => dataLastUpdated === null || DatasetValidator.isISOString(dataLastUpdated), 'must be an date');
Severity: Minor
Found in src/validators/dataset.validator.js and 1 other location - About 35 mins to fix
src/validators/dataset.validator.js on lines 205..205

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

        if (!currentDataset) {
            logger.error(`[DatasetService]: Dataset with id ${id} doesn't exist`);
            throw new DatasetNotFound(`Dataset with id '${id}' doesn't exist`);
        }
Severity: Major
Found in src/services/dataset.service.js and 4 other locations - About 30 mins to fix
src/services/dataset.service.js on lines 239..242
src/services/dataset.service.js on lines 378..381
src/services/dataset.service.js on lines 588..591
src/services/dataset.service.js on lines 792..795

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

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

        if (!currentDataset) {
            logger.error(`[DatasetService]: Dataset with id ${id} doesn't exist`);
            throw new DatasetNotFound(`Dataset with id '${id}' doesn't exist`);
        }
Severity: Major
Found in src/services/dataset.service.js and 4 other locations - About 30 mins to fix
src/services/dataset.service.js on lines 239..242
src/services/dataset.service.js on lines 378..381
src/services/dataset.service.js on lines 588..591
src/services/dataset.service.js on lines 723..726

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

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

        if (!dataset) {
            logger.error(`[DatasetService]: Dataset with id ${id} doesn't exist`);
            throw new DatasetNotFound(`Dataset with id '${id}' doesn't exist`);
        }
Severity: Major
Found in src/services/dataset.service.js and 4 other locations - About 30 mins to fix
src/services/dataset.service.js on lines 239..242
src/services/dataset.service.js on lines 378..381
src/services/dataset.service.js on lines 723..726
src/services/dataset.service.js on lines 792..795

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

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

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

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

                if (!dataset) {
                    logger.info(`[DatasetService]: Dataset with id ${id} doesn't exist`);
                    throw new DatasetNotFound(`Dataset with id '${id}' doesn't exist`);
                }
        Severity: Major
        Found in src/services/dataset.service.js and 4 other locations - About 30 mins to fix
        src/services/dataset.service.js on lines 378..381
        src/services/dataset.service.js on lines 588..591
        src/services/dataset.service.js on lines 723..726
        src/services/dataset.service.js on lines 792..795

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

        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

        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

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

                  if (!currentDataset) {
                      logger.error(`[DatasetService]: Dataset with id ${id} doesn't exist`);
                      throw new DatasetNotFound(`Dataset with id '${id}' doesn't exist`);
                  }
          Severity: Major
          Found in src/services/dataset.service.js and 4 other locations - About 30 mins to fix
          src/services/dataset.service.js on lines 239..242
          src/services/dataset.service.js on lines 588..591
          src/services/dataset.service.js on lines 723..726
          src/services/dataset.service.js on lines 792..795

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

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

          Severity
          Category
          Status
          Source
          Language