Emapic/emapic

View on GitHub

Showing 2,019 of 2,019 total issues

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

                case 'list-radio-other':
                    var otherAns = null;
                    for (var j = 0, jLen = questions[i].Answers.length; j < jLen; j++) {
                        if (questions[i].Answers[j].sortorder === -1) {
                            otherAns = questions[i].Answers[j];
Severity: Major
Found in routes/utils_api.js and 1 other location - About 6 hrs to fix
routes/utils_api.js on lines 87..97

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

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

File utils.js has 422 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// utils.js/
var nodemailer = require('nodemailer'),
    fs = require('fs'),
    nconf = require('nconf'),
    Promise = require('bluebird'),
Severity: Minor
Found in utils.js - About 6 hrs to fix

    Function addResultsXlsxSheet has 144 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function addResultsXlsxSheet(wb, questions, results, i18n) {
            var ws = wb.addWorksheet(i18n.__('export_sheet_answers')),
                headerStyle = wb.createStyle({
                    font: {
                        color: '#000000',
    Severity: Major
    Found in routes/utils_api.js - About 5 hrs to fix

      Function parseQuestionsfromPost has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

      function parseQuestionsfromPost(req, survey) {
          var questions = [];
          for (var i = 1;;i++) {
              if (!((('question_type_' + i) in req.body) && (('question_' + i) in req.body))) {
                  break;
      Severity: Minor
      Found in models/question.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

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

                                  answers.push({
                                      answer : question.Answers[i].answer,
                                      legend : question.Answers[i].legend,
                                      id : question.Answers[i].id,
                                      imageUrl : (question.Answers[i].img !== null && question.Answers[i].img.length > 0) ? '/answer_img/' + question.Answers[i].id : null,
      Severity: Major
      Found in routes/utils_api.js and 1 other location - About 5 hrs to fix
      routes/utils_api.js on lines 934..940

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

      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

                                  otherAnswer = {
                                      answer : question.Answers[i].answer,
                                      legend : question.Answers[i].legend,
                                      id : question.Answers[i].id,
                                      imageUrl : (question.Answers[i].img !== null && question.Answers[i].img.length > 0) ? '/answer_img/' + question.Answers[i].id : null,
      Severity: Major
      Found in routes/utils_api.js and 1 other location - About 5 hrs to fix
      routes/utils_api.js on lines 926..932

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

      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 (user === null) {
                              // If we don't find it either by facebook id or email, we
                              // create a new user.
                              logger.debug("Could not find user in db for Facebook signin: " + profile.id + " / " + profile.emails[0].value);
                              usr = {
      Severity: Major
      Found in routes/auth/index.js and 1 other location - About 4 hrs to fix
      routes/auth/index.js on lines 663..704

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

      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 (user === null) {
                              // If we don't find it either by google id or email, we
                              // create a new user.
                              logger.debug("Could not find user in db for Google signin: " + profile.id + " / " + profile.emails[0].value);
                              usr = {
      Severity: Major
      Found in routes/auth/index.js and 1 other location - About 4 hrs to fix
      routes/auth/index.js on lines 723..768

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

      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 checkValidAnswersFromPost has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

      function checkValidAnswersFromPost(req, questions) {
          var answers = [];
          for (var i = 1, iLen = questions.length; i<=iLen; i++) {
              var question = questions[i-1];
              switch(question.type) {
      Severity: Minor
      Found in models/question.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 main.js has 356 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      var passport = require('passport'),
          Promise = require('bluebird'),
          nconf = require('nconf'),
          fs = require('fs'),
          logger = require('../utils/logger'),
      Severity: Minor
      Found in routes/main.js - About 4 hrs to fix

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

        module.exports = function(app) {
            requireRole = function(roles, json) {
                return function(req, res, next) {
                    delete req.session.lastUnauthPage;
                    var allowedPromise;
        Severity: Major
        Found in routes/auth/utils_auth.js - About 4 hrs to fix

          Function addQuestionStatsXlsxSheet has 110 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function addQuestionStatsXlsxSheet(wb, questions, results, i18n) {
                  var ws = wb.addWorksheet(i18n.__('export_sheet_question_stats')),
                      headerStyle = wb.createStyle({
                          font: {
                              color: '#000000',
          Severity: Major
          Found in routes/utils_api.js - About 4 hrs to fix

            Function has too many statements (51). Maximum allowed is 30.
            Open

            module.exports = function(sequelize, DataTypes) {
            Severity: Minor
            Found in models/survey.js by eslint

            enforce a maximum number of statements allowed in function blocks (max-statements)

            The max-statements rule allows you to specify the maximum number of statements allowed in a function.

            function foo() {
              var bar = 1; // one statement
              var baz = 2; // two statements
              var qux = 3; // three statements
            }

            Rule Details

            This rule enforces a maximum number of statements allowed in function blocks.

            Options

            This rule has a number or object option:

            • "max" (default 10) enforces a maximum number of statements allows in function blocks

            Deprecated: The object property maximum is deprecated; please use the object property max instead.

            This rule has an object option:

            • "ignoreTopLevelFunctions": true ignores top-level functions

            max

            Examples of incorrect code for this rule with the default { "max": 10 } option:

            /*eslint max-statements: ["error", 10]*/
            /*eslint-env es6*/
            
            function foo() {
              var foo1 = 1;
              var foo2 = 2;
              var foo3 = 3;
              var foo4 = 4;
              var foo5 = 5;
              var foo6 = 6;
              var foo7 = 7;
              var foo8 = 8;
              var foo9 = 9;
              var foo10 = 10;
            
              var foo11 = 11; // Too many.
            }
            
            let foo = () => {
              var foo1 = 1;
              var foo2 = 2;
              var foo3 = 3;
              var foo4 = 4;
              var foo5 = 5;
              var foo6 = 6;
              var foo7 = 7;
              var foo8 = 8;
              var foo9 = 9;
              var foo10 = 10;
            
              var foo11 = 11; // Too many.
            };

            Examples of correct code for this rule with the default { "max": 10 } option:

            /*eslint max-statements: ["error", 10]*/
            /*eslint-env es6*/
            
            function foo() {
              var foo1 = 1;
              var foo2 = 2;
              var foo3 = 3;
              var foo4 = 4;
              var foo5 = 5;
              var foo6 = 6;
              var foo7 = 7;
              var foo8 = 8;
              var foo9 = 9;
              var foo10 = 10;
              return function () {
            
                // The number of statements in the inner function does not count toward the
                // statement maximum.
            
                return 42;
              };
            }
            
            let foo = () => {
              var foo1 = 1;
              var foo2 = 2;
              var foo3 = 3;
              var foo4 = 4;
              var foo5 = 5;
              var foo6 = 6;
              var foo7 = 7;
              var foo8 = 8;
              var foo9 = 9;
              var foo10 = 10;
              return function () {
            
                // The number of statements in the inner function does not count toward the
                // statement maximum.
            
                return 42;
              };
            }

            ignoreTopLevelFunctions

            Examples of additional correct code for this rule with the { "max": 10 }, { "ignoreTopLevelFunctions": true } options:

            /*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/
            
            function foo() {
              var foo1 = 1;
              var foo2 = 2;
              var foo3 = 3;
              var foo4 = 4;
              var foo5 = 5;
              var foo6 = 6;
              var foo7 = 7;
              var foo8 = 8;
              var foo9 = 9;
              var foo10 = 10;
              var foo11 = 11;
            }

            Related Rules

            • [complexity](complexity.md)
            • [max-depth](max-depth.md)
            • [max-len](max-len.md)
            • [max-nested-callbacks](max-nested-callbacks.md)
            • [max-params](max-params.md) Source: http://eslint.org/docs/rules/

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

                    return Utils.sendMail({
                        to: user.email,
                        subject: req.i18n.__("signup_notification_mail_subject"),
                        text: req.i18n.__("signup_notification_mail_text_body",
                            user.login, Utils.getApplicationBaseURL() + "/activate?id=" + usrid),
            Severity: Major
            Found in routes/auth/utils_auth.js and 1 other location - About 4 hrs to fix
            routes/auth/utils_auth.js on lines 61..70

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

            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

                    return Utils.sendMail({
                        to: user.email,
                        subject: req.i18n.__("password_reset_confirm_mail_subject"),
                        text: req.i18n.__("password_reset_confirm_mail_text_body",
                            user.login, Utils.getApplicationBaseURL() + "/pwd_reset/confirm?id=" + usrid),
            Severity: Major
            Found in routes/auth/utils_auth.js and 1 other location - About 4 hrs to fix
            routes/auth/utils_auth.js on lines 47..56

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

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

                self.loadSitemapRobots = function() {
                    var sitemap = Sitemap({
                        url: serverConfig.domain,
                        http: 'https',
                        hideByRegex: false,
            Severity: Major
            Found in server.js - About 4 hrs to fix

              Function checkValidResponse has 99 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  Question.prototype.checkValidResponse = function(responses) {
                      var question = this,
                          promise = (typeof this.Answers !== 'undefined') ? Promise.resolve(this.Answers) : this.getAnswers();
                      return promise.then(function(answers) {
                          var answer = null;
              Severity: Major
              Found in models/question.js - About 3 hrs to fix

                Function has too many statements (48). Maximum allowed is 30.
                Open

                module.exports = function(app) {
                Severity: Minor
                Found in routes/auth/index.js by eslint

                enforce a maximum number of statements allowed in function blocks (max-statements)

                The max-statements rule allows you to specify the maximum number of statements allowed in a function.

                function foo() {
                  var bar = 1; // one statement
                  var baz = 2; // two statements
                  var qux = 3; // three statements
                }

                Rule Details

                This rule enforces a maximum number of statements allowed in function blocks.

                Options

                This rule has a number or object option:

                • "max" (default 10) enforces a maximum number of statements allows in function blocks

                Deprecated: The object property maximum is deprecated; please use the object property max instead.

                This rule has an object option:

                • "ignoreTopLevelFunctions": true ignores top-level functions

                max

                Examples of incorrect code for this rule with the default { "max": 10 } option:

                /*eslint max-statements: ["error", 10]*/
                /*eslint-env es6*/
                
                function foo() {
                  var foo1 = 1;
                  var foo2 = 2;
                  var foo3 = 3;
                  var foo4 = 4;
                  var foo5 = 5;
                  var foo6 = 6;
                  var foo7 = 7;
                  var foo8 = 8;
                  var foo9 = 9;
                  var foo10 = 10;
                
                  var foo11 = 11; // Too many.
                }
                
                let foo = () => {
                  var foo1 = 1;
                  var foo2 = 2;
                  var foo3 = 3;
                  var foo4 = 4;
                  var foo5 = 5;
                  var foo6 = 6;
                  var foo7 = 7;
                  var foo8 = 8;
                  var foo9 = 9;
                  var foo10 = 10;
                
                  var foo11 = 11; // Too many.
                };

                Examples of correct code for this rule with the default { "max": 10 } option:

                /*eslint max-statements: ["error", 10]*/
                /*eslint-env es6*/
                
                function foo() {
                  var foo1 = 1;
                  var foo2 = 2;
                  var foo3 = 3;
                  var foo4 = 4;
                  var foo5 = 5;
                  var foo6 = 6;
                  var foo7 = 7;
                  var foo8 = 8;
                  var foo9 = 9;
                  var foo10 = 10;
                  return function () {
                
                    // The number of statements in the inner function does not count toward the
                    // statement maximum.
                
                    return 42;
                  };
                }
                
                let foo = () => {
                  var foo1 = 1;
                  var foo2 = 2;
                  var foo3 = 3;
                  var foo4 = 4;
                  var foo5 = 5;
                  var foo6 = 6;
                  var foo7 = 7;
                  var foo8 = 8;
                  var foo9 = 9;
                  var foo10 = 10;
                  return function () {
                
                    // The number of statements in the inner function does not count toward the
                    // statement maximum.
                
                    return 42;
                  };
                }

                ignoreTopLevelFunctions

                Examples of additional correct code for this rule with the { "max": 10 }, { "ignoreTopLevelFunctions": true } options:

                /*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/
                
                function foo() {
                  var foo1 = 1;
                  var foo2 = 2;
                  var foo3 = 3;
                  var foo4 = 4;
                  var foo5 = 5;
                  var foo6 = 6;
                  var foo7 = 7;
                  var foo8 = 8;
                  var foo9 = 9;
                  var foo10 = 10;
                  var foo11 = 11;
                }

                Related Rules

                • [complexity](complexity.md)
                • [max-depth](max-depth.md)
                • [max-len](max-len.md)
                • [max-nested-callbacks](max-nested-callbacks.md)
                • [max-params](max-params.md) Source: http://eslint.org/docs/rules/

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

                                        return avatarPromise.then(function(avatar) {
                                            usr.avatar = avatar;
                                            return nextLoginUserSignup(usr, 0).then(function(user) {
                                                logger.info("Registered new user from Google data with mail " + user.email + " and id " + user.id);
                                                req.session.success = 'google_signup_success_msg';
                Severity: Major
                Found in routes/auth/index.js and 1 other location - About 3 hrs to fix
                routes/auth/index.js on lines 751..758

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

                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

                                        return avatarPromise.then(function(avatar) {
                                            usr.avatar = avatar;
                                            return nextLoginUserSignup(usr, 0).then(function(user) {
                                                logger.info("Registered new user from Facebook data with mail " + user.email + " and id " + user.id);
                                                req.session.success = 'facebook_signup_success_msg';
                Severity: Major
                Found in routes/auth/index.js and 1 other location - About 3 hrs to fix
                routes/auth/index.js on lines 687..694

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

                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

                Severity
                Category
                Status
                Source
                Language