resource-watch/dataset

View on GitHub

Showing 116 of 116 total issues

File dataset.service.js has 684 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const { URL } = require('url');
const { default: logger } = require('logger');
const Dataset = require('models/dataset.model');
const RelationshipsService = require('services/relationships.service');
const { RWAPIMicroservice } = require('rw-api-microservice-node');
Severity: Major
Found in src/services/dataset.service.js - About 1 day to fix

    File dataset.router.js has 558 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    Severity: Major
    Found in src/routes/api/v1/dataset.router.js - About 1 day to fix

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

      Severity: Minor
      Found in src/routes/api/v1/dataset.router.js - About 7 hrs 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 2 locations. Consider refactoring.
      Open

          static async update(dataset) {
              logger.debug('Sync update');
              try {
                  const response = await RWAPIMicroservice.requestToMicroservice({
                      uri: '/v1/task/sync-dataset/by-dataset',
      Severity: Major
      Found in src/services/sync.service.js and 1 other location - About 6 hrs to fix
      src/services/sync.service.js on lines 7..28

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

      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

          static async create(dataset) {
              logger.debug('Sync creation');
              try {
                  const response = await RWAPIMicroservice.requestToMicroservice({
                      uri: '/v1/task/sync-dataset',
      Severity: Major
      Found in src/services/sync.service.js and 1 other location - About 6 hrs to fix
      src/services/sync.service.js on lines 30..51

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

      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 41 (exceeds 5 allowed). Consider refactoring.
      Open

          static async update(id, dataset, user) {
              logger.debug(`[DatasetService]: Getting dataset with id:  ${id}`);
              logger.info(`[DBACCESS-FIND]: dataset.id: ${id}`);
      
              const currentDataset = await Dataset.findById(id).exec() || await Dataset.findOne({
      Severity: Minor
      Found in src/services/dataset.service.js - About 6 hrs 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 2 locations. Consider refactoring.
      Open

              if (dataset.sync && dataset.connectorType === 'document') {
                  try {
                      await SyncService.create(Object.assign(newDataset, dataset));
                  } catch (err) {
                      if (err instanceof SyncError) {
      Severity: Major
      Found in src/services/dataset.service.js and 1 other location - About 5 hrs to fix
      src/services/dataset.service.js on lines 460..473

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

      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 (dataset.sync && newDataset.connectorType === 'document') {
                  try {
                      await SyncService.update(Object.assign(newDataset, dataset));
                  } catch (err) {
                      if (err instanceof SyncError) {
      Severity: Major
      Found in src/services/dataset.service.js and 1 other location - About 5 hrs to fix
      src/services/dataset.service.js on lines 322..335

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

      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 getAll has 116 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Severity: Major
      Found in src/routes/api/v1/dataset.router.js - About 4 hrs to fix

        Function update has 108 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async update(id, dataset, user) {
                logger.debug(`[DatasetService]: Getting dataset with id:  ${id}`);
                logger.info(`[DBACCESS-FIND]: dataset.id: ${id}`);
        
                const currentDataset = await Dataset.findById(id).exec() || await Dataset.findOne({
        Severity: Major
        Found in src/services/dataset.service.js - About 4 hrs to fix

          Function getResources has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

              static async getResources(ids, includes, query = '', users = [], isAdmin = false) {
                  logger.info(`Getting resources of ids: ${ids}`);
                  delete query.ids;
                  delete query.usersRole;
                  let resources = includes.map(async (include) => {
          Severity: Minor
          Found in src/services/relationships.service.js - About 4 hrs 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

          File relationships.service.js has 313 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          const { default: logger } = require('logger');
          const { RWAPIMicroservice } = require('rw-api-microservice-node');
          const { INCLUDES } = require('app.constants');
          const { compact, uniq, startsWith, pickBy } = require('lodash');
          const InvalidRequest = require('errors/invalidRequest.error');
          Severity: Minor
          Found in src/services/relationships.service.js - About 3 hrs to fix

            Function getResources has 86 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async getResources(ids, includes, query = '', users = [], isAdmin = false) {
                    logger.info(`Getting resources of ids: ${ids}`);
                    delete query.ids;
                    delete query.usersRole;
                    let resources = includes.map(async (include) => {
            Severity: Major
            Found in src/services/relationships.service.js - About 3 hrs to fix

              Function create has 86 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static async create(dataset, user) {
                      logger.debug(`[DatasetService]: Getting dataset with name:  ${dataset.name}`);
                      logger.info(`[DBACCES-FIND]: dataset.name: ${dataset.name}`);
                      const tempSlug = await DatasetService.getSlug(dataset.name);
                      // Check if raw dataset
              Severity: Major
              Found in src/services/dataset.service.js - About 3 hrs to fix

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

                    static async create(dataset, user) {
                        logger.debug(`[DatasetService]: Getting dataset with name:  ${dataset.name}`);
                        logger.info(`[DBACCES-FIND]: dataset.name: ${dataset.name}`);
                        const tempSlug = await DatasetService.getSlug(dataset.name);
                        // Check if raw dataset
                Severity: Minor
                Found in src/services/dataset.service.js - About 3 hrs 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

                DatasetService has 27 functions (exceeds 20 allowed). Consider refactoring.
                Open

                class DatasetService {
                
                    // eslint-disable-next-line consistent-return
                    static async getSlug(name) {
                        const valid = false;
                Severity: Minor
                Found in src/services/dataset.service.js - About 3 hrs to fix

                  Function getFilteredQuery has 77 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

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

                    File dataset.validator.js has 286 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    const { default: logger } = require('logger');
                    const DatasetNotValid = require('errors/datasetNotValid.error');
                    const { CONNECTOR_TYPES } = require('app.constants');
                    const { RASDAMAN_TYPES } = require('app.constants');
                    const { URL } = require('url');
                    Severity: Minor
                    Found in src/validators/dataset.validator.js - About 2 hrs to fix

                      Function init has 63 lines of code (exceeds 25 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: Major
                      Found in src/app.ts - About 2 hrs to fix

                        Function checkConnectorUrl has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                        Open

                            static checkConnectorUrl(connectorUrl, koaObj) {
                                let validation = false;
                                const {
                                    connectorType, provider, data, tableName, sources
                                } = koaObj.request.body;
                        Severity: Minor
                        Found in src/validators/dataset.validator.js - About 2 hrs 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