maestro-server/analytics-front

View on GitHub
app/core/repositories/daos/connector/query.js

Summary

Maintainability
D
2 days
Test Coverage

Function find has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

Query.prototype.find = function (query, options) {
    let Model = this.model;

    query = _.assign({}, this.query, query);

Severity: Minor
Found in app/core/repositories/daos/connector/query.js - About 2 hrs to fix

    Function where has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    Query.prototype.where = function (key, value) {
        // if object was passed instead of key-value pair
        // iterate over that object and call .where(key, value)
        if (_.isObject(key)) {
            let conditions = key;
    Severity: Minor
    Found in app/core/repositories/daos/connector/query.js - About 45 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

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

    Query.prototype.find = function (query, options) {
        let Model = this.model;
    
        query = _.assign({}, this.query, query);
    
    
    Severity: Minor
    Found in app/core/repositories/daos/connector/query.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

    Unexpected use of undefined.
    Open

            this.options.projection[key] = value === undefined ? 1 : value;

    Disallow Use of undefined Variable (no-undefined)

    The undefined variable is unique in JavaScript because it is actually a property of the global object. As such, in ECMAScript 3 it was possible to overwrite the value of undefined. While ECMAScript 5 disallows overwriting undefined, it's still possible to shadow undefined, such as:

    function doSomething(data) {
        var undefined = "hi";
    
        // doesn't do what you think it does
        if (data === undefined) {
            // ...
        }
    
    }

    This represents a problem for undefined that doesn't exist for null, which is a keyword and primitive value that can neither be overwritten nor shadowed.

    All uninitialized variables automatically get the value of undefined:

    var foo;
    
    console.log(foo === undefined);     // true (assuming no shadowing)

    For this reason, it's not necessary to explicitly initialize a variable to undefined.

    Taking all of this into account, some style guides forbid the use of undefined, recommending instead:

    • Variables that should be undefined are simply left uninitialized.
    • Checking if a value is undefined should be done with typeof.
    • Using the void operator to generate the value of undefined if necessary.

    Rule Details

    This rule aims to eliminate the use of undefined, and as such, generates a warning whenever it is used.

    Examples of incorrect code for this rule:

    /*eslint no-undefined: "error"*/
    
    var foo = undefined;
    
    var undefined = "foo";
    
    if (foo === undefined) {
        // ...
    }
    
    function foo(undefined) {
        // ...
    }

    Examples of correct code for this rule:

    /*eslint no-undefined: "error"*/
    
    var foo = void 0;
    
    var Undefined = "foo";
    
    if (typeof foo === "undefined") {
        // ...
    }
    
    global.undefined = "foo";

    When Not To Use It

    If you want to allow the use of undefined in your code, then you can safely turn this rule off.

    Further Reading

    Related Rules

    Unexpected use of undefined.
    Open

            let hasValue = value !== undefined;

    Disallow Use of undefined Variable (no-undefined)

    The undefined variable is unique in JavaScript because it is actually a property of the global object. As such, in ECMAScript 3 it was possible to overwrite the value of undefined. While ECMAScript 5 disallows overwriting undefined, it's still possible to shadow undefined, such as:

    function doSomething(data) {
        var undefined = "hi";
    
        // doesn't do what you think it does
        if (data === undefined) {
            // ...
        }
    
    }

    This represents a problem for undefined that doesn't exist for null, which is a keyword and primitive value that can neither be overwritten nor shadowed.

    All uninitialized variables automatically get the value of undefined:

    var foo;
    
    console.log(foo === undefined);     // true (assuming no shadowing)

    For this reason, it's not necessary to explicitly initialize a variable to undefined.

    Taking all of this into account, some style guides forbid the use of undefined, recommending instead:

    • Variables that should be undefined are simply left uninitialized.
    • Checking if a value is undefined should be done with typeof.
    • Using the void operator to generate the value of undefined if necessary.

    Rule Details

    This rule aims to eliminate the use of undefined, and as such, generates a warning whenever it is used.

    Examples of incorrect code for this rule:

    /*eslint no-undefined: "error"*/
    
    var foo = undefined;
    
    var undefined = "foo";
    
    if (foo === undefined) {
        // ...
    }
    
    function foo(undefined) {
        // ...
    }

    Examples of correct code for this rule:

    /*eslint no-undefined: "error"*/
    
    var foo = void 0;
    
    var Undefined = "foo";
    
    if (typeof foo === "undefined") {
        // ...
    }
    
    global.undefined = "foo";

    When Not To Use It

    If you want to allow the use of undefined in your code, then you can safely turn this rule off.

    Further Reading

    Related Rules

    Unexpected use of undefined.
    Open

            this.options.projection[key] = value === undefined ? 0 : value;

    Disallow Use of undefined Variable (no-undefined)

    The undefined variable is unique in JavaScript because it is actually a property of the global object. As such, in ECMAScript 3 it was possible to overwrite the value of undefined. While ECMAScript 5 disallows overwriting undefined, it's still possible to shadow undefined, such as:

    function doSomething(data) {
        var undefined = "hi";
    
        // doesn't do what you think it does
        if (data === undefined) {
            // ...
        }
    
    }

    This represents a problem for undefined that doesn't exist for null, which is a keyword and primitive value that can neither be overwritten nor shadowed.

    All uninitialized variables automatically get the value of undefined:

    var foo;
    
    console.log(foo === undefined);     // true (assuming no shadowing)

    For this reason, it's not necessary to explicitly initialize a variable to undefined.

    Taking all of this into account, some style guides forbid the use of undefined, recommending instead:

    • Variables that should be undefined are simply left uninitialized.
    • Checking if a value is undefined should be done with typeof.
    • Using the void operator to generate the value of undefined if necessary.

    Rule Details

    This rule aims to eliminate the use of undefined, and as such, generates a warning whenever it is used.

    Examples of incorrect code for this rule:

    /*eslint no-undefined: "error"*/
    
    var foo = undefined;
    
    var undefined = "foo";
    
    if (foo === undefined) {
        // ...
    }
    
    function foo(undefined) {
        // ...
    }

    Examples of correct code for this rule:

    /*eslint no-undefined: "error"*/
    
    var foo = void 0;
    
    var Undefined = "foo";
    
    if (typeof foo === "undefined") {
        // ...
    }
    
    global.undefined = "foo";

    When Not To Use It

    If you want to allow the use of undefined in your code, then you can safely turn this rule off.

    Further Reading

    Related Rules

    Unexpected use of undefined.
    Open

        this.query[key] = { $exists: (exists === undefined ? true : exists) };

    Disallow Use of undefined Variable (no-undefined)

    The undefined variable is unique in JavaScript because it is actually a property of the global object. As such, in ECMAScript 3 it was possible to overwrite the value of undefined. While ECMAScript 5 disallows overwriting undefined, it's still possible to shadow undefined, such as:

    function doSomething(data) {
        var undefined = "hi";
    
        // doesn't do what you think it does
        if (data === undefined) {
            // ...
        }
    
    }

    This represents a problem for undefined that doesn't exist for null, which is a keyword and primitive value that can neither be overwritten nor shadowed.

    All uninitialized variables automatically get the value of undefined:

    var foo;
    
    console.log(foo === undefined);     // true (assuming no shadowing)

    For this reason, it's not necessary to explicitly initialize a variable to undefined.

    Taking all of this into account, some style guides forbid the use of undefined, recommending instead:

    • Variables that should be undefined are simply left uninitialized.
    • Checking if a value is undefined should be done with typeof.
    • Using the void operator to generate the value of undefined if necessary.

    Rule Details

    This rule aims to eliminate the use of undefined, and as such, generates a warning whenever it is used.

    Examples of incorrect code for this rule:

    /*eslint no-undefined: "error"*/
    
    var foo = undefined;
    
    var undefined = "foo";
    
    if (foo === undefined) {
        // ...
    }
    
    function foo(undefined) {
        // ...
    }

    Examples of correct code for this rule:

    /*eslint no-undefined: "error"*/
    
    var foo = void 0;
    
    var Undefined = "foo";
    
    if (typeof foo === "undefined") {
        // ...
    }
    
    global.undefined = "foo";

    When Not To Use It

    If you want to allow the use of undefined in your code, then you can safely turn this rule off.

    Further Reading

    Related Rules

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

    Query.prototype.exclude = function (key, value) {
    
        if (Array.isArray(key)) {
            let projection = key;
            projection.forEach((k) => this.exclude(k));
    Severity: Major
    Found in app/core/repositories/daos/connector/query.js and 1 other location - About 6 hrs to fix
    app/core/repositories/daos/connector/query.js on lines 64..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 177.

    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

    Query.prototype.include = function (key, value) {
        if (Array.isArray(key)) {
            let projection = key;
            projection.forEach((k) => this.include(k));
    
    
    Severity: Major
    Found in app/core/repositories/daos/connector/query.js and 1 other location - About 6 hrs to fix
    app/core/repositories/daos/connector/query.js on lines 82..99

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

    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