Emapic/emapic

View on GitHub

Showing 2,019 of 2,019 total issues

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

    app.get('/api/survey/:surveyId/legend', function(req, res) {
        models.Survey.scope('includeAuthor').findByPk(Utils.decryptSurveyId(req.params.surveyId)).then(function(survey) {
            if (survey === null) {
                return res.status(404).json({ error_code: 'invalid_resource', error: 'requested survey doesn\'t exist.' });
            }
Severity: Major
Found in routes/api-engine_routes.js and 2 other locations - About 1 day to fix
routes/api-engine_routes.js on lines 167..187
routes/api-engine_routes.js on lines 246..266

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

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

module.exports = function(app) {

    app.get('/login', function(req, res){
        if (req.user) {
            res.redirect('/dashboard');
Severity: Major
Found in routes/main.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 exports has 292 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      module.exports = function(app) {
          Utils = {
              encryptSurveyId: function(id) {
                  return (id) ? bases.toBase(id * surveyIdEncr.factor, surveyIdEncr.base ) : null;
              },
      Severity: Major
      Found in utils.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

        File api-engine_routes.js has 585 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        var fs = require('fs'),
            Promise = require('bluebird'),
            bases = require('bases'),
            RateLimit = require('express-rate-limit'),
            logger = require('../utils/logger'),
        Severity: Major
        Found in routes/api-engine_routes.js - About 1 day to fix

          Function initializeServer has 221 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              self.initializeServer = function() {
          
                  self.app = express();
          
                  utils(self.app);
          Severity: Major
          Found in server.js - About 1 day to fix

            Function EmapicApp has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
            Open

            var EmapicApp = function() {
            
                //  Scope.
                var self = this,
                    serverConfig,
            Severity: Minor
            Found in server.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 'addLocationStatsXlsxSheet' has too many statements (86). Maximum allowed is 30.
            Open

                function addLocationStatsXlsxSheet(wb, results, i18n) {
            Severity: Minor
            Found in routes/utils_api.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 exports has 179 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = function(app) {
                FileHelper = {
            
                    saveFileFromBuffer: function(buffer, dstPath, fileName, defaultMime) {
                        var cleanDstPath = dstPath;
            Severity: Major
            Found in utils/file_helper.js - About 7 hrs to fix

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

                          return sequelize.query('SELECT a.gid id, a.codigo AS adm_code, a.' + municipalityName + ' AS name, a.cod_prov, a.provincia, a.cod_ccaa, ' +
                              'a.comautonom, b.adm1_code as province_adm_code, lower(b.iso_a2) AS country_iso_code, a.province_gid province_id ' +
                              'FROM base_layers.municipalities a JOIN base_layers.provinces b ON a.province_gid = b.gid ' +
                              'WHERE st_intersects(a.geom, st_setsrid(st_makepoint(:lon, :lat), 4326)) LIMIT 1', {
                              replacements: {
              Severity: Major
              Found in routes/api-engine_routes.js and 1 other location - About 6 hrs to fix
              routes/api-engine_routes.js on lines 605..648

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

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

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

                File server.js has 440 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                require('exit-on-epipe');
                
                var express = require('express'),
                    session = require('express-session'),
                    FileStore = require('session-file-store')(session),
                Severity: Minor
                Found in server.js - About 6 hrs to fix

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

                          var query = req.query.q && req.query.q.trim() !== '' ? req.query.q : null,
                              order = req.query.order && req.query.order.trim() !== '' ? req.query.order : null,
                              pageNr = isNaN(req.query.page) ? 1 : req.query.page,
                              pageSize = isNaN(req.query.size) ? defaultPageSize : req.query.size;
                  Severity: Major
                  Found in routes/main.js and 2 other locations - About 6 hrs to fix
                  routes/main.js on lines 62..65
                  routes/main.js on lines 128..131

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

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

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

                          var query = req.query.q && req.query.q.trim() !== '' ? req.query.q : null,
                              order = req.query.order && req.query.order.trim() !== '' ? req.query.order : null,
                              pageNr = isNaN(req.query.page) ? 1 : req.query.page,
                              pageSize = isNaN(req.query.size) ? defaultPageSize : req.query.size;
                  Severity: Major
                  Found in routes/main.js and 2 other locations - About 6 hrs to fix
                  routes/main.js on lines 62..65
                  routes/main.js on lines 77..80

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

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

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

                          var query = req.query.q && req.query.q.trim() !== '' ? req.query.q : null,
                              order = req.query.order && req.query.order.trim() !== '' ? req.query.order : null,
                              pageNr = isNaN(req.query.page) ? 1 : req.query.page,
                              pageSize = isNaN(req.query.size) ? defaultPageSize : req.query.size;
                  Severity: Major
                  Found in routes/main.js and 2 other locations - About 6 hrs to fix
                  routes/main.js on lines 77..80
                  routes/main.js on lines 128..131

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

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

                  module.exports = function(sequelize, DataTypes) {
                      var User = sequelize.define('User', {
                          id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true },
                          email: { type: DataTypes.STRING, unique: true, allowNull: false },
                          login: { type: DataTypes.STRING, allowNull: false },
                  Severity: Major
                  Found in models/user.js - About 6 hrs to fix

                    Function getFiltersSQL has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function getFiltersSQL(getFilters, questions) {
                        var sqls = [],
                            params = {};
                        if (getFilters) {
                            for (var param in getFilters) {
                    Severity: Minor
                    Found in models/survey.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

                    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 675..685

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language