mysociety/popit-api

View on GitHub

Showing 55 of 97 total issues

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

module.exports = function(app) {

  app.get('/:collection', function (req, res, next) {
    var pagination = paginate(req.query);
    req.collection.find({}, null, pagination, function (err, docs) {
Severity: Minor
Found in src/routes/1.0/collection.get.js - About 1 hr to fix

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

    module.exports = function(app, options) {
      // Pretty print json in production as well as development
      app.set('json spaces', 2);
    
      // Clean up requests from tools like slumber that set the Content-Type but no body
    Severity: Minor
    Found in src/app-setup.js - About 1 hr to fix

      Function hiddenFields has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      function hiddenFields(doc, options) {
        var fields = options.hiddenFields || {};
        var newDoc = {};
        for (var field in doc) {
          // Skip any fields that have been hidden on this doc.
      Severity: Minor
      Found in src/transform.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 addLinks has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function addLinks(doc, options) {
        if (doc.constructor.collection) {
          if (options.apiBaseUrl) {
            doc.set('url', [
              options.apiBaseUrl,
      Severity: Minor
      Found in src/transform.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 exports has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = function(app) {
      
        app.delete('/:collection/:id/image', function (req, res, next) {
          var id = req.params.id;
      
      
      Severity: Minor
      Found in src/routes/image.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 saveImages has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          function saveImages( doc, image, upload, dest_path, idx ) {
      Severity: Minor
      Found in src/routes/image.js - About 35 mins to fix

        Function removeOldMemberships has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        function removeOldMemberships(req, memberships, key, id, done) {
        Severity: Minor
        Found in src/inline-memberships.js - About 35 mins to fix

          Function tidyUpInlineMembershipError has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          function tidyUpInlineMembershipError(req, doc, created, updated, callback) {
          Severity: Minor
          Found in src/inline-memberships.js - About 35 mins to fix

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

            function setImage(doc, options) {
              var images = doc.get('images');
              if (!images || images.length === 0) {
                return doc;
              }
            Severity: Minor
            Found in src/transform.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

            Avoid too many return statements within this function.
            Open

                    return;
            Severity: Major
            Found in src/mongoose/merge.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return;
              Severity: Major
              Found in src/mongoose/merge.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return;
                Severity: Major
                Found in src/mongoose/merge.js - About 30 mins to fix

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

                  function filterDates(doc, options) {
                    if (!options.at) {
                      return doc;
                    }
                  
                  
                  Severity: Minor
                  Found in src/transform.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 toElasticsearch has a Cognitive Complexity of 6 (exceeds 5 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 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 embedPlugin has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function embedPlugin(schema) {
                  
                    /**
                     * Taked the ?embed parameter and embeds any people, organizations or
                     * memberships that have been requested.
                  Severity: Minor
                  Found in src/mongoose/embed.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