jackmellis/mock-http

View on GitHub

Showing 10 of 10 total issues

Function exports has 192 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function () {
  var Promise = module.exports.config.Promise;

  function findMatchingRequest(request) {
    var method = request.method.toLowerCase(),
Severity: Major
Found in src/index.js - About 7 hrs to fix

    Function exports has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = function () {
      var Promise = module.exports.config.Promise;
    
      function findMatchingRequest(request) {
        var method = request.method.toLowerCase(),
    Severity: Minor
    Found in src/index.js - About 7 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function when has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      http.when = function (method, url) {
        var any = /.*/;
        if (method === undefined && url === undefined){
          method = url = any;
        }else if (url === undefined){
    Severity: Major
    Found in src/index.js - About 2 hrs to fix

      Function http has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function http(url, options){
          if (typeof url === 'string') {
            options = Object.assign({}, options, {url: url});
          } else {
            options = url;
      Severity: Minor
      Found in src/index.js - About 1 hr to fix

        Function findMatchingRequest has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function findMatchingRequest(request) {
            var method = request.method.toLowerCase(),
              url = request.url.toLowerCase(),
              $$when = http.$$when.slice();
        
        
        Severity: Minor
        Found in src/index.js - About 1 hr to fix

          Avoid too many return statements within this function.
          Open

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

            '__dirname' is not defined.
            Open

              entry : path.join(__dirname, '../src/index.js'),
            Severity: Minor
            Found in build/webpack.config.js by eslint

            Disallow Undeclared Variables (no-undef)

            This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

            Rule Details

            Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

            Examples of incorrect code for this rule:

            /*eslint no-undef: "error"*/
            
            var a = someFunction();
            b = 10;

            Examples of correct code for this rule with global declaration:

            /*global someFunction b:true*/
            /*eslint no-undef: "error"*/
            
            var a = someFunction();
            b = 10;

            The b:true syntax in /*global */ indicates that assignment to b is correct.

            Examples of incorrect code for this rule with global declaration:

            /*global b*/
            /*eslint no-undef: "error"*/
            
            b = 10;

            By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

            Options

            • typeof set to true will warn for variables used inside typeof check (Default false).

            typeof

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

            /*eslint no-undef: "error"*/
            
            if (typeof UndefinedIdentifier === "undefined") {
                // do something ...
            }

            You can use this option if you want to prevent typeof check on a variable which has not been declared.

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

            /*eslint no-undef: ["error", { "typeof": true }] */
            
            if(typeof a === "string"){}

            Examples of correct code for the { "typeof": true } option with global declaration:

            /*global a*/
            /*eslint no-undef: ["error", { "typeof": true }] */
            
            if(typeof a === "string"){}

            Environments

            For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

            browser

            Examples of correct code for this rule with browser environment:

            /*eslint no-undef: "error"*/
            /*eslint-env browser*/
            
            setTimeout(function() {
                alert("Hello");
            });

            node

            Examples of correct code for this rule with node environment:

            /*eslint no-undef: "error"*/
            /*eslint-env node*/
            
            var fs = require("fs");
            module.exports = function() {
                console.log(fs);
            };

            When Not To Use It

            If explicit declaration of global variables is not to your taste.

            Compatibility

            This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

            Expected a conditional expression and instead saw an assignment.
            Open

                    if (match = url.match(when.url)){
            Severity: Minor
            Found in src/index.js by eslint

            disallow assignment operators in conditional statements (no-cond-assign)

            In conditional statements, it is very easy to mistype a comparison operator (such as ==) as an assignment operator (such as =). For example:

            // Check the user's job title
            if (user.jobTitle = "manager") {
                // user.jobTitle is now incorrect
            }

            There are valid reasons to use assignment operators in conditional statements. However, it can be difficult to tell whether a specific assignment was intentional.

            Rule Details

            This rule disallows ambiguous assignment operators in test conditions of if, for, while, and do...while statements.

            Options

            This rule has a string option:

            • "except-parens" (default) allows assignments in test conditions only if they are enclosed in parentheses (for example, to allow reassigning a variable in the test of a while or do...while loop)
            • "always" disallows all assignments in test conditions

            except-parens

            Examples of incorrect code for this rule with the default "except-parens" option:

            /*eslint no-cond-assign: "error"*/
            
            // Unintentional assignment
            var x;
            if (x = 0) {
                var b = 1;
            }
            
            // Practical example that is similar to an error
            function setHeight(someNode) {
                "use strict";
                do {
                    someNode.height = "100px";
                } while (someNode = someNode.parentNode);
            }

            Examples of correct code for this rule with the default "except-parens" option:

            /*eslint no-cond-assign: "error"*/
            
            // Assignment replaced by comparison
            var x;
            if (x === 0) {
                var b = 1;
            }
            
            // Practical example that wraps the assignment in parentheses
            function setHeight(someNode) {
                "use strict";
                do {
                    someNode.height = "100px";
                } while ((someNode = someNode.parentNode));
            }
            
            // Practical example that wraps the assignment and tests for 'null'
            function setHeight(someNode) {
                "use strict";
                do {
                    someNode.height = "100px";
                } while ((someNode = someNode.parentNode) !== null);
            }

            always

            Examples of incorrect code for this rule with the "always" option:

            /*eslint no-cond-assign: ["error", "always"]*/
            
            // Unintentional assignment
            var x;
            if (x = 0) {
                var b = 1;
            }
            
            // Practical example that is similar to an error
            function setHeight(someNode) {
                "use strict";
                do {
                    someNode.height = "100px";
                } while (someNode = someNode.parentNode);
            }
            
            // Practical example that wraps the assignment in parentheses
            function setHeight(someNode) {
                "use strict";
                do {
                    someNode.height = "100px";
                } while ((someNode = someNode.parentNode));
            }
            
            // Practical example that wraps the assignment and tests for 'null'
            function setHeight(someNode) {
                "use strict";
                do {
                    someNode.height = "100px";
                } while ((someNode = someNode.parentNode) !== null);
            }

            Examples of correct code for this rule with the "always" option:

            /*eslint no-cond-assign: ["error", "always"]*/
            
            // Assignment replaced by comparison
            var x;
            if (x === 0) {
                var b = 1;
            }

            Related Rules

            '__dirname' is not defined.
            Open

                path : path.join(__dirname, '../dist'),
            Severity: Minor
            Found in build/webpack.config.js by eslint

            Disallow Undeclared Variables (no-undef)

            This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

            Rule Details

            Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

            Examples of incorrect code for this rule:

            /*eslint no-undef: "error"*/
            
            var a = someFunction();
            b = 10;

            Examples of correct code for this rule with global declaration:

            /*global someFunction b:true*/
            /*eslint no-undef: "error"*/
            
            var a = someFunction();
            b = 10;

            The b:true syntax in /*global */ indicates that assignment to b is correct.

            Examples of incorrect code for this rule with global declaration:

            /*global b*/
            /*eslint no-undef: "error"*/
            
            b = 10;

            By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

            Options

            • typeof set to true will warn for variables used inside typeof check (Default false).

            typeof

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

            /*eslint no-undef: "error"*/
            
            if (typeof UndefinedIdentifier === "undefined") {
                // do something ...
            }

            You can use this option if you want to prevent typeof check on a variable which has not been declared.

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

            /*eslint no-undef: ["error", { "typeof": true }] */
            
            if(typeof a === "string"){}

            Examples of correct code for the { "typeof": true } option with global declaration:

            /*global a*/
            /*eslint no-undef: ["error", { "typeof": true }] */
            
            if(typeof a === "string"){}

            Environments

            For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

            browser

            Examples of correct code for this rule with browser environment:

            /*eslint no-undef: "error"*/
            /*eslint-env browser*/
            
            setTimeout(function() {
                alert("Hello");
            });

            node

            Examples of correct code for this rule with node environment:

            /*eslint no-undef: "error"*/
            /*eslint-env node*/
            
            var fs = require("fs");
            module.exports = function() {
                console.log(fs);
            };

            When Not To Use It

            If explicit declaration of global variables is not to your taste.

            Compatibility

            This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

            'Promise' is not defined.
            Open

              Promise : Promise
            Severity: Minor
            Found in src/index.js by eslint

            Disallow Undeclared Variables (no-undef)

            This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

            Rule Details

            Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

            Examples of incorrect code for this rule:

            /*eslint no-undef: "error"*/
            
            var a = someFunction();
            b = 10;

            Examples of correct code for this rule with global declaration:

            /*global someFunction b:true*/
            /*eslint no-undef: "error"*/
            
            var a = someFunction();
            b = 10;

            The b:true syntax in /*global */ indicates that assignment to b is correct.

            Examples of incorrect code for this rule with global declaration:

            /*global b*/
            /*eslint no-undef: "error"*/
            
            b = 10;

            By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

            Options

            • typeof set to true will warn for variables used inside typeof check (Default false).

            typeof

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

            /*eslint no-undef: "error"*/
            
            if (typeof UndefinedIdentifier === "undefined") {
                // do something ...
            }

            You can use this option if you want to prevent typeof check on a variable which has not been declared.

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

            /*eslint no-undef: ["error", { "typeof": true }] */
            
            if(typeof a === "string"){}

            Examples of correct code for the { "typeof": true } option with global declaration:

            /*global a*/
            /*eslint no-undef: ["error", { "typeof": true }] */
            
            if(typeof a === "string"){}

            Environments

            For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

            browser

            Examples of correct code for this rule with browser environment:

            /*eslint no-undef: "error"*/
            /*eslint-env browser*/
            
            setTimeout(function() {
                alert("Hello");
            });

            node

            Examples of correct code for this rule with node environment:

            /*eslint no-undef: "error"*/
            /*eslint-env node*/
            
            var fs = require("fs");
            module.exports = function() {
                console.log(fs);
            };

            When Not To Use It

            If explicit declaration of global variables is not to your taste.

            Compatibility

            This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

            Severity
            Category
            Status
            Source
            Language