Emapic/emapic

View on GitHub
models/user.js

Summary

Maintainability
D
1 day
Test Coverage

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 exports has a Cognitive Complexity of 18 (exceeds 5 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: Minor
    Found in models/user.js - About 2 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 getAnsweredSurveysWithAllDates has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        User.prototype.getAnsweredSurveysWithAllDates = function() {
            var userId = this.id;
            return Promise.reduce(this.getVotes({
                    include: [
                        {
    Severity: Minor
    Found in models/user.js - About 1 hr to fix

      Function getAnsweredSurveys has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          User.prototype.getAnsweredSurveys = function(query, order, pageSize, pageNr) {
              var userId = this.id,
                  orders;
              if (order === 'answer') {
                  orders = [[sequelize.fn('max', sequelize.col('vote_date')), 'DESC'], [models.Survey, 'id', 'DESC']];
      Severity: Minor
      Found in models/user.js - About 1 hr to fix

        'pageSize' is already defined.
        Open

                    pageSize = (pageSize === null || isNaN(pageSize)) ? defaultPageSize : pageSize;
        Severity: Minor
        Found in models/user.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/

        Missing radix parameter.
        Open

                    if (isNaN(parseInt(results.count))) {
        Severity: Minor
        Found in models/user.js by eslint

        Require Radix Parameter (radix)

        When using the parseInt() function it is common to omit the second argument, the radix, and let the function try to determine from the first argument what type of number it is. By default, parseInt() will autodetect decimal and hexadecimal (via 0x prefix). Prior to ECMAScript 5, parseInt() also autodetected octal literals, which caused problems because many developers assumed a leading 0 would be ignored.

        This confusion led to the suggestion that you always use the radix parameter to parseInt() to eliminate unintended consequences. So instead of doing this:

        var num = parseInt("071");      // 57

        Do this:

        var num = parseInt("071", 10);  // 71

        ECMAScript 5 changed the behavior of parseInt() so that it no longer autodetects octal literals and instead treats them as decimal literals. However, the differences between hexadecimal and decimal interpretation of the first parameter causes many developers to continue using the radix parameter to ensure the string is interpreted in the intended way.

        On the other hand, if the code is targeting only ES5-compliant environments passing the radix 10 may be redundant. In such a case you might want to disallow using such a radix.

        Rule Details

        This rule is aimed at preventing the unintended conversion of a string to a number of a different base than intended or at preventing the redundant 10 radix if targeting modern environments only.

        Options

        There are two options for this rule:

        • "always" enforces providing a radix (default)
        • "as-needed" disallows providing the 10 radix

        always

        Examples of incorrect code for the default "always" option:

        /*eslint radix: "error"*/
        
        var num = parseInt("071");
        
        var num = parseInt(someValue);
        
        var num = parseInt("071", "abc");
        
        var num = parseInt();

        Examples of correct code for the default "always" option:

        /*eslint radix: "error"*/
        
        var num = parseInt("071", 10);
        
        var num = parseInt("071", 8);
        
        var num = parseFloat(someValue);

        as-needed

        Examples of incorrect code for the "as-needed" option:

        /*eslint radix: ["error", "as-needed"]*/
        
        var num = parseInt("071", 10);
        
        var num = parseInt("071", "abc");
        
        var num = parseInt();

        Examples of correct code for the "as-needed" option:

        /*eslint radix: ["error", "as-needed"]*/
        
        var num = parseInt("071");
        
        var num = parseInt("071", 8);
        
        var num = parseFloat(someValue);

        When Not To Use It

        If you don't want to enforce either presence or omission of the 10 radix value you can turn this rule off.

        Further Reading

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

                if (pageSize !== null) {
                    params.limit = pageSize;
                    if (pageNr !== null && !isNaN(pageNr)) {
                        params.offset = (pageNr - 1) * pageSize;
                    }
        Severity: Major
        Found in models/user.js and 1 other location - About 1 hr to fix
        models/survey.js on lines 529..534

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

        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

                    for (var i = 0, iLen = orders.length; i<iLen; i++) {
                        orders[i].unshift(models.Survey);
                    }
        Severity: Minor
        Found in models/user.js and 1 other location - About 55 mins to fix
        models/survey.js on lines 355..357

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

        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