thegameofcode/cipherlayer

View on GitHub
src/platforms/salesforce.js

Summary

Maintainability
F
3 days
Test Coverage

Function salesforceCallback has 125 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function salesforceCallback(req, res, next) {
    const sfData = req.user;
    const profile = sfData.profile;

    daoMng.getFromUsername(profile._raw.email, function (err, foundUser) {
Severity: Major
Found in src/platforms/salesforce.js - About 5 hrs to fix

    File salesforce.js has 285 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict';
    
    const log = require('../logger/service');
    const request = require('request');
    const async = require('async');
    Severity: Minor
    Found in src/platforms/salesforce.js - About 2 hrs to fix

      Function renewSFAccessTokenIfNecessary has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function renewSFAccessTokenIfNecessary(user, platform, cbk) {
          const maxTimeTillRenewal = (new Date().getTime() + config.salesforce.renewWhenLessThan * 60 * 1000);
          if (platform.expiry > maxTimeTillRenewal) {
              return cbk(null, platform.accessToken.params.access_token);
          }
      Severity: Minor
      Found in src/platforms/salesforce.js - About 1 hr to fix

        Function prepareSession has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function prepareSession(accessToken, refreshToken, profile, done) {
            log.info(`user ${profile.id} logged in using salesforce`);
            async.series([
                    function uploadAvatar(done) {
                        if (!profile._raw || !profile._raw.photos || !profile._raw.photos.picture || !config.aws || !config.aws.buckets || !config.aws.buckets.avatars) {
        Severity: Minor
        Found in src/platforms/salesforce.js - About 1 hr to fix

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

          function prepareSession(accessToken, refreshToken, profile, done) {
              log.info(`user ${profile.id} logged in using salesforce`);
              async.series([
                      function uploadAvatar(done) {
                          if (!profile._raw || !profile._raw.photos || !profile._raw.photos.picture || !config.aws || !config.aws.buckets || !config.aws.buckets.avatars) {
          Severity: Minor
          Found in src/platforms/salesforce.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

          Consider simplifying this complex logical expression.
          Open

                          if (!profile._raw || !profile._raw.photos || !profile._raw.photos.picture || !config.aws || !config.aws.buckets || !config.aws.buckets.avatars) {
                              return done();
                          }
          Severity: Major
          Found in src/platforms/salesforce.js - About 40 mins to fix

            'err' is already declared in the upper scope.
            Open

                    daoMng.updateArrayItem(user._id, 'platforms', 'platform', newSFplatformItem, function (err) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            'done' is already declared in the upper scope.
            Open

                        function uploadAvatar(done) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            'next' is already declared in the upper scope.
            Open

                                        async.eachSeries(realms, function (realm, next) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            'err' is already declared in the upper scope.
            Open

                                tokenMng.createBothTokens(foundUser._id, data, function (err, tokens) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            Expected to return a value at the end of function.
            Open

                request(optionsForSFRenew, function (err, res, rawBody) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            require return statements to either always or never specify values (consistent-return)

            Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

            A confusing aspect of JavaScript is that a function returns undefined if any of the following are true:

            • it does not execute a return statement before it exits
            • it executes return which does not specify a value explicitly
            • it executes return undefined
            • it executes return void followed by an expression (for example, a function call)
            • it executes return followed by any other expression which evaluates to undefined

            If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

            • a code path through the function returns a Boolean value true
            • another code path does not return a value explicitly, therefore returns undefined implicitly
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }

            Rule Details

            This rule requires return statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new operator) return the instantiated object implicitly if they do not return another object explicitly.

            Examples of incorrect code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                }
            }

            Examples of correct code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return false;
                }
            }
            
            function Foo() {
                if (!(this instanceof Foo)) {
                    return new Foo();
                }
            
                this.a = 0;
            }

            Options

            This rule has an object option:

            • "treatUndefinedAsUnspecified": false (default) always either specify values or return undefined implicitly only.
            • "treatUndefinedAsUnspecified": true always either specify values or return undefined explicitly or implicitly.

            treatUndefinedAsUnspecified

            Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                return true;
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                return true;
            }

            Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            When Not To Use It

            If you want to allow functions to have different return behavior depending on code branching, then it is safe to disable this rule. Source: http://eslint.org/docs/rules/

            'err' is already declared in the upper scope.
            Open

                            tokenMng.createAccessToken(profile.id, tokenData, function (err, token) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            Expected to return a value at the end of function.
            Open

                                countries.countryFromPhone(profile._raw.mobile_phone, function (err, country) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            require return statements to either always or never specify values (consistent-return)

            Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

            A confusing aspect of JavaScript is that a function returns undefined if any of the following are true:

            • it does not execute a return statement before it exits
            • it executes return which does not specify a value explicitly
            • it executes return undefined
            • it executes return void followed by an expression (for example, a function call)
            • it executes return followed by any other expression which evaluates to undefined

            If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

            • a code path through the function returns a Boolean value true
            • another code path does not return a value explicitly, therefore returns undefined implicitly
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }

            Rule Details

            This rule requires return statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new operator) return the instantiated object implicitly if they do not return another object explicitly.

            Examples of incorrect code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                }
            }

            Examples of correct code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return false;
                }
            }
            
            function Foo() {
                if (!(this instanceof Foo)) {
                    return new Foo();
                }
            
                this.a = 0;
            }

            Options

            This rule has an object option:

            • "treatUndefinedAsUnspecified": false (default) always either specify values or return undefined implicitly only.
            • "treatUndefinedAsUnspecified": true always either specify values or return undefined explicitly or implicitly.

            treatUndefinedAsUnspecified

            Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                return true;
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                return true;
            }

            Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            When Not To Use It

            If you want to allow functions to have different return behavior depending on code branching, then it is safe to disable this rule. Source: http://eslint.org/docs/rules/

            'err' is already declared in the upper scope.
            Open

                        userMng.setPlatformData(foundUser._id, 'sf', platform, function (err) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            Expected to return a value at the end of function 'renewSFAccessTokenIfNecessary'.
            Open

            function renewSFAccessTokenIfNecessary(user, platform, cbk) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            require return statements to either always or never specify values (consistent-return)

            Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

            A confusing aspect of JavaScript is that a function returns undefined if any of the following are true:

            • it does not execute a return statement before it exits
            • it executes return which does not specify a value explicitly
            • it executes return undefined
            • it executes return void followed by an expression (for example, a function call)
            • it executes return followed by any other expression which evaluates to undefined

            If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

            • a code path through the function returns a Boolean value true
            • another code path does not return a value explicitly, therefore returns undefined implicitly
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }

            Rule Details

            This rule requires return statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new operator) return the instantiated object implicitly if they do not return another object explicitly.

            Examples of incorrect code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                }
            }

            Examples of correct code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return false;
                }
            }
            
            function Foo() {
                if (!(this instanceof Foo)) {
                    return new Foo();
                }
            
                this.a = 0;
            }

            Options

            This rule has an object option:

            • "treatUndefinedAsUnspecified": false (default) always either specify values or return undefined implicitly only.
            • "treatUndefinedAsUnspecified": true always either specify values or return undefined explicitly or implicitly.

            treatUndefinedAsUnspecified

            Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                return true;
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                return true;
            }

            Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            When Not To Use It

            If you want to allow functions to have different return behavior depending on code branching, then it is safe to disable this rule. Source: http://eslint.org/docs/rules/

            'err' is already declared in the upper scope.
            Open

                                    daoMng.getRealms(function (err, realms) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            Expected to return a value at the end of function.
            Open

                                            async.eachSeries(realm.allowedDomains, function (domain, more) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            require return statements to either always or never specify values (consistent-return)

            Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

            A confusing aspect of JavaScript is that a function returns undefined if any of the following are true:

            • it does not execute a return statement before it exits
            • it executes return which does not specify a value explicitly
            • it executes return undefined
            • it executes return void followed by an expression (for example, a function call)
            • it executes return followed by any other expression which evaluates to undefined

            If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

            • a code path through the function returns a Boolean value true
            • another code path does not return a value explicitly, therefore returns undefined implicitly
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }

            Rule Details

            This rule requires return statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new operator) return the instantiated object implicitly if they do not return another object explicitly.

            Examples of incorrect code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                }
            }

            Examples of correct code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return false;
                }
            }
            
            function Foo() {
                if (!(this instanceof Foo)) {
                    return new Foo();
                }
            
                this.a = 0;
            }

            Options

            This rule has an object option:

            • "treatUndefinedAsUnspecified": false (default) always either specify values or return undefined implicitly only.
            • "treatUndefinedAsUnspecified": true always either specify values or return undefined explicitly or implicitly.

            treatUndefinedAsUnspecified

            Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                return true;
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                return true;
            }

            Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            When Not To Use It

            If you want to allow functions to have different return behavior depending on code branching, then it is safe to disable this rule. Source: http://eslint.org/docs/rules/

            Expected to return a value at the end of function.
            Open

                                        async.eachSeries(realms, function (realm, next) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            require return statements to either always or never specify values (consistent-return)

            Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

            A confusing aspect of JavaScript is that a function returns undefined if any of the following are true:

            • it does not execute a return statement before it exits
            • it executes return which does not specify a value explicitly
            • it executes return undefined
            • it executes return void followed by an expression (for example, a function call)
            • it executes return followed by any other expression which evaluates to undefined

            If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

            • a code path through the function returns a Boolean value true
            • another code path does not return a value explicitly, therefore returns undefined implicitly
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }

            Rule Details

            This rule requires return statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new operator) return the instantiated object implicitly if they do not return another object explicitly.

            Examples of incorrect code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                }
            }

            Examples of correct code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return false;
                }
            }
            
            function Foo() {
                if (!(this instanceof Foo)) {
                    return new Foo();
                }
            
                this.a = 0;
            }

            Options

            This rule has an object option:

            • "treatUndefinedAsUnspecified": false (default) always either specify values or return undefined implicitly only.
            • "treatUndefinedAsUnspecified": true always either specify values or return undefined explicitly or implicitly.

            treatUndefinedAsUnspecified

            Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                return true;
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                return true;
            }

            Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            When Not To Use It

            If you want to allow functions to have different return behavior depending on code branching, then it is safe to disable this rule. Source: http://eslint.org/docs/rules/

            Expected to return a value at the end of function 'uploadAvatar'.
            Open

                        function uploadAvatar(done) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            require return statements to either always or never specify values (consistent-return)

            Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

            A confusing aspect of JavaScript is that a function returns undefined if any of the following are true:

            • it does not execute a return statement before it exits
            • it executes return which does not specify a value explicitly
            • it executes return undefined
            • it executes return void followed by an expression (for example, a function call)
            • it executes return followed by any other expression which evaluates to undefined

            If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

            • a code path through the function returns a Boolean value true
            • another code path does not return a value explicitly, therefore returns undefined implicitly
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }

            Rule Details

            This rule requires return statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new operator) return the instantiated object implicitly if they do not return another object explicitly.

            Examples of incorrect code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                }
            }

            Examples of correct code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return false;
                }
            }
            
            function Foo() {
                if (!(this instanceof Foo)) {
                    return new Foo();
                }
            
                this.a = 0;
            }

            Options

            This rule has an object option:

            • "treatUndefinedAsUnspecified": false (default) always either specify values or return undefined implicitly only.
            • "treatUndefinedAsUnspecified": true always either specify values or return undefined explicitly or implicitly.

            treatUndefinedAsUnspecified

            Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                return true;
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                return true;
            }

            Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            When Not To Use It

            If you want to allow functions to have different return behavior depending on code branching, then it is safe to disable this rule. Source: http://eslint.org/docs/rules/

            Expected to return a value at the end of function.
            Open

                            tokenMng.createAccessToken(profile.id, tokenData, function (err, token) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            require return statements to either always or never specify values (consistent-return)

            Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

            A confusing aspect of JavaScript is that a function returns undefined if any of the following are true:

            • it does not execute a return statement before it exits
            • it executes return which does not specify a value explicitly
            • it executes return undefined
            • it executes return void followed by an expression (for example, a function call)
            • it executes return followed by any other expression which evaluates to undefined

            If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

            • a code path through the function returns a Boolean value true
            • another code path does not return a value explicitly, therefore returns undefined implicitly
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }

            Rule Details

            This rule requires return statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new operator) return the instantiated object implicitly if they do not return another object explicitly.

            Examples of incorrect code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                }
            }

            Examples of correct code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return false;
                }
            }
            
            function Foo() {
                if (!(this instanceof Foo)) {
                    return new Foo();
                }
            
                this.a = 0;
            }

            Options

            This rule has an object option:

            • "treatUndefinedAsUnspecified": false (default) always either specify values or return undefined implicitly only.
            • "treatUndefinedAsUnspecified": true always either specify values or return undefined explicitly or implicitly.

            treatUndefinedAsUnspecified

            Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                return true;
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                return true;
            }

            Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            When Not To Use It

            If you want to allow functions to have different return behavior depending on code branching, then it is safe to disable this rule. Source: http://eslint.org/docs/rules/

            Expected to return a value at the end of function.
            Open

                                    daoMng.getRealms(function (err, realms) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            require return statements to either always or never specify values (consistent-return)

            Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

            A confusing aspect of JavaScript is that a function returns undefined if any of the following are true:

            • it does not execute a return statement before it exits
            • it executes return which does not specify a value explicitly
            • it executes return undefined
            • it executes return void followed by an expression (for example, a function call)
            • it executes return followed by any other expression which evaluates to undefined

            If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

            • a code path through the function returns a Boolean value true
            • another code path does not return a value explicitly, therefore returns undefined implicitly
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }

            Rule Details

            This rule requires return statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the new operator) return the instantiated object implicitly if they do not return another object explicitly.

            Examples of incorrect code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return;
                }
            }
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                }
            }

            Examples of correct code for this rule:

            /*eslint consistent-return: "error"*/
            
            function doSomething(condition) {
                if (condition) {
                    return true;
                } else {
                    return false;
                }
            }
            
            function Foo() {
                if (!(this instanceof Foo)) {
                    return new Foo();
                }
            
                this.a = 0;
            }

            Options

            This rule has an object option:

            • "treatUndefinedAsUnspecified": false (default) always either specify values or return undefined implicitly only.
            • "treatUndefinedAsUnspecified": true always either specify values or return undefined explicitly or implicitly.

            treatUndefinedAsUnspecified

            Examples of incorrect code for this rule with the default { "treatUndefinedAsUnspecified": false } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            Examples of incorrect code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                return true;
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                return true;
            }

            Examples of correct code for this rule with the { "treatUndefinedAsUnspecified": true } option:

            /*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/
            
            function foo(callback) {
                if (callback) {
                    return void callback();
                }
                // no return statement
            }
            
            function bar(condition) {
                if (condition) {
                    return undefined;
                }
                // no return statement
            }

            When Not To Use It

            If you want to allow functions to have different return behavior depending on code branching, then it is safe to disable this rule. Source: http://eslint.org/docs/rules/

            'err' is already declared in the upper scope.
            Open

                                countries.countryFromPhone(profile._raw.mobile_phone, function (err, country) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            'done' is already declared in the upper scope.
            Open

                        function returnSessionData(done) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            'err' is already declared in the upper scope.
            Open

                                    getUserOptionalInfo(sfData, profile._raw.user_id, function (err, profileDetail) {
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            disallow variable declarations from shadowing variables declared in the outer scope (no-shadow)

            Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. For example:

            var a = 3;
            function b() {
                var a = 10;
            }

            In this case, the variable a inside of b() is shadowing the variable a in the global scope. This can cause confusion while reading the code and it's impossible to access the global variable.

            Rule Details

            This rule aims to eliminate shadowed variable declarations.

            Examples of incorrect code for this rule:

            /*eslint no-shadow: "error"*/
            /*eslint-env es6*/
            
            var a = 3;
            function b() {
                var a = 10;
            }
            
            var b = function () {
                var a = 10;
            }
            
            function b(a) {
                a = 10;
            }
            b(a);
            
            if (true) {
                let a = 5;
            }

            Options

            This rule takes one option, an object, with properties "builtinGlobals", "hoist" and "allow".

            {
                "no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
            }

            builtinGlobals

            The builtinGlobals option is false by default. If it is true, the rule prevents shadowing of built-in global variables: Object, Array, Number, and so on.

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

            /*eslint no-shadow: ["error", { "builtinGlobals": true }]*/
            
            function foo() {
                var Object = 0;
            }

            hoist

            The hoist option has three settings:

            • functions (by default) - reports shadowing before the outer functions are defined.
            • all - reports all shadowing before the outer variables/functions are defined.
            • never - never report shadowing before the outer variables/functions are defined.

            hoist: functions

            Examples of incorrect code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let b = 6;
            }
            
            function b() {}

            Although let b in the if statement is before the function declaration in the outer scope, it is incorrect.

            Examples of correct code for the default { "hoist": "functions" } option:

            /*eslint no-shadow: ["error", { "hoist": "functions" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
            }
            
            let a = 5;

            Because let a in the if statement is before the variable declaration in the outer scope, it is correct.

            hoist: all

            Examples of incorrect code for the { "hoist": "all" } option:

            /*eslint no-shadow: ["error", { "hoist": "all" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            hoist: never

            Examples of correct code for the { "hoist": "never" } option:

            /*eslint no-shadow: ["error", { "hoist": "never" }]*/
            /*eslint-env es6*/
            
            if (true) {
                let a = 3;
                let b = 6;
            }
            
            let a = 5;
            function b() {}

            Because let a and let b in the if statement are before the declarations in the outer scope, they are correct.

            allow

            The allow option is an array of identifier names for which shadowing is allowed. For example, "resolve", "reject", "done", "cb".

            Examples of correct code for the { "allow": ["done"] } option:

            /*eslint no-shadow: ["error", { "allow": ["done"] }]*/
            /*eslint-env es6*/
            
            import async from 'async';
            
            function foo(done) {
              async.map([1, 2], function (e, done) {
                done(null, e * 2)
              }, done);
            }
            
            foo(function (err, result) {
              console.log({ err, result });
            });

            Further Reading

            Related Rules

            TODO found
            Open

                            return next(true); // TODO: return error
            Severity: Minor
            Found in src/platforms/salesforce.js by fixme

            TODO found
            Open

                return next(true); // TODO: return error
            Severity: Minor
            Found in src/platforms/salesforce.js by fixme

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

                            async.series([
                                function (done) {
                                    //Add "realms" & "capabilities"
                                    daoMng.getRealms(function (err, realms) {
                                        if (err) {
            Severity: Major
            Found in src/platforms/salesforce.js and 2 other locations - About 2 days to fix
            src/routes_public/auth/login_post.js on lines 47..89
            src/routes_public/auth/renew_post.js on lines 61..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 381.

            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

            Definition for rule 'extra-rules/potential-point-free' was not found
            Open

            'use strict';
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            For more information visit Source: http://eslint.org/docs/rules/

            Definition for rule 'extra-rules/no-for-loops' was not found
            Open

            'use strict';
            Severity: Minor
            Found in src/platforms/salesforce.js by eslint

            For more information visit Source: http://eslint.org/docs/rules/

            There are no issues that match your filters.

            Category
            Status