reactioncommerce/redoc

View on GitHub
packages/search-source/lib/client.js

Summary

Maintainability
B
6 hrs
Test Coverage

Function _loadData has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

SearchSource.prototype._loadData = function (query, options) {
  const self = this;
  let version = 0;
  const historyKey = query + EJSON.stringify(options);
  if (this._canUseHistory(historyKey)) {
Severity: Minor
Found in packages/search-source/lib/client.js - About 2 hrs to fix

Cognitive Complexity

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

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

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

Further reading

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

SearchSource.prototype._loadData = function (query, options) {
  const self = this;
  let version = 0;
  const historyKey = query + EJSON.stringify(options);
  if (this._canUseHistory(historyKey)) {
Severity: Minor
Found in packages/search-source/lib/client.js - About 1 hr to fix

    Function getData has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    SearchSource.prototype.getData = function (options, getCursor) {
      options = options || {};
      const self = this;
      this._storeDep.depend();
      let selector = {$or: []};
    Severity: Minor
    Found in packages/search-source/lib/client.js - About 1 hr to fix

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

      SearchSource.prototype.getData = function (options, getCursor) {
        options = options || {};
        const self = this;
        this._storeDep.depend();
        let selector = {$or: []};
      Severity: Minor
      Found in packages/search-source/lib/client.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

      Expected '===' and instead saw '=='.
      Open

            if (version == self._currentVersion) {
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      Require === and !== (eqeqeq)

      It is considered good practice to use the type-safe equality operators === and !== instead of their regular counterparts == and !=.

      The reason for this is that == and != do type coercion which follows the rather obscure Abstract Equality Comparison Algorithm. For instance, the following statements are all considered true:

      • [] == false
      • [] == ![]
      • 3 == "03"

      If one of those occurs in an innocent-looking statement such as a == b the actual problem is very difficult to spot.

      Rule Details

      This rule is aimed at eliminating the type-unsafe equality operators.

      Examples of incorrect code for this rule:

      /*eslint eqeqeq: "error"*/
      
      if (x == 42) { }
      
      if ("" == text) { }
      
      if (obj.getStuff() != undefined) { }

      The --fix option on the command line automatically fixes some problems reported by this rule. A problem is only fixed if one of the operands is a typeof expression, or if both operands are literals with the same type.

      Options

      always

      The "always" option (default) enforces the use of === and !== in every situation (except when you opt-in to more specific handling of null [see below]).

      Examples of incorrect code for the "always" option:

      /*eslint eqeqeq: ["error", "always"]*/
      
      a == b
      foo == true
      bananas != 1
      value == undefined
      typeof foo == 'undefined'
      'hello' != 'world'
      0 == 0
      true == true
      foo == null

      Examples of correct code for the "always" option:

      /*eslint eqeqeq: ["error", "always"]*/
      
      a === b
      foo === true
      bananas !== 1
      value === undefined
      typeof foo === 'undefined'
      'hello' !== 'world'
      0 === 0
      true === true
      foo === null

      This rule optionally takes a second argument, which should be an object with the following supported properties:

      • "null": Customize how this rule treats null literals. Possible values:
        • always (default) - Always use === or !==.
        • never - Never use === or !== with null.
        • ignore - Do not apply this rule to null.

      smart

      The "smart" option enforces the use of === and !== except for these cases:

      • Comparing two literal values
      • Evaluating the value of typeof
      • Comparing against null

      Examples of incorrect code for the "smart" option:

      /*eslint eqeqeq: ["error", "smart"]*/
      
      // comparing two variables requires ===
      a == b
      
      // only one side is a literal
      foo == true
      bananas != 1
      
      // comparing to undefined requires ===
      value == undefined

      Examples of correct code for the "smart" option:

      /*eslint eqeqeq: ["error", "smart"]*/
      
      typeof foo == 'undefined'
      'hello' != 'world'
      0 == 0
      true == true
      foo == null

      allow-null

      Deprecated: Instead of using this option use "always" and pass a "null" option property with value "ignore". This will tell eslint to always enforce strict equality except when comparing with the null literal.

      ["error", "always", {"null": "ignore"}]

      When Not To Use It

      If you don't want to enforce a style for using equality operators, then it's safe to disable this rule. Source: http://eslint.org/docs/rules/

      'data' is already defined.
      Open

              var data = payload.data;
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      disallow variable redeclaration (no-redeclare)

      In JavaScript, it's possible to redeclare the same variable name using var. This can lead to confusion as to where the variable is actually declared and initialized.

      Rule Details

      This rule is aimed at eliminating variables that have multiple declarations in the same scope.

      Examples of incorrect code for this rule:

      /*eslint no-redeclare: "error"*/
      
      var a = 3;
      var a = 10;

      Examples of correct code for this rule:

      /*eslint no-redeclare: "error"*/
      
      var a = 3;
      // ...
      a = 10;

      Options

      This rule takes one optional argument, an object with a boolean property "builtinGlobals". It defaults to false. If set to true, this rule also checks redeclaration of built-in globals, such as Object, Array, Number...

      builtinGlobals

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

      /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
      
      var Object = 0;

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

      /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
      /*eslint-env browser*/
      
      var top = 0;

      The browser environment has many built-in global variables (for example, top). Some of built-in global variables cannot be redeclared. Source: http://eslint.org/docs/rules/

      Assignment to function parameter 'options'.
      Open

        options = options || {};
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

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

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

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

      Rule Details

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

      Examples of incorrect code for this rule:

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

      Examples of correct code for this rule:

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

      Options

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

      props

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

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

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

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

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

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

      When Not To Use It

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

      Further Reading

      Assignment to function parameter 'query'.
      Open

        query = query || "";
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

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

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

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

      Rule Details

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

      Examples of incorrect code for this rule:

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

      Examples of correct code for this rule:

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

      Options

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

      props

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

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

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

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

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

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

      When Not To Use It

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

      Further Reading

      Expected '===' and instead saw '=='.
      Open

        if (typeof this.fetchData == "function") {
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      Require === and !== (eqeqeq)

      It is considered good practice to use the type-safe equality operators === and !== instead of their regular counterparts == and !=.

      The reason for this is that == and != do type coercion which follows the rather obscure Abstract Equality Comparison Algorithm. For instance, the following statements are all considered true:

      • [] == false
      • [] == ![]
      • 3 == "03"

      If one of those occurs in an innocent-looking statement such as a == b the actual problem is very difficult to spot.

      Rule Details

      This rule is aimed at eliminating the type-unsafe equality operators.

      Examples of incorrect code for this rule:

      /*eslint eqeqeq: "error"*/
      
      if (x == 42) { }
      
      if ("" == text) { }
      
      if (obj.getStuff() != undefined) { }

      The --fix option on the command line automatically fixes some problems reported by this rule. A problem is only fixed if one of the operands is a typeof expression, or if both operands are literals with the same type.

      Options

      always

      The "always" option (default) enforces the use of === and !== in every situation (except when you opt-in to more specific handling of null [see below]).

      Examples of incorrect code for the "always" option:

      /*eslint eqeqeq: ["error", "always"]*/
      
      a == b
      foo == true
      bananas != 1
      value == undefined
      typeof foo == 'undefined'
      'hello' != 'world'
      0 == 0
      true == true
      foo == null

      Examples of correct code for the "always" option:

      /*eslint eqeqeq: ["error", "always"]*/
      
      a === b
      foo === true
      bananas !== 1
      value === undefined
      typeof foo === 'undefined'
      'hello' !== 'world'
      0 === 0
      true === true
      foo === null

      This rule optionally takes a second argument, which should be an object with the following supported properties:

      • "null": Customize how this rule treats null literals. Possible values:
        • always (default) - Always use === or !==.
        • never - Never use === or !== with null.
        • ignore - Do not apply this rule to null.

      smart

      The "smart" option enforces the use of === and !== except for these cases:

      • Comparing two literal values
      • Evaluating the value of typeof
      • Comparing against null

      Examples of incorrect code for the "smart" option:

      /*eslint eqeqeq: ["error", "smart"]*/
      
      // comparing two variables requires ===
      a == b
      
      // only one side is a literal
      foo == true
      bananas != 1
      
      // comparing to undefined requires ===
      value == undefined

      Examples of correct code for the "smart" option:

      /*eslint eqeqeq: ["error", "smart"]*/
      
      typeof foo == 'undefined'
      'hello' != 'world'
      0 == 0
      true == true
      foo == null

      allow-null

      Deprecated: Instead of using this option use "always" and pass a "null" option property with value "ignore". This will tell eslint to always enforce strict equality except when comparing with the null literal.

      ["error", "always", {"null": "ignore"}]

      When Not To Use It

      If you don't want to enforce a style for using equality operators, then it's safe to disable this rule. Source: http://eslint.org/docs/rules/

      'metadata' is already defined.
      Open

              var metadata = payload.metadata;
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      disallow variable redeclaration (no-redeclare)

      In JavaScript, it's possible to redeclare the same variable name using var. This can lead to confusion as to where the variable is actually declared and initialized.

      Rule Details

      This rule is aimed at eliminating variables that have multiple declarations in the same scope.

      Examples of incorrect code for this rule:

      /*eslint no-redeclare: "error"*/
      
      var a = 3;
      var a = 10;

      Examples of correct code for this rule:

      /*eslint no-redeclare: "error"*/
      
      var a = 3;
      // ...
      a = 10;

      Options

      This rule takes one optional argument, an object with a boolean property "builtinGlobals". It defaults to false. If set to true, this rule also checks redeclaration of built-in globals, such as Object, Array, Number...

      builtinGlobals

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

      /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
      
      var Object = 0;

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

      /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
      /*eslint-env browser*/
      
      var top = 0;

      The browser environment has many built-in global variables (for example, top). Some of built-in global variables cannot be redeclared. Source: http://eslint.org/docs/rules/

      Unexpected var, use let or const instead.
      Open

              var metadata = payload.metadata;
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      require let or const instead of var (no-var)

      ECMAScript 6 allows programmers to create variables with block scope instead of function scope using the let and const keywords. Block scope is common in many other programming languages and helps programmers avoid mistakes such as:

      var count = people.length;
      var enoughFood = count > sandwiches.length;
      
      if (enoughFood) {
          var count = sandwiches.length; // accidentally overriding the count variable
          console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
      }
      
      // our count variable is no longer accurate
      console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");

      Rule Details

      This rule is aimed at discouraging the use of var and encouraging the use of const or let instead.

      Examples

      Examples of incorrect code for this rule:

      /*eslint no-var: "error"*/
      
      var x = "y";
      var CONFIG = {};

      Examples of correct code for this rule:

      /*eslint no-var: "error"*/
      /*eslint-env es6*/
      
      let x = "y";
      const CONFIG = {};

      When Not To Use It

      In addition to non-ES6 environments, existing JavaScript projects that are beginning to introduce ES6 into their codebase may not want to apply this rule if the cost of migrating from var to let is too costly. Source: http://eslint.org/docs/rules/

      All 'var' declarations must be at the top of the function scope.
      Open

              var data = payload;
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      Require Variable Declarations to be at the top of their scope (vars-on-top)

      The vars-on-top rule generates warnings when variable declarations are not used serially at the top of a function scope or the top of a program. By default variable declarations are always moved (“hoisted”) invisibly to the top of their containing scope by the JavaScript interpreter. This rule forces the programmer to represent that behaviour by manually moving the variable declaration to the top of its containing scope.

      Rule Details

      This rule aims to keep all variable declarations in the leading series of statements. Allowing multiple declarations helps promote maintainability and is thus allowed.

      Examples of incorrect code for this rule:

      /*eslint vars-on-top: "error"*/
      
      // Variable declarations in a block:
      function doSomething() {
          var first;
          if (true) {
              first = true;
          }
          var second;
      }
      
      // Variable declaration in for initializer:
      function doSomething() {
          for (var i=0; i<10; i++) {}
      }
      /*eslint vars-on-top: "error"*/
      
      // Variables after other statements:
      f();
      var a;

      Examples of correct code for this rule:

      /*eslint vars-on-top: "error"*/
      
      function doSomething() {
          var first;
          var second; //multiple declarations are allowed at the top
          if (true) {
              first = true;
          }
      }
      
      function doSomething() {
          var i;
          for (i=0; i<10; i++) {}
      }
      /*eslint vars-on-top: "error"*/
      
      var a;
      f();
      /*eslint vars-on-top: "error"*/
      
      // Directives may precede variable declarations.
      "use strict";
      var a;
      f();
      
      // Comments can describe variables.
      function doSomething() {
          // this is the first var.
          var first;
          // this is the second var.
          var second
      }

      Further Reading

      All 'var' declarations must be at the top of the function scope.
      Open

              var metadata = payload.metadata;
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      Require Variable Declarations to be at the top of their scope (vars-on-top)

      The vars-on-top rule generates warnings when variable declarations are not used serially at the top of a function scope or the top of a program. By default variable declarations are always moved (“hoisted”) invisibly to the top of their containing scope by the JavaScript interpreter. This rule forces the programmer to represent that behaviour by manually moving the variable declaration to the top of its containing scope.

      Rule Details

      This rule aims to keep all variable declarations in the leading series of statements. Allowing multiple declarations helps promote maintainability and is thus allowed.

      Examples of incorrect code for this rule:

      /*eslint vars-on-top: "error"*/
      
      // Variable declarations in a block:
      function doSomething() {
          var first;
          if (true) {
              first = true;
          }
          var second;
      }
      
      // Variable declaration in for initializer:
      function doSomething() {
          for (var i=0; i<10; i++) {}
      }
      /*eslint vars-on-top: "error"*/
      
      // Variables after other statements:
      f();
      var a;

      Examples of correct code for this rule:

      /*eslint vars-on-top: "error"*/
      
      function doSomething() {
          var first;
          var second; //multiple declarations are allowed at the top
          if (true) {
              first = true;
          }
      }
      
      function doSomething() {
          var i;
          for (i=0; i<10; i++) {}
      }
      /*eslint vars-on-top: "error"*/
      
      var a;
      f();
      /*eslint vars-on-top: "error"*/
      
      // Directives may precede variable declarations.
      "use strict";
      var a;
      f();
      
      // Comments can describe variables.
      function doSomething() {
          // this is the first var.
          var first;
          // this is the second var.
          var second
      }

      Further Reading

      All 'var' declarations must be at the top of the function scope.
      Open

              var data = payload.data;
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      Require Variable Declarations to be at the top of their scope (vars-on-top)

      The vars-on-top rule generates warnings when variable declarations are not used serially at the top of a function scope or the top of a program. By default variable declarations are always moved (“hoisted”) invisibly to the top of their containing scope by the JavaScript interpreter. This rule forces the programmer to represent that behaviour by manually moving the variable declaration to the top of its containing scope.

      Rule Details

      This rule aims to keep all variable declarations in the leading series of statements. Allowing multiple declarations helps promote maintainability and is thus allowed.

      Examples of incorrect code for this rule:

      /*eslint vars-on-top: "error"*/
      
      // Variable declarations in a block:
      function doSomething() {
          var first;
          if (true) {
              first = true;
          }
          var second;
      }
      
      // Variable declaration in for initializer:
      function doSomething() {
          for (var i=0; i<10; i++) {}
      }
      /*eslint vars-on-top: "error"*/
      
      // Variables after other statements:
      f();
      var a;

      Examples of correct code for this rule:

      /*eslint vars-on-top: "error"*/
      
      function doSomething() {
          var first;
          var second; //multiple declarations are allowed at the top
          if (true) {
              first = true;
          }
      }
      
      function doSomething() {
          var i;
          for (i=0; i<10; i++) {}
      }
      /*eslint vars-on-top: "error"*/
      
      var a;
      f();
      /*eslint vars-on-top: "error"*/
      
      // Directives may precede variable declarations.
      "use strict";
      var a;
      f();
      
      // Comments can describe variables.
      function doSomething() {
          // this is the first var.
          var first;
          // this is the second var.
          var second
      }

      Further Reading

      Unexpected var, use let or const instead.
      Open

              var data = payload;
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      require let or const instead of var (no-var)

      ECMAScript 6 allows programmers to create variables with block scope instead of function scope using the let and const keywords. Block scope is common in many other programming languages and helps programmers avoid mistakes such as:

      var count = people.length;
      var enoughFood = count > sandwiches.length;
      
      if (enoughFood) {
          var count = sandwiches.length; // accidentally overriding the count variable
          console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
      }
      
      // our count variable is no longer accurate
      console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");

      Rule Details

      This rule is aimed at discouraging the use of var and encouraging the use of const or let instead.

      Examples

      Examples of incorrect code for this rule:

      /*eslint no-var: "error"*/
      
      var x = "y";
      var CONFIG = {};

      Examples of correct code for this rule:

      /*eslint no-var: "error"*/
      /*eslint-env es6*/
      
      let x = "y";
      const CONFIG = {};

      When Not To Use It

      In addition to non-ES6 environments, existing JavaScript projects that are beginning to introduce ES6 into their codebase may not want to apply this rule if the cost of migrating from var to let is too costly. Source: http://eslint.org/docs/rules/

      All 'var' declarations must be at the top of the function scope.
      Open

              var metadata = {};
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      Require Variable Declarations to be at the top of their scope (vars-on-top)

      The vars-on-top rule generates warnings when variable declarations are not used serially at the top of a function scope or the top of a program. By default variable declarations are always moved (“hoisted”) invisibly to the top of their containing scope by the JavaScript interpreter. This rule forces the programmer to represent that behaviour by manually moving the variable declaration to the top of its containing scope.

      Rule Details

      This rule aims to keep all variable declarations in the leading series of statements. Allowing multiple declarations helps promote maintainability and is thus allowed.

      Examples of incorrect code for this rule:

      /*eslint vars-on-top: "error"*/
      
      // Variable declarations in a block:
      function doSomething() {
          var first;
          if (true) {
              first = true;
          }
          var second;
      }
      
      // Variable declaration in for initializer:
      function doSomething() {
          for (var i=0; i<10; i++) {}
      }
      /*eslint vars-on-top: "error"*/
      
      // Variables after other statements:
      f();
      var a;

      Examples of correct code for this rule:

      /*eslint vars-on-top: "error"*/
      
      function doSomething() {
          var first;
          var second; //multiple declarations are allowed at the top
          if (true) {
              first = true;
          }
      }
      
      function doSomething() {
          var i;
          for (i=0; i<10; i++) {}
      }
      /*eslint vars-on-top: "error"*/
      
      var a;
      f();
      /*eslint vars-on-top: "error"*/
      
      // Directives may precede variable declarations.
      "use strict";
      var a;
      f();
      
      // Comments can describe variables.
      function doSomething() {
          // this is the first var.
          var first;
          // this is the second var.
          var second
      }

      Further Reading

      Unexpected var, use let or const instead.
      Open

              var metadata = {};
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      require let or const instead of var (no-var)

      ECMAScript 6 allows programmers to create variables with block scope instead of function scope using the let and const keywords. Block scope is common in many other programming languages and helps programmers avoid mistakes such as:

      var count = people.length;
      var enoughFood = count > sandwiches.length;
      
      if (enoughFood) {
          var count = sandwiches.length; // accidentally overriding the count variable
          console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
      }
      
      // our count variable is no longer accurate
      console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");

      Rule Details

      This rule is aimed at discouraging the use of var and encouraging the use of const or let instead.

      Examples

      Examples of incorrect code for this rule:

      /*eslint no-var: "error"*/
      
      var x = "y";
      var CONFIG = {};

      Examples of correct code for this rule:

      /*eslint no-var: "error"*/
      /*eslint-env es6*/
      
      let x = "y";
      const CONFIG = {};

      When Not To Use It

      In addition to non-ES6 environments, existing JavaScript projects that are beginning to introduce ES6 into their codebase may not want to apply this rule if the cost of migrating from var to let is too costly. Source: http://eslint.org/docs/rules/

      Unexpected var, use let or const instead.
      Open

              var data = payload.data;
      Severity: Minor
      Found in packages/search-source/lib/client.js by eslint

      require let or const instead of var (no-var)

      ECMAScript 6 allows programmers to create variables with block scope instead of function scope using the let and const keywords. Block scope is common in many other programming languages and helps programmers avoid mistakes such as:

      var count = people.length;
      var enoughFood = count > sandwiches.length;
      
      if (enoughFood) {
          var count = sandwiches.length; // accidentally overriding the count variable
          console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
      }
      
      // our count variable is no longer accurate
      console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");

      Rule Details

      This rule is aimed at discouraging the use of var and encouraging the use of const or let instead.

      Examples

      Examples of incorrect code for this rule:

      /*eslint no-var: "error"*/
      
      var x = "y";
      var CONFIG = {};

      Examples of correct code for this rule:

      /*eslint no-var: "error"*/
      /*eslint-env es6*/
      
      let x = "y";
      const CONFIG = {};

      When Not To Use It

      In addition to non-ES6 environments, existing JavaScript projects that are beginning to introduce ES6 into their codebase may not want to apply this rule if the cost of migrating from var to let is too costly. Source: http://eslint.org/docs/rules/

      There are no issues that match your filters.

      Category
      Status