resource-watch/rw_metadata

View on GitHub

Showing 18 of 35 total issues

Function exports has 81 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = (grunt) => {

    grunt.file.setBase('..');
    // eslint-disable-next-line import/no-extraneous-dependencies
    require('load-grunt-tasks')(grunt);
Severity: Major
Found in app/Gruntfile.js - About 3 hrs to fix

    Function init has 72 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const init = async () => {
        return new Promise((resolve, reject) => {
            async function onDbReady(err) {
                if (err) {
                    if (retries >= 0) {
    Severity: Major
    Found in app/src/app.js - About 2 hrs to fix

      Function onDbReady has 66 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              async function onDbReady(err) {
                  if (err) {
                      if (retries >= 0) {
                          retries--;
                          logger.error(`Failed to connect to MongoDB uri ${mongoUri}, retrying...`);
      Severity: Major
      Found in app/src/app.js - About 2 hrs to fix

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

        const authorizationMiddleware = async (ctx, next) => {
            // Get user from query (delete) or body (post-patch)
            const user = { ...(ctx.request.query.loggedUser ? JSON.parse(ctx.request.query.loggedUser) : {}), ...ctx.request.body.loggedUser };
            if (user.id === 'microservice') {
                await next();
        Severity: Minor
        Found in app/src/routes/api/v1/metadata.router.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

        Function exports has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports = (() => {
        
            const loadAPI = (app, path, pathApi) => {
                const routesFiles = fs.readdirSync(path);
                let existIndexRouter = false;
        Severity: Minor
        Found in app/src/loader.js - About 1 hr to fix

          Function validate has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static validate(koaObj) {
                  logger.info('Validating Metadata Creation');
                  koaObj.checkBody('language').notEmpty().check((lang) => MetadataValidator.isString(lang)).toLow();
                  koaObj.checkBody('application').notEmpty().check((application) => MetadataValidator.notEmptyString(application));
                  koaObj.checkBody('name').optional().check((name) => MetadataValidator.isString(name), 'should be a valid string');
          Severity: Minor
          Found in app/src/validators/metadata.validator.js - About 1 hr to fix

            Function serialize has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static serialize(data) {
            
                    const result = {
                        data: []
                    };
            Severity: Minor
            Found in app/src/serializers/metadata.serializer.js - About 1 hr to fix

              Function authorizationMiddleware has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const authorizationMiddleware = async (ctx, next) => {
                  // Get user from query (delete) or body (post-patch)
                  const user = { ...(ctx.request.query.loggedUser ? JSON.parse(ctx.request.query.loggedUser) : {}), ...ctx.request.body.loggedUser };
                  if (user.id === 'microservice') {
                      await next();
              Severity: Minor
              Found in app/src/routes/api/v1/metadata.router.js - About 1 hr to fix

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

                  Function getAll has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      static async getAll(filter, extendedFilter) {
                          const finalFilter = MetadataService.getFilter(filter);
                          let projection = null;
                          const options = {};
                          if (filter.sort) {
                  Severity: Minor
                  Found in app/src/services/metadata.service.js - About 1 hr to fix

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

                        static async create(user, dataset, resource, body) {
                            logger.debug('Checking if metadata exists');
                            const currentMetadata = await Metadata.findOne({
                                dataset,
                                'resource.id': resource.id,
                    Severity: Minor
                    Found in app/src/services/metadata.service.js - About 1 hr to fix

                      Function update has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                          static async update(dataset, resource, body) {
                              const metadata = await Metadata.findOne({
                                  dataset,
                                  'resource.id': resource.id,
                                  'resource.type': resource.type,
                      Severity: Minor
                      Found in app/src/services/metadata.service.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 init has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

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

                          static async getAll(ctx) {
                              logger.info('Getting all metadata');
                              const filter = {};
                              const extendedFilter = {};
                              filter.search = ctx.query.search ? ctx.query.search.split(' ').map((elem) => elem.trim()) : [];
                      Severity: Minor
                      Found in app/src/routes/api/v1/metadata.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 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 app/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 getFilter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                          static getFilter(filter) {
                              let finalFilter = {};
                              if (filter && filter.application) {
                                  finalFilter.application = { $in: filter.application.split(',') };
                              }
                      Severity: Minor
                      Found in app/src/services/metadata.service.js - About 45 mins to fix

                      Cognitive Complexity

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

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

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

                      Further reading

                      Avoid too many return statements within this function.
                      Open

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

                        Avoid too many return statements within this function.
                        Open

                                        return;
                        Severity: Major
                        Found in app/src/routes/api/v1/metadata.router.js - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language