metamaps/metamaps

View on GitHub
frontend/src/Metamaps/Util.js

Summary

Maintainability
A
2 hrs
Test Coverage

Function splitLine has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  splitLine: function(st, n) {
    var b = ''
    var s = st || ''
    while (s.length > n) {
      var c = s.substring(0, n)
Severity: Minor
Found in frontend/src/Metamaps/Util.js - About 25 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 a conditional expression and instead saw an assignment.
Open

    for (let event = walker.next(); event = walker.next(); event) {
Severity: Minor
Found in frontend/src/Metamaps/Util.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

Expected an assignment or function call and instead saw an expression.
Open

    s = graph.canvas.getSize(),
Severity: Minor
Found in frontend/src/Metamaps/Util.js by eslint

Disallow Unused Expressions (no-unused-expressions)

An unused expression which has no effect on the state of the program indicates a logic error.

For example, n + 1; is not a syntax error, but it might be a typing mistake where a programmer meant an assignment statement n += 1; instead.

Rule Details

This rule aims to eliminate unused expressions which have no effect on the state of the program.

This rule does not apply to function calls or constructor calls with the new operator, because they could have side effects on the state of the program.

var i = 0;
function increment() { i += 1; }
increment(); // return value is unused, but i changed as a side effect

var nThings = 0;
function Thing() { nThings += 1; }
new Thing(); // constructed object is unused, but nThings changed as a side effect

This rule does not apply to directives (which are in the form of literal string expressions such as "use strict"; at the beginning of a script, module, or function).

Sequence expressions (those using a comma, such as a = 1, b = 2) are always considered unused unless their return value is assigned or used in a condition evaluation, or a function call is made with the sequence expression value.

Options

This rule, in its default state, does not require any arguments. If you would like to enable one or more of the following you may pass an object with the options set as follows:

  • allowShortCircuit set to true will allow you to use short circuit evaluations in your expressions (Default: false).
  • allowTernary set to true will enable you to use ternary operators in your expressions similarly to short circuit evaluations (Default: false).
  • allowTaggedTemplates set to true will enable you to use tagged template literals in your expressions (Default: false).

These options allow unused expressions only if all of the code paths either directly change the state (for example, assignment statement) or could have side effects (for example, function call).

Examples of incorrect code for the default { "allowShortCircuit": false, "allowTernary": false } options:

/*eslint no-unused-expressions: "error"*/

0

if(0) 0

{0}

f(0), {}

a && b()

a, b()

c = a, b;

a() && function namedFunctionInExpressionContext () {f();}

(function anIncompleteIIFE () {});

injectGlobal`body{ color: red; }`

Note that one or more string expression statements (with or without semi-colons) will only be considered as unused if they are not in the beginning of a script, module, or function (alone and uninterrupted by other statements). Otherwise, they will be treated as part of a "directive prologue", a section potentially usable by JavaScript engines. This includes "strict mode" directives.

"use strict";
"use asm"
"use stricter";
"use babel"
"any other strings like this in the prologue";

Examples of correct code for the default { "allowShortCircuit": false, "allowTernary": false } options:

/*eslint no-unused-expressions: "error"*/

{} // In this context, this is a block statement, not an object literal

{myLabel: someVar} // In this context, this is a block statement with a label and expression, not an object literal

function namedFunctionDeclaration () {}

(function aGenuineIIFE () {}());

f()

a = 0

new C

delete a.b

void a

allowShortCircuit

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

/*eslint no-unused-expressions: ["error", { "allowShortCircuit": true }]*/

a || b

Examples of correct code for the { "allowShortCircuit": true } option:

/*eslint no-unused-expressions: ["error", { "allowShortCircuit": true }]*/

a && b()
a() || (b = c)

allowTernary

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

/*eslint no-unused-expressions: ["error", { "allowTernary": true }]*/

a ? b : 0
a ? b : c()

Examples of correct code for the { "allowTernary": true } option:

/*eslint no-unused-expressions: ["error", { "allowTernary": true }]*/

a ? b() : c()
a ? (b = c) : d()

allowShortCircuit and allowTernary

Examples of correct code for the { "allowShortCircuit": true, "allowTernary": true } options:

/*eslint no-unused-expressions: ["error", { "allowShortCircuit": true, "allowTernary": true }]*/

a ? b() || (c = d) : e()

allowTaggedTemplates

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

/*eslint no-unused-expressions: ["error", { "allowTaggedTemplates": true }]*/

`some untagged template string`;

Examples of correct code for the { "allowTaggedTemplates": true } option:

/*eslint no-unused-expressions: ["error", { "allowTaggedTemplates": true }]*/

tag`some tagged template string`;

Source: http://eslint.org/docs/rules/

Unexpected use of comma operator.
Open

    s = graph.canvas.getSize(),
Severity: Minor
Found in frontend/src/Metamaps/Util.js by eslint

Disallow Use of the Comma Operator (no-sequences)

The comma operator includes multiple expressions where only one is expected. It evaluates each operand from left to right and returns the value of the last operand. However, this frequently obscures side effects, and its use is often an accident. Here are some examples of sequences:

var a = (3, 5); // a = 5

a = b += 5, a + b;

while (a = next(), a && a.length);

(0, eval)("doSomething();");

Rule Details

This rule forbids the use of the comma operator, with the following exceptions:

  • In the initialization or update portions of a for statement.
  • If the expression sequence is explicitly wrapped in parentheses.

Examples of incorrect code for this rule:

/*eslint no-sequences: "error"*/

foo = doSomething(), val;

0, eval("doSomething();");

do {} while (doSomething(), !!test);

for (; doSomething(), !!test; );

if (doSomething(), !!test);

switch (val = foo(), val) {}

while (val = foo(), val < 42);

with (doSomething(), val) {}

Examples of correct code for this rule:

/*eslint no-sequences: "error"*/

foo = (doSomething(), val);

(0, eval)("doSomething();");

do {} while ((doSomething(), !!test));

for (i = 0, j = 10; i < j; i++, j--);

if ((doSomething(), !!test));

switch ((val = foo(), val)) {}

while ((val = foo(), val < 42));

// with ((doSomething(), val)) {}

When Not To Use It

Disable this rule if sequence expressions with the comma operator are acceptable. Source: http://eslint.org/docs/rules/

Split initialized 'var' declarations into multiple statements.
Open

    var newX = (zoomPoint.x - p.x - s.width / 2 - ox) * (1 / sx),
Severity: Minor
Found in frontend/src/Metamaps/Util.js by eslint

enforce variables to be declared either together or separately in functions (one-var)

Variables can be declared at any point in JavaScript code using var, let, or const. There are many styles and preferences related to the declaration of variables, and one of those is deciding on how many variable declarations should be allowed in a single function.

There are two schools of thought in this regard:

  1. There should be just one variable declaration for all variables in the function. That declaration typically appears at the top of the function.
  2. You should use one variable declaration for each variable you want to define.

For instance:

// one variable declaration per function
function foo() {
    var bar, baz;
}

// multiple variable declarations per function
function foo() {
    var bar;
    var baz;
}

The single-declaration school of thought is based in pre-ECMAScript 6 behaviors, where there was no such thing as block scope, only function scope. Since all var statements are hoisted to the top of the function anyway, some believe that declaring all variables in a single declaration at the top of the function removes confusion around scoping rules.

Rule Details

This rule enforces variables to be declared either together or separately per function ( for var) or block (for let and const) scope.

Options

This rule has one option, which can be a string option or an object option.

String option:

  • "always" (default) requires one variable declaration per scope
  • "never" requires multiple variable declarations per scope

Object option:

  • "var": "always" requires one var declaration per function
  • "var": "never" requires multiple var declarations per function
  • "let": "always" requires one let declaration per block
  • "let": "never" requires multiple let declarations per block
  • "const": "always" requires one const declaration per block
  • "const": "never" requires multiple const declarations per block

Alternate object option:

  • "initialized": "always" requires one variable declaration for initialized variables per scope
  • "initialized": "never" requires multiple variable declarations for initialized variables per scope
  • "uninitialized": "always" requires one variable declaration for uninitialized variables per scope
  • "uninitialized": "never" requires multiple variable declarations for uninitialized variables per scope

always

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

/*eslint one-var: ["error", "always"]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
    let qux;
    let norf;
}

function foo(){
    const bar = false;
    const baz = true;
    let qux;
    let norf;
}

function foo() {
    var bar;

    if (baz) {
        var qux = true;
    }
}

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

/*eslint one-var: ["error", "always"]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    let qux,
        norf;
}

function foo(){
    const bar = true,
        baz = false;
    let qux,
        norf;
}

function foo() {
    var bar,
        qux;

    if (baz) {
        qux = true;
    }
}

function foo(){
    let bar;

    if (baz) {
        let qux;
    }
}

never

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

/*eslint one-var: ["error", "never"]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    const bar = true,
        baz = false;
}

function foo() {
    var bar,
        qux;

    if (baz) {
        qux = true;
    }
}

function foo(){
    let bar = true,
        baz = false;
}

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

/*eslint one-var: ["error", "never"]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
}

function foo() {
    var bar;

    if (baz) {
        var qux = true;
    }
}

function foo() {
    let bar;

    if (baz) {
        let qux = true;
    }
}

var, let, and const

Examples of incorrect code for this rule with the { var: "always", let: "never", const: "never" } option:

/*eslint one-var: ["error", { var: "always", let: "never", const: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
    let qux,
        norf;
}

function foo() {
    const bar = 1,
          baz = 2;
    let qux,
        norf;
}

Examples of correct code for this rule with the { var: "always", let: "never", const: "never" } option:

/*eslint one-var: ["error", { var: "always", let: "never", const: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    let qux;
    let norf;
}

function foo() {
    const bar = 1;
    const baz = 2;
    let qux;
    let norf;
}

Examples of incorrect code for this rule with the { var: "never" } option:

/*eslint one-var: ["error", { var: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
}

Examples of correct code for this rule with the { var: "never" } option:

/*eslint one-var: ["error", { var: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    const bar = 1; // `const` and `let` declarations are ignored if they are not specified
    const baz = 2;
    let qux;
    let norf;
}

initialized and uninitialized

Examples of incorrect code for this rule with the { "initialized": "always", "uninitialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/
/*eslint-env es6*/

function foo() {
    var a, b, c;
    var foo = true;
    var bar = false;
}

Examples of correct code for this rule with the { "initialized": "always", "uninitialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/

function foo() {
    var a;
    var b;
    var c;
    var foo = true,
        bar = false;
}

for (let z of foo) {
    doSomething(z);
}

let z;
for (z of foo) {
    doSomething(z);
}

Examples of incorrect code for this rule with the { "initialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "never" }]*/
/*eslint-env es6*/

function foo() {
    var foo = true,
        bar = false;
}

Examples of correct code for this rule with the { "initialized": "never" } option:

/*eslint one-var: ["error", { initialized: "never" }]*/

function foo() {
    var foo = true;
    var bar = false;
    var a, b, c; // Uninitialized variables are ignored
}

Compatibility

Split initialized 'var' declarations into multiple statements.
Open

    var pointerCoordX = (zoomPoint.x - p.x - s.width / 2 - ox) * (1 / sx),
Severity: Minor
Found in frontend/src/Metamaps/Util.js by eslint

enforce variables to be declared either together or separately in functions (one-var)

Variables can be declared at any point in JavaScript code using var, let, or const. There are many styles and preferences related to the declaration of variables, and one of those is deciding on how many variable declarations should be allowed in a single function.

There are two schools of thought in this regard:

  1. There should be just one variable declaration for all variables in the function. That declaration typically appears at the top of the function.
  2. You should use one variable declaration for each variable you want to define.

For instance:

// one variable declaration per function
function foo() {
    var bar, baz;
}

// multiple variable declarations per function
function foo() {
    var bar;
    var baz;
}

The single-declaration school of thought is based in pre-ECMAScript 6 behaviors, where there was no such thing as block scope, only function scope. Since all var statements are hoisted to the top of the function anyway, some believe that declaring all variables in a single declaration at the top of the function removes confusion around scoping rules.

Rule Details

This rule enforces variables to be declared either together or separately per function ( for var) or block (for let and const) scope.

Options

This rule has one option, which can be a string option or an object option.

String option:

  • "always" (default) requires one variable declaration per scope
  • "never" requires multiple variable declarations per scope

Object option:

  • "var": "always" requires one var declaration per function
  • "var": "never" requires multiple var declarations per function
  • "let": "always" requires one let declaration per block
  • "let": "never" requires multiple let declarations per block
  • "const": "always" requires one const declaration per block
  • "const": "never" requires multiple const declarations per block

Alternate object option:

  • "initialized": "always" requires one variable declaration for initialized variables per scope
  • "initialized": "never" requires multiple variable declarations for initialized variables per scope
  • "uninitialized": "always" requires one variable declaration for uninitialized variables per scope
  • "uninitialized": "never" requires multiple variable declarations for uninitialized variables per scope

always

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

/*eslint one-var: ["error", "always"]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
    let qux;
    let norf;
}

function foo(){
    const bar = false;
    const baz = true;
    let qux;
    let norf;
}

function foo() {
    var bar;

    if (baz) {
        var qux = true;
    }
}

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

/*eslint one-var: ["error", "always"]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    let qux,
        norf;
}

function foo(){
    const bar = true,
        baz = false;
    let qux,
        norf;
}

function foo() {
    var bar,
        qux;

    if (baz) {
        qux = true;
    }
}

function foo(){
    let bar;

    if (baz) {
        let qux;
    }
}

never

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

/*eslint one-var: ["error", "never"]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    const bar = true,
        baz = false;
}

function foo() {
    var bar,
        qux;

    if (baz) {
        qux = true;
    }
}

function foo(){
    let bar = true,
        baz = false;
}

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

/*eslint one-var: ["error", "never"]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
}

function foo() {
    var bar;

    if (baz) {
        var qux = true;
    }
}

function foo() {
    let bar;

    if (baz) {
        let qux = true;
    }
}

var, let, and const

Examples of incorrect code for this rule with the { var: "always", let: "never", const: "never" } option:

/*eslint one-var: ["error", { var: "always", let: "never", const: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
    let qux,
        norf;
}

function foo() {
    const bar = 1,
          baz = 2;
    let qux,
        norf;
}

Examples of correct code for this rule with the { var: "always", let: "never", const: "never" } option:

/*eslint one-var: ["error", { var: "always", let: "never", const: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    let qux;
    let norf;
}

function foo() {
    const bar = 1;
    const baz = 2;
    let qux;
    let norf;
}

Examples of incorrect code for this rule with the { var: "never" } option:

/*eslint one-var: ["error", { var: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
}

Examples of correct code for this rule with the { var: "never" } option:

/*eslint one-var: ["error", { var: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    const bar = 1; // `const` and `let` declarations are ignored if they are not specified
    const baz = 2;
    let qux;
    let norf;
}

initialized and uninitialized

Examples of incorrect code for this rule with the { "initialized": "always", "uninitialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/
/*eslint-env es6*/

function foo() {
    var a, b, c;
    var foo = true;
    var bar = false;
}

Examples of correct code for this rule with the { "initialized": "always", "uninitialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/

function foo() {
    var a;
    var b;
    var c;
    var foo = true,
        bar = false;
}

for (let z of foo) {
    doSomething(z);
}

let z;
for (z of foo) {
    doSomething(z);
}

Examples of incorrect code for this rule with the { "initialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "never" }]*/
/*eslint-env es6*/

function foo() {
    var foo = true,
        bar = false;
}

Examples of correct code for this rule with the { "initialized": "never" } option:

/*eslint one-var: ["error", { initialized: "never" }]*/

function foo() {
    var foo = true;
    var bar = false;
    var a, b, c; // Uninitialized variables are ignored
}

Compatibility

Split initialized 'var' declarations into multiple statements.
Open

    var s = graph.canvas.getSize(),
Severity: Minor
Found in frontend/src/Metamaps/Util.js by eslint

enforce variables to be declared either together or separately in functions (one-var)

Variables can be declared at any point in JavaScript code using var, let, or const. There are many styles and preferences related to the declaration of variables, and one of those is deciding on how many variable declarations should be allowed in a single function.

There are two schools of thought in this regard:

  1. There should be just one variable declaration for all variables in the function. That declaration typically appears at the top of the function.
  2. You should use one variable declaration for each variable you want to define.

For instance:

// one variable declaration per function
function foo() {
    var bar, baz;
}

// multiple variable declarations per function
function foo() {
    var bar;
    var baz;
}

The single-declaration school of thought is based in pre-ECMAScript 6 behaviors, where there was no such thing as block scope, only function scope. Since all var statements are hoisted to the top of the function anyway, some believe that declaring all variables in a single declaration at the top of the function removes confusion around scoping rules.

Rule Details

This rule enforces variables to be declared either together or separately per function ( for var) or block (for let and const) scope.

Options

This rule has one option, which can be a string option or an object option.

String option:

  • "always" (default) requires one variable declaration per scope
  • "never" requires multiple variable declarations per scope

Object option:

  • "var": "always" requires one var declaration per function
  • "var": "never" requires multiple var declarations per function
  • "let": "always" requires one let declaration per block
  • "let": "never" requires multiple let declarations per block
  • "const": "always" requires one const declaration per block
  • "const": "never" requires multiple const declarations per block

Alternate object option:

  • "initialized": "always" requires one variable declaration for initialized variables per scope
  • "initialized": "never" requires multiple variable declarations for initialized variables per scope
  • "uninitialized": "always" requires one variable declaration for uninitialized variables per scope
  • "uninitialized": "never" requires multiple variable declarations for uninitialized variables per scope

always

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

/*eslint one-var: ["error", "always"]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
    let qux;
    let norf;
}

function foo(){
    const bar = false;
    const baz = true;
    let qux;
    let norf;
}

function foo() {
    var bar;

    if (baz) {
        var qux = true;
    }
}

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

/*eslint one-var: ["error", "always"]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    let qux,
        norf;
}

function foo(){
    const bar = true,
        baz = false;
    let qux,
        norf;
}

function foo() {
    var bar,
        qux;

    if (baz) {
        qux = true;
    }
}

function foo(){
    let bar;

    if (baz) {
        let qux;
    }
}

never

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

/*eslint one-var: ["error", "never"]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    const bar = true,
        baz = false;
}

function foo() {
    var bar,
        qux;

    if (baz) {
        qux = true;
    }
}

function foo(){
    let bar = true,
        baz = false;
}

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

/*eslint one-var: ["error", "never"]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
}

function foo() {
    var bar;

    if (baz) {
        var qux = true;
    }
}

function foo() {
    let bar;

    if (baz) {
        let qux = true;
    }
}

var, let, and const

Examples of incorrect code for this rule with the { var: "always", let: "never", const: "never" } option:

/*eslint one-var: ["error", { var: "always", let: "never", const: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar;
    var baz;
    let qux,
        norf;
}

function foo() {
    const bar = 1,
          baz = 2;
    let qux,
        norf;
}

Examples of correct code for this rule with the { var: "always", let: "never", const: "never" } option:

/*eslint one-var: ["error", { var: "always", let: "never", const: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    let qux;
    let norf;
}

function foo() {
    const bar = 1;
    const baz = 2;
    let qux;
    let norf;
}

Examples of incorrect code for this rule with the { var: "never" } option:

/*eslint one-var: ["error", { var: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
}

Examples of correct code for this rule with the { var: "never" } option:

/*eslint one-var: ["error", { var: "never" }]*/
/*eslint-env es6*/

function foo() {
    var bar,
        baz;
    const bar = 1; // `const` and `let` declarations are ignored if they are not specified
    const baz = 2;
    let qux;
    let norf;
}

initialized and uninitialized

Examples of incorrect code for this rule with the { "initialized": "always", "uninitialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/
/*eslint-env es6*/

function foo() {
    var a, b, c;
    var foo = true;
    var bar = false;
}

Examples of correct code for this rule with the { "initialized": "always", "uninitialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/

function foo() {
    var a;
    var b;
    var c;
    var foo = true,
        bar = false;
}

for (let z of foo) {
    doSomething(z);
}

let z;
for (z of foo) {
    doSomething(z);
}

Examples of incorrect code for this rule with the { "initialized": "never" } option:

/*eslint one-var: ["error", { "initialized": "never" }]*/
/*eslint-env es6*/

function foo() {
    var foo = true,
        bar = false;
}

Examples of correct code for this rule with the { "initialized": "never" } option:

/*eslint one-var: ["error", { initialized: "never" }]*/

function foo() {
    var foo = true;
    var bar = false;
    var a, b, c; // Uninitialized variables are ignored
}

Compatibility

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

    var pointerCoordX = (zoomPoint.x - p.x - s.width / 2 - ox) * (1 / sx),
      pointerCoordY = (zoomPoint.y - p.y - s.height / 2 - oy) * (1 / sy)
Severity: Minor
Found in frontend/src/Metamaps/Util.js and 1 other location - About 50 mins to fix
frontend/src/Metamaps/Util.js on lines 227..228

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

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

    var newX = (zoomPoint.x - p.x - s.width / 2 - ox) * (1 / sx),
      newY = (zoomPoint.y - p.y - s.height / 2 - oy) * (1 / sy)
Severity: Minor
Found in frontend/src/Metamaps/Util.js and 1 other location - About 50 mins to fix
frontend/src/Metamaps/Util.js on lines 213..214

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

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

There are no issues that match your filters.

Category
Status