RouteInjector/route-injector

View on GitHub

Showing 414 of 414 total issues

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

function getExtension(filename) {
    var ext = path.extname(filename || '').split('.');
    return ext[ext.length - 1];
}
Severity: Major
Found in lib/engine/routeinjector/images/image-injector.js and 2 other locations - About 50 mins to fix
lib/engine/routeinjector/files/file-injector.js on lines 252..255
lib/engine/routeinjector/images/new-image-injector.js on lines 402..405

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

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

function getExtension(filename) {
    var ext = path.extname(filename || '').split('.');
    return ext[ext.length - 1];
}
Severity: Major
Found in lib/engine/routeinjector/files/file-injector.js and 2 other locations - About 50 mins to fix
lib/engine/routeinjector/images/image-injector.js on lines 444..447
lib/engine/routeinjector/images/new-image-injector.js on lines 402..405

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

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

                    if (result != null) {
                        if(cb) return cb(decoded);
                        res.statusCode = statusCode.OK;
                        res.json(decoded);
                        res.end();
Severity: Minor
Found in lib/engine/routeinjector/routes/auth.js and 1 other location - About 50 mins to fix
lib/engine/routeinjector/routes/auth.js on lines 170..191

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

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

            if (aconf.login.stateless) {
                if(cb) return cb(decoded);

                res.statusCode = statusCode.OK;
                res.json(decoded);
Severity: Minor
Found in lib/engine/routeinjector/routes/auth.js and 1 other location - About 50 mins to fix
lib/engine/routeinjector/routes/auth.js on lines 178..189

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

Avoid deeply nested control flow statements.
Open

                    if (value !== undefined) {
                        _.set(target, f, value);
                    }
Severity: Major
Found in lib/engine/routeinjector/newdenormalizer.js - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        if (objDoc == null || objDoc == undefined) {
                            //Null objects marked as undefined
                            doc = undefined;
                        }
    Severity: Major
    Found in lib/engine/routeinjector/utils.js - About 45 mins to fix

      Function TypeBased has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      var TypeBased = /** @class */ (function () {
          function TypeBased() {
          }
          //TODO: Add hooks and middlewares
          TypeBased.directReference = function (model, field, refModel, refField) {
      Severity: Minor
      Found in lib/engine/routeinjector/newTypeBased/TypeBased.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

      Function injectRefs has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      function injectRefs(app, baseConfig, refConfig, Model, refModel, key) {
      Severity: Minor
      Found in lib/engine/routeinjector/typeBased.js - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if (parent) {
                                var child = element.substring(parentPath.length + 1);
                                return module.exports.getElementSchema(parent.schema.paths, child);
                            }
        Severity: Major
        Found in lib/engine/routeinjector/utils.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              for (var i in doc) {
                                  if (doc.hasOwnProperty(i)) {
                                      //Prune all the elements in the object
                                      doc[i] = prune(doc[i]);
                                  }
          Severity: Major
          Found in lib/engine/routeinjector/utils.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                                                if (e) {
                                                                    log.error(e);
                                                                    res.json(e);
                                                                    res.statusCode = statusCode.INTERNAL_SERVER_ERROR;
                                                                    return res.end();
            Severity: Major
            Found in lib/engine/routeinjector/images/new-image-injector.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                                          if (e) {
                                                              log.error(e);
                                                              res.json(e);
                                                              res.statusCode = statusCode.INTERNAL_SERVER_ERROR;
                                                              return res.end();
              Severity: Major
              Found in lib/engine/routeinjector/files/file-injector.js - About 45 mins to fix

                Function routeConfigurationCheck has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                function routeConfigurationCheck(config, method) {
                    var routesRestrictions = injector.config.env.restrictions || {};
                    var allowed = true;
                
                    if ((routesRestrictions.blacklist && routesRestrictions.blacklist.routes) || (routesRestrictions.whitelist && routesRestrictions.whitelist.routes)) {
                Severity: Minor
                Found in lib/engine/routeinjector/utils.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 deeply nested control flow statements.
                Open

                                    for (let field of Model.schema.paths[key].options.denormalize)
                                        validFields.push(key + "." + field);
                Severity: Major
                Found in lib/engine/routeinjector/rest/export.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if (i == 0) {
                                              fileName = sourceFileName;
                                          } else {
                                              fileName = addStringBeforeExtension(sourceFileName, '_' + i);
                                          }
                  Severity: Major
                  Found in lib/engine/routeinjector/images/image-injector.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if (value !== undefined) {
                                            _.set(target, f.target, value);
                                        }
                    Severity: Major
                    Found in lib/engine/routeinjector/newdenormalizer.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                                                  if (e) {
                                                                      log.error(e);
                                                                      res.json(e);
                                                                      res.statusCode = statusCode.INTERNAL_SERVER_ERROR;
                                                                      return res.end();
                      Severity: Major
                      Found in lib/engine/routeinjector/images/image-injector.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                                                if (e) {
                                                                                    log.error(e);
                                                                                    res.json(e);
                                                                                    res.statusCode = statusCode.INTERNAL_SERVER_ERROR;
                                                                                    return res.end();
                        Severity: Major
                        Found in lib/engine/routeinjector/images/new-image-injector.js - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                  if (i == 0) {
                                                      fileName = sourceFileName;
                                                  } else {
                                                      fileName = addStringBeforeExtension(sourceFileName, '_' + i);
                                                  }
                          Severity: Major
                          Found in lib/engine/routeinjector/images/new-image-injector.js - About 45 mins to fix

                            Function walkSchema has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            function walkSchema(app, Model, schema, parentName, fromArray, rawPath) {
                            Severity: Minor
                            Found in lib/engine/routeinjector/typeBased.js - About 45 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language