Emapic/emapic

View on GitHub
models/question.js

Summary

Maintainability
F
2 wks
Test Coverage

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

module.exports = function(sequelize, DataTypes) {
    var Question = sequelize.define('Question', {
        id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true },
        type: { type: DataTypes.STRING, allowNull: false, defaultValue: 'text' },
        title: { type: DataTypes.STRING, allowNull: false, defaultValue: '' },
Severity: Major
Found in models/question.js - About 1 day to fix

    File question.js has 679 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    var fs = require('fs'),
        path = require('path'),
        escape = require('escape-html'),
        Promise = require('bluebird'),
        linkifyHtml = require('linkifyjs/html'),
    Severity: Major
    Found in models/question.js - About 1 day to fix

      Function parseAnswersFromPost has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
      Open

      function parseAnswersFromPost(req, questions, oldAnswers) {
          var answers = [];
          oldAnswers = oldAnswers || null;
          for (var i = 1, iLen = questions.length; i<=iLen; i++) {
              var question = questions[i-1];
      Severity: Minor
      Found in models/question.js - About 1 day 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 42 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = function(sequelize, DataTypes) {
          var Question = sequelize.define('Question', {
              id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true },
              type: { type: DataTypes.STRING, allowNull: false, defaultValue: 'text' },
              title: { type: DataTypes.STRING, allowNull: false, defaultValue: '' },
      Severity: Minor
      Found in models/question.js - About 6 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 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

      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

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

        function generateExclusiveBtnAnswerHtml(answer, layout, question) {
            var btnClass,
                divClass,
                btnContent,
                style = '';
        Severity: Major
        Found in models/question.js - About 2 hrs to fix

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

              Question.prototype.getHtml = function(req) {
                  var parent = this,
                      html = '';
                  switch (parent.type) {
                      case 'list-radio':
          Severity: Major
          Found in models/question.js - About 2 hrs to fix

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

                    return promise.then(function(answers) {
            Severity: Minor
            Found in models/question.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/

            Function parseQuestionsfromPost has 58 lines of code (exceeds 25 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: Major
            Found in models/question.js - About 2 hrs to fix

              Function parseAnswersFromPost has 55 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function parseAnswersFromPost(req, questions, oldAnswers) {
                  var answers = [];
                  oldAnswers = oldAnswers || null;
                  for (var i = 1, iLen = questions.length; i<=iLen; i++) {
                      var question = questions[i-1];
              Severity: Major
              Found in models/question.js - About 2 hrs to fix

                Function checkValidAnswersFromPost has 43 lines of code (exceeds 25 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 1 hr to fix

                  Function generateExclusiveBtnAnswerHtml has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function generateExclusiveBtnAnswerHtml(answer, layout, question) {
                      var btnClass,
                          divClass,
                          btnContent,
                          style = '';
                  Severity: Minor
                  Found in models/question.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 getInsertSql has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      Question.prototype.getInsertSql = function(responses) {
                          var respField = 'q' + this.question_order + '.id';
                          switch (this.type) {
                              case 'list-radio-other':
                                  if (respField in responses &&
                  Severity: Minor
                  Found in models/question.js - About 1 hr to fix

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

                        Question.prototype.getPostInsertOperations = function(responses, answerId) {
                            var respField = 'q' + this.question_order + '.id',
                                question = this,
                                survey = this.Survey;
                            switch (this.type) {
                    Severity: Minor
                    Found in models/question.js - About 1 hr to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if (!(('option_' + i + '_other') in req.body) || req.body['option_' + i + '_other'].trim() === '') {
                                                  break;
                                              }
                      Severity: Major
                      Found in models/question.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if (answerImg === null && oldAnswers !== null) {
                                                    // If not and we have old answers, we recycle the image previously used for this answer
                                                    if (!isNaN(req.body['id_' + i + '_' + j])) {
                                                        var originalId = parseInt(req.body['id_' + i + '_' + j], 10);
                                                        images:
                        Severity: Major
                        Found in models/question.js - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                                  if (answers[i].sortorder === -1) {
                                                                      otherAnswer = answers[i];
                                                                      continue;
                                                                  }
                          Severity: Major
                          Found in models/question.js - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                    if (!(Utils.isImage(fs.readFileSync(req.files['img_' + i + '_' + j].path)))) {
                                                        return Promise.reject({
                                                            message: "invalid image for question nr " + i + " answer nr " + j + ": selected file is not an image.",
                                                            code: 'answer_img_invalid'
                                                        });
                            Severity: Major
                            Found in models/question.js - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                      if (!(('option_' + i + '_other') in req.body) || req.body['option_' + i + '_other'].trim() === '') {
                                                          break;
                                                      }
                              Severity: Major
                              Found in models/question.js - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                        if (req.files['img_' + i + '_' + j].size > 2000000) {
                                                            return Promise.reject({
                                                                message: "invalid image for question nr " + i + " answer nr " + j + ": image file exceeds the 2MB max size.",
                                                                code: 'answer_img_too_big'
                                                            });
                                Severity: Major
                                Found in models/question.js - About 45 mins to fix

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

                                  function generateTextInputQuestionHtml(question, validator, maxLength, placeholderText, req) {
                                  Severity: Minor
                                  Found in models/question.js - About 35 mins to fix

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

                                    function generateTextAreaQuestionHtml(question, validator, maxLength, placeholderText, req) {
                                    Severity: Minor
                                    Found in models/question.js - About 35 mins to fix

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

                                      function generateTextInputQuestionHtml(question, validator, maxLength, placeholderText, req) {
                                          var opt = req.i18n.__('optional_note'),
                                              max = req.i18n.__('max_length_note'),
                                              validator = validator || null,
                                              mandatory = question.mandatory;
                                      Severity: Minor
                                      Found in models/question.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 Promise.reject({
                                                                          message: "invalid answer for question nr " + question.question_order + " : selected file is not an image.",
                                                                          status: 400,
                                                                          code: 'invalid_request'
                                                                      });
                                      Severity: Major
                                      Found in models/question.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                                    return Promise.resolve();
                                        Severity: Major
                                        Found in models/question.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                                  return Promise.resolve();
                                          Severity: Major
                                          Found in models/question.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                                            return Promise.reject({
                                                                                message: "invalid answer for question nr " + question.question_order + " : image file exceeds the 10MB max size.",
                                                                                status: 400,
                                                                                code: 'invalid_request'
                                                                            });
                                            Severity: Major
                                            Found in models/question.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                                      return Utils.checkUrlIsImage(responses['q' + question.question_order + '.value']);
                                              Severity: Major
                                              Found in models/question.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                            return Promise.reject({
                                                                message: "invalid answer for question nr " + question.question_order + " : " + answer,
                                                                status: 400,
                                                                code: 'invalid_request'
                                                            });
                                                Severity: Major
                                                Found in models/question.js - About 30 mins to fix

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

                                                  function generateTextAreaQuestionHtml(question, validator, maxLength, placeholderText, req) {
                                                      var opt = req.i18n.__('optional_note'),
                                                          max = req.i18n.__('max_length_note'),
                                                          validator = validator || null,
                                                          mandatory = question.mandatory;
                                                  Severity: Minor
                                                  Found in models/question.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

                                                  'validator' is already defined.
                                                  Open

                                                          validator = validator || null,
                                                  Severity: Minor
                                                  Found in models/question.js by eslint

                                                  disallow variable redeclaration (no-redeclare)

                                                  In JavaScript, it's possible to redeclare the same variable name using var. This can lead to confusion as to where the variable is actually declared and initialized.

                                                  Rule Details

                                                  This rule is aimed at eliminating variables that have multiple declarations in the same scope.

                                                  Examples of incorrect code for this rule:

                                                  /*eslint no-redeclare: "error"*/
                                                  
                                                  var a = 3;
                                                  var a = 10;

                                                  Examples of correct code for this rule:

                                                  /*eslint no-redeclare: "error"*/
                                                  
                                                  var a = 3;
                                                  // ...
                                                  a = 10;

                                                  Options

                                                  This rule takes one optional argument, an object with a boolean property "builtinGlobals". It defaults to false. If set to true, this rule also checks redeclaration of built-in globals, such as Object, Array, Number...

                                                  builtinGlobals

                                                  Examples of incorrect code for the { "builtinGlobals": true } option:

                                                  /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
                                                  
                                                  var Object = 0;

                                                  Examples of incorrect code for the { "builtinGlobals": true } option and the browser environment:

                                                  /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
                                                  /*eslint-env browser*/
                                                  
                                                  var top = 0;

                                                  The browser environment has many built-in global variables (for example, top). Some of built-in global variables cannot be redeclared. Source: http://eslint.org/docs/rules/

                                                  Expected a 'break' statement before 'case'.
                                                  Open

                                                              case 'list-radio-other':
                                                  Severity: Minor
                                                  Found in models/question.js by eslint

                                                  Disallow Case Statement Fallthrough (no-fallthrough)

                                                  The switch statement in JavaScript is one of the more error-prone constructs of the language thanks in part to the ability to "fall through" from one case to the next. For example:

                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                  
                                                      case 2:
                                                          doSomethingElse();
                                                  }

                                                  In this example, if foo is 1, then execution will flow through both cases, as the first falls through to the second. You can prevent this by using break, as in this example:

                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          break;
                                                  
                                                      case 2:
                                                          doSomethingElse();
                                                  }

                                                  That works fine when you don't want a fallthrough, but what if the fallthrough is intentional, there is no way to indicate that in the language. It's considered a best practice to always indicate when a fallthrough is intentional using a comment which matches the /falls?\s?through/i regular expression:

                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          // falls through
                                                  
                                                      case 2:
                                                          doSomethingElse();
                                                  }
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          // fall through
                                                  
                                                      case 2:
                                                          doSomethingElse();
                                                  }
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          // fallsthrough
                                                  
                                                      case 2:
                                                          doSomethingElse();
                                                  }

                                                  In this example, there is no confusion as to the expected behavior. It is clear that the first case is meant to fall through to the second case.

                                                  Rule Details

                                                  This rule is aimed at eliminating unintentional fallthrough of one case to the other. As such, it flags any fallthrough scenarios that are not marked by a comment.

                                                  Examples of incorrect code for this rule:

                                                  /*eslint no-fallthrough: "error"*/
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                  
                                                      case 2:
                                                          doSomething();
                                                  }

                                                  Examples of correct code for this rule:

                                                  /*eslint no-fallthrough: "error"*/
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          break;
                                                  
                                                      case 2:
                                                          doSomething();
                                                  }
                                                  
                                                  function bar(foo) {
                                                      switch(foo) {
                                                          case 1:
                                                              doSomething();
                                                              return;
                                                  
                                                          case 2:
                                                              doSomething();
                                                      }
                                                  }
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          throw new Error("Boo!");
                                                  
                                                      case 2:
                                                          doSomething();
                                                  }
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                      case 2:
                                                          doSomething();
                                                  }
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          // falls through
                                                  
                                                      case 2:
                                                          doSomething();
                                                  }

                                                  Note that the last case statement in these examples does not cause a warning because there is nothing to fall through into.

                                                  Options

                                                  This rule accepts a single options argument:

                                                  • Set the commentPattern option to a regular expression string to change the test for intentional fallthrough comment

                                                  commentPattern

                                                  Examples of correct code for the { "commentPattern": "break[\\s\\w]*omitted" } option:

                                                  /*eslint no-fallthrough: ["error", { "commentPattern": "break[\\s\\w]*omitted" }]*/
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          // break omitted
                                                  
                                                      case 2:
                                                          doSomething();
                                                  }
                                                  
                                                  switch(foo) {
                                                      case 1:
                                                          doSomething();
                                                          // caution: break is omitted intentionally
                                                  
                                                      default:
                                                          doSomething();
                                                  }

                                                  When Not To Use It

                                                  If you don't want to enforce that each case statement should end with a throw, return, break, or comment, then you can safely turn this rule off.

                                                  Related Rules

                                                  Unexpected string concatenation of literals.
                                                  Open

                                                          '"' + ' id="q' + question.question_order + '-input" target="#q' + question.question_order +
                                                  Severity: Minor
                                                  Found in models/question.js by eslint

                                                  Disallow unnecessary concatenation of strings (no-useless-concat)

                                                  It's unnecessary to concatenate two strings together, such as:

                                                  var foo = "a" + "b";

                                                  This code is likely the result of refactoring where a variable was removed from the concatenation (such as "a" + b + "b"). In such a case, the concatenation isn't important and the code can be rewritten as:

                                                  var foo = "ab";

                                                  Rule Details

                                                  This rule aims to flag the concatenation of 2 literals when they could be combined into a single literal. Literals can be strings or template literals.

                                                  Examples of incorrect code for this rule:

                                                  /*eslint no-useless-concat: "error"*/
                                                  /*eslint-env es6*/
                                                  
                                                  // these are the same as "10"
                                                  var a = `some` + `string`;
                                                  var a = '1' + '0';
                                                  var a = '1' + `0`;
                                                  var a = `1` + '0';
                                                  var a = `1` + `0`;

                                                  Examples of correct code for this rule:

                                                  /*eslint no-useless-concat: "error"*/
                                                  
                                                  // when a non string is included
                                                  var c = a + b;
                                                  var c = '1' + a;
                                                  var a = 1 + '1';
                                                  var c = 1 - 2;
                                                  // when the string concatenation is multiline
                                                  var c = "foo" +
                                                      "bar";

                                                  When Not To Use It

                                                  If you don't want to be notified about unnecessary string concatenation, you can safely disable this rule. Source: http://eslint.org/docs/rules/

                                                  'validator' is already defined.
                                                  Open

                                                          validator = validator || null,
                                                  Severity: Minor
                                                  Found in models/question.js by eslint

                                                  disallow variable redeclaration (no-redeclare)

                                                  In JavaScript, it's possible to redeclare the same variable name using var. This can lead to confusion as to where the variable is actually declared and initialized.

                                                  Rule Details

                                                  This rule is aimed at eliminating variables that have multiple declarations in the same scope.

                                                  Examples of incorrect code for this rule:

                                                  /*eslint no-redeclare: "error"*/
                                                  
                                                  var a = 3;
                                                  var a = 10;

                                                  Examples of correct code for this rule:

                                                  /*eslint no-redeclare: "error"*/
                                                  
                                                  var a = 3;
                                                  // ...
                                                  a = 10;

                                                  Options

                                                  This rule takes one optional argument, an object with a boolean property "builtinGlobals". It defaults to false. If set to true, this rule also checks redeclaration of built-in globals, such as Object, Array, Number...

                                                  builtinGlobals

                                                  Examples of incorrect code for the { "builtinGlobals": true } option:

                                                  /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
                                                  
                                                  var Object = 0;

                                                  Examples of incorrect code for the { "builtinGlobals": true } option and the browser environment:

                                                  /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
                                                  /*eslint-env browser*/
                                                  
                                                  var top = 0;

                                                  The browser environment has many built-in global variables (for example, top). Some of built-in global variables cannot be redeclared. Source: http://eslint.org/docs/rules/

                                                  Unreachable code.
                                                  Open

                                                                  break;
                                                  Severity: Minor
                                                  Found in models/question.js by eslint

                                                  disallow unreachable code after return, throw, continue, and break statements (no-unreachable)

                                                  Because the return, throw, break, and continue statements unconditionally exit a block of code, any statements after them cannot be executed. Unreachable statements are usually a mistake.

                                                  function fn() {
                                                      x = 1;
                                                      return x;
                                                      x = 3; // this will never execute
                                                  }

                                                  Rule Details

                                                  This rule disallows unreachable code after return, throw, continue, and break statements.

                                                  Examples of incorrect code for this rule:

                                                  /*eslint no-unreachable: "error"*/
                                                  
                                                  function foo() {
                                                      return true;
                                                      console.log("done");
                                                  }
                                                  
                                                  function bar() {
                                                      throw new Error("Oops!");
                                                      console.log("done");
                                                  }
                                                  
                                                  while(value) {
                                                      break;
                                                      console.log("done");
                                                  }
                                                  
                                                  throw new Error("Oops!");
                                                  console.log("done");
                                                  
                                                  function baz() {
                                                      if (Math.random() < 0.5) {
                                                          return;
                                                      } else {
                                                          throw new Error();
                                                      }
                                                      console.log("done");
                                                  }
                                                  
                                                  for (;;) {}
                                                  console.log("done");

                                                  Examples of correct code for this rule, because of JavaScript function and variable hoisting:

                                                  /*eslint no-unreachable: "error"*/
                                                  
                                                  function foo() {
                                                      return bar();
                                                      function bar() {
                                                          return 1;
                                                      }
                                                  }
                                                  
                                                  function bar() {
                                                      return x;
                                                      var x;
                                                  }
                                                  
                                                  switch (foo) {
                                                      case 1:
                                                          break;
                                                          var x;
                                                  }

                                                  Source: http://eslint.org/docs/rules/

                                                  'validator' is already defined.
                                                  Open

                                                          validator = validator || null,
                                                  Severity: Minor
                                                  Found in models/question.js by eslint

                                                  disallow variable redeclaration (no-redeclare)

                                                  In JavaScript, it's possible to redeclare the same variable name using var. This can lead to confusion as to where the variable is actually declared and initialized.

                                                  Rule Details

                                                  This rule is aimed at eliminating variables that have multiple declarations in the same scope.

                                                  Examples of incorrect code for this rule:

                                                  /*eslint no-redeclare: "error"*/
                                                  
                                                  var a = 3;
                                                  var a = 10;

                                                  Examples of correct code for this rule:

                                                  /*eslint no-redeclare: "error"*/
                                                  
                                                  var a = 3;
                                                  // ...
                                                  a = 10;

                                                  Options

                                                  This rule takes one optional argument, an object with a boolean property "builtinGlobals". It defaults to false. If set to true, this rule also checks redeclaration of built-in globals, such as Object, Array, Number...

                                                  builtinGlobals

                                                  Examples of incorrect code for the { "builtinGlobals": true } option:

                                                  /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
                                                  
                                                  var Object = 0;

                                                  Examples of incorrect code for the { "builtinGlobals": true } option and the browser environment:

                                                  /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
                                                  /*eslint-env browser*/
                                                  
                                                  var top = 0;

                                                  The browser environment has many built-in global variables (for example, top). Some of built-in global variables cannot be redeclared. Source: http://eslint.org/docs/rules/

                                                  Unexpected string concatenation of literals.
                                                  Open

                                                          fileSizeText + '</div></div>' + '<button id="q' + question.question_order + '-ok" autocomplete="off" ' +
                                                  Severity: Minor
                                                  Found in models/question.js by eslint

                                                  Disallow unnecessary concatenation of strings (no-useless-concat)

                                                  It's unnecessary to concatenate two strings together, such as:

                                                  var foo = "a" + "b";

                                                  This code is likely the result of refactoring where a variable was removed from the concatenation (such as "a" + b + "b"). In such a case, the concatenation isn't important and the code can be rewritten as:

                                                  var foo = "ab";

                                                  Rule Details

                                                  This rule aims to flag the concatenation of 2 literals when they could be combined into a single literal. Literals can be strings or template literals.

                                                  Examples of incorrect code for this rule:

                                                  /*eslint no-useless-concat: "error"*/
                                                  /*eslint-env es6*/
                                                  
                                                  // these are the same as "10"
                                                  var a = `some` + `string`;
                                                  var a = '1' + '0';
                                                  var a = '1' + `0`;
                                                  var a = `1` + '0';
                                                  var a = `1` + `0`;

                                                  Examples of correct code for this rule:

                                                  /*eslint no-useless-concat: "error"*/
                                                  
                                                  // when a non string is included
                                                  var c = a + b;
                                                  var c = '1' + a;
                                                  var a = 1 + '1';
                                                  var c = 1 - 2;
                                                  // when the string concatenation is multiline
                                                  var c = "foo" +
                                                      "bar";

                                                  When Not To Use It

                                                  If you don't want to be notified about unnecessary string concatenation, you can safely disable this rule. Source: http://eslint.org/docs/rules/

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

                                                  function generateTextAreaQuestionHtml(question, validator, maxLength, placeholderText, req) {
                                                      var opt = req.i18n.__('optional_note'),
                                                          max = req.i18n.__('max_length_note'),
                                                          validator = validator || null,
                                                          mandatory = question.mandatory;
                                                  Severity: Major
                                                  Found in models/question.js and 1 other location - About 1 day to fix
                                                  models/question.js on lines 271..287

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

                                                  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

                                                  function generateTextInputQuestionHtml(question, validator, maxLength, placeholderText, req) {
                                                      var opt = req.i18n.__('optional_note'),
                                                          max = req.i18n.__('max_length_note'),
                                                          validator = validator || null,
                                                          mandatory = question.mandatory;
                                                  Severity: Major
                                                  Found in models/question.js and 1 other location - About 1 day to fix
                                                  models/question.js on lines 289..305

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

                                                  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 (responses['q' + question.question_order + '.value']) {
                                                                                  responses['q' + question.question_order + '.value'] = responses['q' + question.question_order + '.value'].trim();
                                                                              }
                                                  Severity: Major
                                                  Found in models/question.js and 1 other location - About 1 hr to fix
                                                  models/question.js on lines 503..505

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

                                                  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 (responses['q' + question.question_order + '.value']) {
                                                                              responses['q' + question.question_order + '.value'] = responses['q' + question.question_order + '.value'].trim();
                                                                          }
                                                  Severity: Major
                                                  Found in models/question.js and 1 other location - About 1 hr to fix
                                                  models/question.js on lines 478..480

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

                                                  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 (!(('option_' + i + '_' + j) in req.body) || req.body['option_' + i + '_' + j].trim() === '') {
                                                                          if (!(('option_' + i + '_other') in req.body) || req.body['option_' + i + '_other'].trim() === '') {
                                                                              break;
                                                                          }
                                                                          j = 'other';
                                                  Severity: Major
                                                  Found in models/question.js and 1 other location - About 1 hr to fix
                                                  models/question.js on lines 84..89

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

                                                  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 (!(('option_' + i + '_' + j) in req.body) || req.body['option_' + i + '_' + j].trim() === '') {
                                                                          if (!(('option_' + i + '_other') in req.body) || req.body['option_' + i + '_other'].trim() === '') {
                                                                              break;
                                                                          }
                                                                          j = 'other';
                                                  Severity: Major
                                                  Found in models/question.js and 1 other location - About 1 hr to fix
                                                  models/question.js on lines 135..140

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

                                                  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 answersPromise.then(function(answers) {
                                                              return Promise.map(answers, function(answer) {
                                                                  return answer.getFullDescription();
                                                              });
                                                          }).then(function(answersDesc) {
                                                  Severity: Major
                                                  Found in models/question.js and 1 other location - About 1 hr to fix
                                                  models/survey.js on lines 1108..1121

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

                                                  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

                                                          var description = this.getDescription(),
                                                              answersPromise = typeof this.Answers !== 'undefined' ?
                                                                  Promise.resolve(this.Answers) : this.getAnswers();
                                                  Severity: Minor
                                                  Found in models/question.js and 1 other location - About 55 mins to fix
                                                  models/survey.js on lines 1105..1107

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

                                                  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 3 locations. Consider refactoring.
                                                  Open

                                                              for (var j = 0, jLen = oldQuestions.length; j<jLen; j++) {
                                                                  oldAnswers.push(oldQuestions[j].Answers);
                                                              }
                                                  Severity: Major
                                                  Found in models/question.js and 2 other locations - About 50 mins to fix
                                                  models/survey.js on lines 888..890
                                                  routes/api-engine_routes.js on lines 103..105

                                                  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

                                                  There are no issues that match your filters.

                                                  Category
                                                  Status