mysociety/popit-api

View on GitHub

Showing 55 of 97 total issues

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

module.exports = function(app) {

  app.delete('/:collection/:id/image', function (req, res, next) {
    var id = req.params.id;

Severity: Major
Found in src/routes/image.js - About 1 day to fix

    Function elasticsearchPlugin has 188 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function elasticsearchPlugin(schema) {
    
      /**
       * Convert the document into a format suitable for indexing in
       * Elasticsearch. This uses the toJSON transform option to remove
    Severity: Major
    Found in src/mongoose/elasticsearch.js - About 7 hrs to fix

      Function esFilters has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = function esFilters() {
        return {
          esFilter: function esFilter(doc, ret, options) {
            if (!doc) {
              return;
      Severity: Minor
      Found in src/esfilter.js - About 5 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 embedPlugin has 104 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function embedPlugin(schema) {
      
        /**
         * Taked the ?embed parameter and embeds any people, organizations or
         * memberships that have been requested.
      Severity: Major
      Found in src/mongoose/embed.js - About 4 hrs to fix

        Function embedDocuments has 102 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          schema.methods.embedDocuments = function embedDocuments(req, newEmbedNames, callback) {
            if (typeof newEmbedNames === 'function') {
              callback = newEmbedNames;
              newEmbedNames = false;
            }
        Severity: Major
        Found in src/mongoose/embed.js - About 4 hrs to fix

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

          module.exports = function(app) {
          
            app.put('/:collection/:id(*)', validateBody, function (req, res, next) {
          
              var id = req.params.id;
          Severity: Major
          Found in src/routes/1.0/document.put.js - About 3 hrs to fix

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

            module.exports = function(app) {
              // Export all languages - can potentially produce invalid popolo
              app.get('/export.json', function(req, res, next) {
                exporter(req.db, req, function(err, exportObject) {
                  if (err) {
            Severity: Major
            Found in src/routes/export.js - About 2 hrs to fix

              Function esFilters has 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              module.exports = function esFilters() {
                return {
                  esFilter: function esFilter(doc, ret, options) {
                    if (!doc) {
                      return;
              Severity: Major
              Found in src/esfilter.js - About 2 hrs to fix

                Function membershipFinder has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function membershipFinder(schema, options) {
                
                  schema.methods.findMemberships = function findMemberships(callback) {
                    var Membership = this.model('Membership');
                    var modelName = this.constructor.modelName;
                Severity: Major
                Found in src/mongoose/membership-finder.js - About 2 hrs to fix

                  Function setup has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function setup(app, options) {
                    function importPopolo(req, res, next) {
                      var queue = kue.createQueue({
                        prefix: req.options.queuePrefix || 'popit-api-',
                      });
                  Severity: Major
                  Found in src/routes/import.js - About 2 hrs to fix

                    Function processMembership has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function processMembership(membership, req, doc, done) {
                      var existing = false;
                      var Membership = req.db.model(models.memberships.modelName);
                      async.waterfall([
                        function callCheckMembership(cb) {
                    Severity: Minor
                    Found in src/inline-memberships.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 saveImagesMiddleware has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      function saveImagesMiddleware(req, res, next) {
                        function saveImages( doc, image, upload, dest_path, idx ) {
                          var options = {};
                          if ( typeof idx != 'undefined' ) {
                            options = { clobber: true };
                    Severity: Major
                    Found in src/routes/image.js - About 2 hrs to fix

                      Function saveImages has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          function saveImages( doc, image, upload, dest_path, idx ) {
                            var options = {};
                            if ( typeof idx != 'undefined' ) {
                              options = { clobber: true };
                            }
                      Severity: Minor
                      Found in src/routes/image.js - About 1 hr to fix

                        Function toElasticsearch has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        MembershipSchema.methods.toElasticsearch = function(callback) {
                          var Person = this.model('Person');
                          var Organization = this.model('Organization');
                          var Post = this.model('Post');
                          var self = this;
                        Severity: Minor
                        Found in src/models.js - About 1 hr to fix

                          Function processMembership has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function processMembership(membership, req, doc, done) {
                            var existing = false;
                            var Membership = req.db.model(models.memberships.modelName);
                            async.waterfall([
                              function callCheckMembership(cb) {
                          Severity: Minor
                          Found in src/inline-memberships.js - About 1 hr to fix

                            Function jsonSchemaFields has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function jsonSchemaFields(jsonSchema) {
                              var fields = {};
                            
                              for (var name in jsonSchema.properties) {
                                if (jsonSchema.properties.hasOwnProperty(name)) {
                            Severity: Minor
                            Found in src/mongoose/json-schema.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 i18n has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function i18n(objectWithLanguages, langs, defaultLang, includeTranslations) {
                              langs = langs || [];
                              includeTranslations = includeTranslations || false;
                              var obj = {};
                              // Detect keys that need translating
                            Severity: Minor
                            Found in src/i18n.js - About 1 hr to fix

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

                              module.exports = function(app) {
                              
                                /**
                                 * Merge two people together.
                                 *
                              Severity: Minor
                              Found in src/routes/merge.js - About 1 hr to fix

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

                                module.exports = exports = function mergePlugin(schema) {
                                  schema.methods.merge = function merge(other, callback) {
                                    var self = this;
                                    var conflicts = [];
                                    var pathsToMerge = Object.keys(other.toObject());
                                Severity: Minor
                                Found in src/mongoose/merge.js - About 1 hr to fix

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

                                  module.exports = function(app) {
                                  
                                    app.put('/:collection/:id(*)', validateBody, function (req, res, next) {
                                  
                                      var id = req.params.id;
                                  Severity: Minor
                                  Found in src/routes/document.put.js - About 1 hr to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language