acooks/jittertrap

View on GitHub
html5-client/src/js/jittertrap-programs.js

Summary

Maintainability
A
1 hr
Test Coverage

Function Program has 66 lines of code (exceeds 50 allowed). Consider refactoring.
Open

  var Program = function (json) {
    this.id = "program_" + nextPID++;
    this.name = json.name;
    this.timeoutHandles = {};
    this.impairments = json.impairments;
Severity: Major
Found in html5-client/src/js/jittertrap-programs.js - About 1 hr to fix

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

          if (this != runningProgram) {

    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/

    Unexpected trailing comma.
    Open

            20: { stop: true },

    require or disallow trailing commas (comma-dangle)

    Trailing commas in object literals are valid according to the ECMAScript 5 (and ECMAScript 3!) spec. However, IE8 (when not in IE8 document mode) and below will throw an error when it encounters trailing commas in JavaScript.

    var foo = {
        bar: "baz",
        qux: "quux",
    };

    Trailing commas simplify adding and removing items to objects and arrays, since only the lines you are modifying must be touched. Another argument in favor of trailing commas is that it improves the clarity of diffs when an item is added or removed from an object or array:

    Less clear:

    var foo = {
    -    bar: "baz",
    -    qux: "quux"
    +    bar: "baz"
     };

    More clear:

    var foo = {
         bar: "baz",
    -    qux: "quux",
     };

    Rule Details

    This rule enforces consistent use of trailing commas in object and array literals.

    Options

    This rule has a string option or an object option:

    {
        "comma-dangle": ["error", "never"],
        // or
        "comma-dangle": ["error", {
            "arrays": "never",
            "objects": "never",
            "imports": "never",
            "exports": "never",
            "functions": "ignore",
        }]
    }
    • "never" (default) disallows trailing commas
    • "always" requires trailing commas
    • "always-multiline" requires trailing commas when the last element or property is in a different line than the closing ] or } and disallows trailing commas when the last element or property is on the same line as the closing ] or }
    • "only-multiline" allows (but does not require) trailing commas when the last element or property is in a different line than the closing ] or } and disallows trailing commas when the last element or property is on the same line as the closing ] or }

    Trailing commas in function declarations and function calls are valid syntax since ECMAScript 2017; however, the string option does not check these situations for backwards compatibility.

    You can also use an object option to configure this rule for each type of syntax. Each of the following options can be set to "never", "always", "always-multiline", "only-multiline", or "ignore". The default for each option is "never" unless otherwise specified.

    • arrays is for array literals and array patterns of destructuring. (e.g. let [a,] = [1,];)
    • objects is for object literals and object patterns of destructuring. (e.g. let {a,} = {a: 1};)
    • imports is for import declarations of ES Modules. (e.g. import {a,} from "foo";)
    • exports is for export declarations of ES Modules. (e.g. export {a,};)
    • functions is for function declarations and function calls. (e.g. (function(a,){ })(b,);)
      functions is set to "ignore" by default for consistency with the string option.

    never

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

    /*eslint comma-dangle: ["error", "never"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux",
    };
    
    var arr = [1,2,];
    
    foo({
      bar: "baz",
      qux: "quux",
    });

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

    /*eslint comma-dangle: ["error", "never"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux"
    };
    
    var arr = [1,2];
    
    foo({
      bar: "baz",
      qux: "quux"
    });

    always

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

    /*eslint comma-dangle: ["error", "always"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux"
    };
    
    var arr = [1,2];
    
    foo({
      bar: "baz",
      qux: "quux"
    });

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

    /*eslint comma-dangle: ["error", "always"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux",
    };
    
    var arr = [1,2,];
    
    foo({
      bar: "baz",
      qux: "quux",
    });

    always-multiline

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

    /*eslint comma-dangle: ["error", "always-multiline"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux"
    };
    
    var foo = { bar: "baz", qux: "quux", };
    
    var arr = [1,2,];
    
    var arr = [1,
        2,];
    
    var arr = [
        1,
        2
    ];
    
    foo({
      bar: "baz",
      qux: "quux"
    });

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

    /*eslint comma-dangle: ["error", "always-multiline"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux",
    };
    
    var foo = {bar: "baz", qux: "quux"};
    var arr = [1,2];
    
    var arr = [1,
        2];
    
    var arr = [
        1,
        2,
    ];
    
    foo({
      bar: "baz",
      qux: "quux",
    });

    only-multiline

    Examples of incorrect code for this rule with the "only-multiline" option:

    /*eslint comma-dangle: ["error", "only-multiline"]*/
    
    var foo = { bar: "baz", qux: "quux", };
    
    var arr = [1,2,];
    
    var arr = [1,
        2,];

    Examples of correct code for this rule with the "only-multiline" option:

    /*eslint comma-dangle: ["error", "only-multiline"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux",
    };
    
    var foo = {
        bar: "baz",
        qux: "quux"
    };
    
    var foo = {bar: "baz", qux: "quux"};
    var arr = [1,2];
    
    var arr = [1,
        2];
    
    var arr = [
        1,
        2,
    ];
    
    var arr = [
        1,
        2
    ];
    
    foo({
      bar: "baz",
      qux: "quux",
    });
    
    foo({
      bar: "baz",
      qux: "quux"
    });

    functions

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

    /*eslint comma-dangle: ["error", {"functions": "never"}]*/
    
    function foo(a, b,) {
    }
    
    foo(a, b,);
    new foo(a, b,);

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

    /*eslint comma-dangle: ["error", {"functions": "never"}]*/
    
    function foo(a, b) {
    }
    
    foo(a, b);
    new foo(a, b);

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

    /*eslint comma-dangle: ["error", {"functions": "always"}]*/
    
    function foo(a, b) {
    }
    
    foo(a, b);
    new foo(a, b);

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

    /*eslint comma-dangle: ["error", {"functions": "always"}]*/
    
    function foo(a, b,) {
    }
    
    foo(a, b,);
    new foo(a, b,);

    When Not To Use It

    You can turn this rule off if you are not concerned with dangling commas. Source: http://eslint.org/docs/rules/

    Don't make functions within a loop.
    Open

              this.timeoutHandles[i] = setTimeout(function(t, d, j, l) {

    Disallow Functions in Loops (no-loop-func)

    Writing functions within loops tends to result in errors due to the way the function creates a closure around the loop. For example:

    for (var i = 0; i < 10; i++) {
        funcs[i] = function() {
            return i;
        };
    }

    In this case, you would expect each function created within the loop to return a different number. In reality, each function returns 10, because that was the last value of i in the scope.

    let or const mitigate this problem.

    /*eslint-env es6*/
    
    for (let i = 0; i < 10; i++) {
        funcs[i] = function() {
            return i;
        };
    }

    In this case, each function created within the loop returns a different number as expected.

    Rule Details

    This error is raised to highlight a piece of code that may not work as you expect it to and could also indicate a misunderstanding of how the language works. Your code may run without any problems if you do not fix this error, but in some situations it could behave unexpectedly.

    Examples of incorrect code for this rule:

    /*eslint no-loop-func: "error"*/
    /*eslint-env es6*/
    
    for (var i=10; i; i--) {
        (function() { return i; })();
    }
    
    while(i) {
        var a = function() { return i; };
        a();
    }
    
    do {
        function a() { return i; };
        a();
    } while (i);
    
    let foo = 0;
    for (let i=10; i; i--) {
        // Bad, function is referencing block scoped variable in the outer scope.
        var a = function() { return foo; };
        a();
    }

    Examples of correct code for this rule:

    /*eslint no-loop-func: "error"*/
    /*eslint-env es6*/
    
    var a = function() {};
    
    for (var i=10; i; i--) {
        a();
    }
    
    for (var i=10; i; i--) {
        var a = function() {}; // OK, no references to variables in the outer scopes.
        a();
    }
    
    for (let i=10; i; i--) {
        var a = function() { return i; }; // OK, all references are referring to block scoped variables in the loop.
        a();
    }
    
    var foo = 100;
    for (let i=10; i; i--) {
        var a = function() { return foo; }; // OK, all references are referring to never modified variables.
        a();
    }
    //... no modifications of foo after this loop ...

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

    Don't make functions within a loop.
    Open

              this.timeoutHandles[i] = setTimeout(function() {

    Disallow Functions in Loops (no-loop-func)

    Writing functions within loops tends to result in errors due to the way the function creates a closure around the loop. For example:

    for (var i = 0; i < 10; i++) {
        funcs[i] = function() {
            return i;
        };
    }

    In this case, you would expect each function created within the loop to return a different number. In reality, each function returns 10, because that was the last value of i in the scope.

    let or const mitigate this problem.

    /*eslint-env es6*/
    
    for (let i = 0; i < 10; i++) {
        funcs[i] = function() {
            return i;
        };
    }

    In this case, each function created within the loop returns a different number as expected.

    Rule Details

    This error is raised to highlight a piece of code that may not work as you expect it to and could also indicate a misunderstanding of how the language works. Your code may run without any problems if you do not fix this error, but in some situations it could behave unexpectedly.

    Examples of incorrect code for this rule:

    /*eslint no-loop-func: "error"*/
    /*eslint-env es6*/
    
    for (var i=10; i; i--) {
        (function() { return i; })();
    }
    
    while(i) {
        var a = function() { return i; };
        a();
    }
    
    do {
        function a() { return i; };
        a();
    } while (i);
    
    let foo = 0;
    for (let i=10; i; i--) {
        // Bad, function is referencing block scoped variable in the outer scope.
        var a = function() { return foo; };
        a();
    }

    Examples of correct code for this rule:

    /*eslint no-loop-func: "error"*/
    /*eslint-env es6*/
    
    var a = function() {};
    
    for (var i=10; i; i--) {
        a();
    }
    
    for (var i=10; i; i--) {
        var a = function() {}; // OK, no references to variables in the outer scopes.
        a();
    }
    
    for (let i=10; i; i--) {
        var a = function() { return i; }; // OK, all references are referring to block scoped variables in the loop.
        a();
    }
    
    var foo = 100;
    for (let i=10; i; i--) {
        var a = function() { return foo; }; // OK, all references are referring to never modified variables.
        a();
    }
    //... no modifications of foo after this loop ...

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

    The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
    Open

          for (var th in this.timeoutHandles) {

    Require Guarding for-in (guard-for-in)

    Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop.

    for (key in foo) {
        doSomething(key);
    }

    Note that simply checking foo.hasOwnProperty(key) is likely to cause an error in some cases; see [no-prototype-builtins](no-prototype-builtins.md).

    Rule Details

    This rule is aimed at preventing unexpected behavior that could arise from using a for in loop without filtering the results in the loop. As such, it will warn when for in loops do not filter their results with an if statement.

    Examples of incorrect code for this rule:

    /*eslint guard-for-in: "error"*/
    
    for (key in foo) {
        doSomething(key);
    }

    Examples of correct code for this rule:

    /*eslint guard-for-in: "error"*/
    
    for (key in foo) {
        if (Object.prototype.hasOwnProperty.call(foo, key)) {
            doSomething(key);
        }
        if ({}.hasOwnProperty.call(foo, key)) {
            doSomething(key);
        }
    }

    Related Rules

    • [no-prototype-builtins](no-prototype-builtins.md)

    Further Reading

    Unexpected trailing comma.
    Open

                                programUID:  pgm.id,

    require or disallow trailing commas (comma-dangle)

    Trailing commas in object literals are valid according to the ECMAScript 5 (and ECMAScript 3!) spec. However, IE8 (when not in IE8 document mode) and below will throw an error when it encounters trailing commas in JavaScript.

    var foo = {
        bar: "baz",
        qux: "quux",
    };

    Trailing commas simplify adding and removing items to objects and arrays, since only the lines you are modifying must be touched. Another argument in favor of trailing commas is that it improves the clarity of diffs when an item is added or removed from an object or array:

    Less clear:

    var foo = {
    -    bar: "baz",
    -    qux: "quux"
    +    bar: "baz"
     };

    More clear:

    var foo = {
         bar: "baz",
    -    qux: "quux",
     };

    Rule Details

    This rule enforces consistent use of trailing commas in object and array literals.

    Options

    This rule has a string option or an object option:

    {
        "comma-dangle": ["error", "never"],
        // or
        "comma-dangle": ["error", {
            "arrays": "never",
            "objects": "never",
            "imports": "never",
            "exports": "never",
            "functions": "ignore",
        }]
    }
    • "never" (default) disallows trailing commas
    • "always" requires trailing commas
    • "always-multiline" requires trailing commas when the last element or property is in a different line than the closing ] or } and disallows trailing commas when the last element or property is on the same line as the closing ] or }
    • "only-multiline" allows (but does not require) trailing commas when the last element or property is in a different line than the closing ] or } and disallows trailing commas when the last element or property is on the same line as the closing ] or }

    Trailing commas in function declarations and function calls are valid syntax since ECMAScript 2017; however, the string option does not check these situations for backwards compatibility.

    You can also use an object option to configure this rule for each type of syntax. Each of the following options can be set to "never", "always", "always-multiline", "only-multiline", or "ignore". The default for each option is "never" unless otherwise specified.

    • arrays is for array literals and array patterns of destructuring. (e.g. let [a,] = [1,];)
    • objects is for object literals and object patterns of destructuring. (e.g. let {a,} = {a: 1};)
    • imports is for import declarations of ES Modules. (e.g. import {a,} from "foo";)
    • exports is for export declarations of ES Modules. (e.g. export {a,};)
    • functions is for function declarations and function calls. (e.g. (function(a,){ })(b,);)
      functions is set to "ignore" by default for consistency with the string option.

    never

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

    /*eslint comma-dangle: ["error", "never"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux",
    };
    
    var arr = [1,2,];
    
    foo({
      bar: "baz",
      qux: "quux",
    });

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

    /*eslint comma-dangle: ["error", "never"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux"
    };
    
    var arr = [1,2];
    
    foo({
      bar: "baz",
      qux: "quux"
    });

    always

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

    /*eslint comma-dangle: ["error", "always"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux"
    };
    
    var arr = [1,2];
    
    foo({
      bar: "baz",
      qux: "quux"
    });

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

    /*eslint comma-dangle: ["error", "always"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux",
    };
    
    var arr = [1,2,];
    
    foo({
      bar: "baz",
      qux: "quux",
    });

    always-multiline

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

    /*eslint comma-dangle: ["error", "always-multiline"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux"
    };
    
    var foo = { bar: "baz", qux: "quux", };
    
    var arr = [1,2,];
    
    var arr = [1,
        2,];
    
    var arr = [
        1,
        2
    ];
    
    foo({
      bar: "baz",
      qux: "quux"
    });

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

    /*eslint comma-dangle: ["error", "always-multiline"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux",
    };
    
    var foo = {bar: "baz", qux: "quux"};
    var arr = [1,2];
    
    var arr = [1,
        2];
    
    var arr = [
        1,
        2,
    ];
    
    foo({
      bar: "baz",
      qux: "quux",
    });

    only-multiline

    Examples of incorrect code for this rule with the "only-multiline" option:

    /*eslint comma-dangle: ["error", "only-multiline"]*/
    
    var foo = { bar: "baz", qux: "quux", };
    
    var arr = [1,2,];
    
    var arr = [1,
        2,];

    Examples of correct code for this rule with the "only-multiline" option:

    /*eslint comma-dangle: ["error", "only-multiline"]*/
    
    var foo = {
        bar: "baz",
        qux: "quux",
    };
    
    var foo = {
        bar: "baz",
        qux: "quux"
    };
    
    var foo = {bar: "baz", qux: "quux"};
    var arr = [1,2];
    
    var arr = [1,
        2];
    
    var arr = [
        1,
        2,
    ];
    
    var arr = [
        1,
        2
    ];
    
    foo({
      bar: "baz",
      qux: "quux",
    });
    
    foo({
      bar: "baz",
      qux: "quux"
    });

    functions

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

    /*eslint comma-dangle: ["error", {"functions": "never"}]*/
    
    function foo(a, b,) {
    }
    
    foo(a, b,);
    new foo(a, b,);

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

    /*eslint comma-dangle: ["error", {"functions": "never"}]*/
    
    function foo(a, b) {
    }
    
    foo(a, b);
    new foo(a, b);

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

    /*eslint comma-dangle: ["error", {"functions": "always"}]*/
    
    function foo(a, b) {
    }
    
    foo(a, b);
    new foo(a, b);

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

    /*eslint comma-dangle: ["error", {"functions": "always"}]*/
    
    function foo(a, b,) {
    }
    
    foo(a, b,);
    new foo(a, b,);

    When Not To Use It

    You can turn this rule off if you are not concerned with dangling commas. Source: http://eslint.org/docs/rules/

    There are no issues that match your filters.

    Category
    Status