r2js/r2query

View on GitHub

Showing 7 of 7 total issues

Function run has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
Open

const run = (query = {}, model, options = {}) => (
  new Promise((resolve, reject) => {
    let Model = model;
    const { sort, skip = 0, fields, populate } = options;
    const { qName } = query;
Severity: Minor
Found in index.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 run has 86 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  new Promise((resolve, reject) => {
    let Model = model;
    const { sort, skip = 0, fields, populate } = options;
    const { qName } = query;
    let { qType = 'all' } = query;
Severity: Major
Found in index.js - About 3 hrs to fix

    Avoid too many return statements within this function.
    Open

          return resolve(qModel.exec ? qModel.exec() : qModel);
    Severity: Major
    Found in index.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          return true;
      Severity: Major
      Found in index.js - About 30 mins to fix

        Assignment to property of function parameter 'query'.
        Open

              delete query.qType;
        Severity: Minor
        Found in index.js by eslint

        Disallow Reassignment of Function Parameters (no-param-reassign)

        Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

        This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

        Rule Details

        This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

        Examples of incorrect code for this rule:

        /*eslint no-param-reassign: "error"*/
        
        function foo(bar) {
            bar = 13;
        }
        
        function foo(bar) {
            bar++;
        }

        Examples of correct code for this rule:

        /*eslint no-param-reassign: "error"*/
        
        function foo(bar) {
            var baz = bar;
        }

        Options

        This rule takes one option, an object, with a boolean property "props" and an array "ignorePropertyModificationsFor". "props" is false by default. If "props" is set to true, this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor", which is an empty array by default.

        props

        Examples of correct code for the default { "props": false } option:

        /*eslint no-param-reassign: ["error", { "props": false }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

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

        /*eslint no-param-reassign: ["error", { "props": true }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

        /*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["bar"] }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        When Not To Use It

        If you want to allow assignment to function parameters, then you can safely disable this rule.

        Further Reading

        Assignment to property of function parameter 'query'.
        Open

              delete query.qName;
        Severity: Minor
        Found in index.js by eslint

        Disallow Reassignment of Function Parameters (no-param-reassign)

        Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

        This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

        Rule Details

        This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

        Examples of incorrect code for this rule:

        /*eslint no-param-reassign: "error"*/
        
        function foo(bar) {
            bar = 13;
        }
        
        function foo(bar) {
            bar++;
        }

        Examples of correct code for this rule:

        /*eslint no-param-reassign: "error"*/
        
        function foo(bar) {
            var baz = bar;
        }

        Options

        This rule takes one option, an object, with a boolean property "props" and an array "ignorePropertyModificationsFor". "props" is false by default. If "props" is set to true, this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor", which is an empty array by default.

        props

        Examples of correct code for the default { "props": false } option:

        /*eslint no-param-reassign: ["error", { "props": false }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

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

        /*eslint no-param-reassign: ["error", { "props": true }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

        /*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["bar"] }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        When Not To Use It

        If you want to allow assignment to function parameters, then you can safely disable this rule.

        Further Reading

        Assignment to property of function parameter 'query'.
        Open

                delete query.childOpts;
        Severity: Minor
        Found in index.js by eslint

        Disallow Reassignment of Function Parameters (no-param-reassign)

        Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

        This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

        Rule Details

        This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

        Examples of incorrect code for this rule:

        /*eslint no-param-reassign: "error"*/
        
        function foo(bar) {
            bar = 13;
        }
        
        function foo(bar) {
            bar++;
        }

        Examples of correct code for this rule:

        /*eslint no-param-reassign: "error"*/
        
        function foo(bar) {
            var baz = bar;
        }

        Options

        This rule takes one option, an object, with a boolean property "props" and an array "ignorePropertyModificationsFor". "props" is false by default. If "props" is set to true, this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor", which is an empty array by default.

        props

        Examples of correct code for the default { "props": false } option:

        /*eslint no-param-reassign: ["error", { "props": false }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

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

        /*eslint no-param-reassign: ["error", { "props": true }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

        /*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["bar"] }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        When Not To Use It

        If you want to allow assignment to function parameters, then you can safely disable this rule.

        Further Reading

        Severity
        Category
        Status
        Source
        Language