resource-watch/widget

View on GitHub

Showing 77 of 77 total issues

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

    static getFilteredQuery(query, ids = []) {
        const { collection, favourite } = query;
        if (!query.application && query.app) {
            query.application = query.app;
            if (favourite) {
Severity: Minor
Found in app/src/services/widget.service.js - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

class WidgetNotFound extends Error {

    constructor(message) {
        super(message);
        this.name = 'WidgetNotFound';
Severity: Major
Found in app/src/errors/widgetNotFound.error.js and 3 other locations - About 35 mins to fix
app/src/errors/datasetNotFound.error.js on lines 1..9
app/src/errors/duplicatedWidget.error.js on lines 1..9
app/src/errors/widgetProtected.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 4 locations. Consider refactoring.
Open

class WidgetProtected extends Error {

    constructor(message) {
        super(message);
        this.name = 'WidgetProtected';
Severity: Major
Found in app/src/errors/widgetProtected.error.js and 3 other locations - About 35 mins to fix
app/src/errors/datasetNotFound.error.js on lines 1..9
app/src/errors/duplicatedWidget.error.js on lines 1..9
app/src/errors/widgetNotFound.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 3 locations. Consider refactoring.
Open

        koaObj.checkBody('name')
            .notEmpty()
            .notBlank()
            .check((v) => WidgetValidator.isString(v), 'must be a string');
Severity: Minor
Found in app/src/validators/widget.validator.js and 2 other locations - About 35 mins to fix
app/src/validators/widget.validator.js on lines 24..27
app/src/validators/widget.validator.js on lines 46..49

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

        koaObj.checkBody('env')
            .optional()
            .notBlank()
            .check((v) => WidgetValidator.isString(v), 'must be a string');
Severity: Minor
Found in app/src/validators/widget.validator.js and 2 other locations - About 35 mins to fix
app/src/validators/widget.validator.js on lines 42..45
app/src/validators/widget.validator.js on lines 46..49

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

class DatasetNotFound extends Error {

    constructor(message) {
        super(message);
        this.name = 'DatasetNotFound';
Severity: Major
Found in app/src/errors/datasetNotFound.error.js and 3 other locations - About 35 mins to fix
app/src/errors/duplicatedWidget.error.js on lines 1..9
app/src/errors/widgetNotFound.error.js on lines 1..9
app/src/errors/widgetProtected.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 3 locations. Consider refactoring.
Open

        koaObj.checkBody('dataset')
            .notEmpty()
            .notBlank()
            .check((v) => WidgetValidator.isString(v), 'must be a string');
Severity: Minor
Found in app/src/validators/widget.validator.js and 2 other locations - About 35 mins to fix
app/src/validators/widget.validator.js on lines 24..27
app/src/validators/widget.validator.js on lines 42..45

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

class DuplicatedWidget extends Error {

    constructor(message) {
        super(message);
        this.name = 'DuplicatedWidget';
Severity: Major
Found in app/src/errors/duplicatedWidget.error.js and 3 other locations - About 35 mins to fix
app/src/errors/datasetNotFound.error.js on lines 1..9
app/src/errors/widgetNotFound.error.js on lines 1..9
app/src/errors/widgetProtected.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

Avoid too many return statements within this function.
Open

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

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

            if (!currentWidget) {
                logger.info(`[WidgetService]: Widget with id ${id} doesn't exist`);
                throw new WidgetNotFound(`Widget with id '${id}' doesn't exist`);
            }
    Severity: Minor
    Found in app/src/services/widget.service.js and 2 other locations - About 30 mins to fix
    app/src/services/widget.service.js on lines 149..152
    app/src/services/widget.service.js on lines 231..234

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

            if (!currentWidget) {
                logger.info(`[WidgetService]: Widget with id ${id} doesn't exist`);
                throw new WidgetNotFound(`Widget with id '${id}' doesn't exist`);
            }
    Severity: Minor
    Found in app/src/services/widget.service.js and 2 other locations - About 30 mins to fix
    app/src/services/widget.service.js on lines 48..51
    app/src/services/widget.service.js on lines 231..234

    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 app/src/routes/api/v1/widget.router.js - About 30 mins to fix

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

              if (!widget) {
                  logger.error(`[WidgetService]: Widget not found with the id ${id}`);
                  throw new WidgetNotFound(`Widget not found with the id ${id}`);
              }
      Severity: Minor
      Found in app/src/services/widget.service.js and 2 other locations - About 30 mins to fix
      app/src/services/widget.service.js on lines 48..51
      app/src/services/widget.service.js on lines 149..152

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

          static async delete(ctx) {
              const id = ctx.params.widget;
              logger.info(`[WidgetRouter] Deleting widget with id: ${id}`);
              try {
                  let { dataset } = ctx.params;
      Severity: Minor
      Found in app/src/routes/api/v1/widget.router.js - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

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

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

          static async getByDataset(resource) {
              logger.debug(`[WidgetService] Getting widgets for datasets with ids ${resource.ids}`);
              if (resource.app) {
                  if (resource.app.indexOf('@') >= 0) {
                      resource.app = {
      Severity: Minor
      Found in app/src/services/widget.service.js - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

          static async checkDataset(ctx) {
              if (ctx.params.dataset || ctx.request.body.dataset) {
                  const datasetId = ctx.params.dataset || ctx.request.body.dataset;
                  logger.info(`[DatasetService] Validating presence of dataset with id: ${datasetId}`);
      
      
      Severity: Minor
      Found in app/src/services/dataset.service.js - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Severity
      Category
      Status
      Source
      Language