Emapic/emapic

View on GitHub
routes/main.js

Summary

Maintainability
F
6 days
Test Coverage

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 main.js has 356 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

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

      Expected error to be handled.
      Open

              }).catch({ message: 'NULL_USER' }, function(err) {
      Severity: Minor
      Found in routes/main.js by eslint

      Enforce Callback Error Handling (handle-callback-err)

      In Node.js, a common pattern for dealing with asynchronous behavior is called the callback pattern. This pattern expects an Error object or null as the first argument of the callback. Forgetting to handle these errors can lead to some really strange behavior in your application.

      function loadData (err, data) {
          doSomething(); // forgot to handle error
      }

      Rule Details

      This rule expects that when you're using the callback pattern in Node.js you'll handle the error.

      Options

      The rule takes a single string option: the name of the error parameter. The default is "err".

      Examples of incorrect code for this rule with the default "err" parameter name:

      /*eslint handle-callback-err: "error"*/
      
      function loadData (err, data) {
          doSomething();
      }

      Examples of correct code for this rule with the default "err" parameter name:

      /*eslint handle-callback-err: "error"*/
      
      function loadData (err, data) {
          if (err) {
              console.log(err.stack);
          }
          doSomething();
      }
      
      function generateError (err) {
          if (err) {}
      }

      Examples of correct code for this rule with a sample "error" parameter name:

      /*eslint handle-callback-err: ["error", "error"]*/
      
      function loadData (error, data) {
          if (error) {
             console.log(error.stack);
          }
          doSomething();
      }

      regular expression

      Sometimes (especially in big projects) the name of the error variable is not consistent across the project, so you need a more flexible configuration to ensure that the rule reports all unhandled errors.

      If the configured name of the error variable begins with a ^ it is considered to be a regexp pattern.

      • If the option is "^(err|error|anySpecificError)$", the rule reports unhandled errors where the parameter name can be err, error or anySpecificError.
      • If the option is "^.+Error$", the rule reports unhandled errors where the parameter name ends with Error (for example, connectionError or validationError will match).
      • If the option is "^.*(e|E)rr", the rule reports unhandled errors where the parameter name matches any string that contains err or Err (for example, err, error, anyError, some_err will match).

      When Not To Use It

      There are cases where it may be safe for your application to ignore errors, however only ignore errors if you are confident that some other form of monitoring will help you catch the problem.

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

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

          app.get('/login', function(req, res){
              if (req.user) {
                  res.redirect('/dashboard');
              } else {
                  res.render('login', {layout: 'layouts/main'});
      Severity: Major
      Found in routes/main.js and 2 other locations - About 1 hr to fix
      routes/auth/index.js on lines 147..153
      routes/main.js on lines 21..27

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

      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

          app.get('/signup', function(req, res){
              if (req.user) {
                  res.redirect('/dashboard');
              } else {
                  res.render('signup', {layout: 'layouts/main'});
      Severity: Major
      Found in routes/main.js and 2 other locations - About 1 hr to fix
      routes/auth/index.js on lines 147..153
      routes/main.js on lines 13..19

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

      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

              models.Survey.findSurveys(req.user.id, false, null, query, null, order, pageSize, pageNr).then(function(results) {
                  res.render('own-surveys-list', {
                      surveys: results.rows,
                      pagination: Utils.getPaginationHtml(req, pageNr, pageSize, results.count, 'pagination_total_surveys'),
                      query: query,
      Severity: Major
      Found in routes/main.js and 2 other locations - About 1 hr to fix
      routes/main.js on lines 66..73
      routes/main.js on lines 81..88

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

      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

              models.Survey.findPublicSurveys(null, null, null, tag, order, pageSize, pageNr).then(function(results) {
                  res.render('tag-surveys-list', {
                      surveys: results.rows,
                      tag: tag,
                      pagination: Utils.getPaginationHtml(req, pageNr, pageSize, results.count, 'pagination_total_surveys'),
      Severity: Major
      Found in routes/main.js and 1 other location - About 1 hr to fix
      routes/main.js on lines 112..122

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

      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

              models.Survey.findPublicSurveys(null, null, query, null, order, pageSize, pageNr).then(function(results) {
                  res.render('surveys-list', {
                      surveys: results.rows,
                      pagination: Utils.getPaginationHtml(req, pageNr, pageSize, results.count, 'pagination_total_surveys'),
                      query: query,
      Severity: Major
      Found in routes/main.js and 2 other locations - About 1 hr to fix
      routes/main.js on lines 66..73
      routes/main.js on lines 132..139

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

      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

              models.User.findByLogin(userLogin).then(function(usr) {
                  user = usr;
                  return models.Survey.findPublicSurveys(user.id, null, null, null, order, pageSize, pageNr);
              }).then(function(results) {
                  res.render('user-surveys-list', {
      Severity: Major
      Found in routes/main.js and 1 other location - About 1 hr to fix
      routes/main.js on lines 96..103

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

      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

              req.user.getAnsweredSurveys(query, order, pageSize, pageNr).then(function(results) {
                  res.render('answered-surveys-list', {
                      answered: results.rows,
                      pagination: Utils.getPaginationHtml(req, pageNr, pageSize, results.count, 'pagination_total_surveys'),
                      query: query,
      Severity: Major
      Found in routes/main.js and 2 other locations - About 1 hr to fix
      routes/main.js on lines 81..88
      routes/main.js on lines 132..139

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

      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

              req.user.getSurveys({
                  where: {
                      id: Utils.decryptSurveyId(req.params.id)
                  }
              }).then(function(surveys) {
      Severity: Minor
      Found in routes/main.js and 2 other locations - About 35 mins to fix
      routes/main.js on lines 277..291
      routes/main.js on lines 303..314

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

      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

              req.user.getSurveys({
                  where: {
                      id: Utils.decryptSurveyId(req.params.id)
                  }
              }).then(function(surveys) {
      Severity: Minor
      Found in routes/main.js and 2 other locations - About 35 mins to fix
      routes/main.js on lines 256..265
      routes/main.js on lines 277..291

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

      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

              req.user.getSurveys({
                  where: {
                      id: Utils.decryptSurveyId(req.params.id)
                  }
              }).then(function(surveys) {
      Severity: Minor
      Found in routes/main.js and 2 other locations - About 35 mins to fix
      routes/main.js on lines 256..265
      routes/main.js on lines 303..314

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

      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