Gottwik/Enduro

View on GitHub
scaffolding/test_js/cms/global/global.js

Summary

Maintainability
A
0 mins
Test Coverage

Unexpected labeled statement.
Open

    company_name: 'something'

Disallow Labeled Statements (no-labels)

Labeled statements in JavaScript are used in conjunction with break and continue to control flow around multiple loops. For example:

outer:
    while (true) {

        while (true) {
            break outer;
        }
    }

The break outer statement ensures that this code will not result in an infinite loop because control is returned to the next statement after the outer label was applied. If this statement was changed to be just break, control would flow back to the outer while statement and an infinite loop would result.

While convenient in some cases, labels tend to be used only rarely and are frowned upon by some as a remedial form of flow control that is more error prone and harder to understand.

Rule Details

This rule aims to eliminate the use of labeled statements in JavaScript. It will warn whenever a labeled statement is encountered and whenever break or continue are used with a label.

Examples of incorrect code for this rule:

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

label:
    while(true) {
        // ...
    }

label:
    while(true) {
        break label;
    }

label:
    while(true) {
        continue label;
    }

label:
    switch (a) {
    case 0:
        break label;
    }

label:
    {
        break label;
    }

label:
    if (a) {
        break label;
    }

Examples of correct code for this rule:

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

var f = {
    label: "foo"
};

while (true) {
    break;
}

while (true) {
    continue;
}

Options

The options allow labels with loop or switch statements:

  • "allowLoop" (boolean, default is false) - If this option was set true, this rule ignores labels which are sticking to loop statements.
  • "allowSwitch" (boolean, default is false) - If this option was set true, this rule ignores labels which are sticking to switch statements.

Actually labeled statements in JavaScript can be used with other than loop and switch statements. However, this way is ultra rare, not well-known, so this would be confusing developers.

allowLoop

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

/*eslint no-labels: ["error", { "allowLoop": true }]*/

label:
    while (true) {
        break label;
    }

allowSwitch

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

/*eslint no-labels: ["error", { "allowSwitch": true }]*/

label:
    switch (a) {
        case 0:
            break label;
    }

When Not To Use It

If you need to use labeled statements everywhere, then you can safely disable this rule.

Related Rules

  • [no-extra-label](./no-extra-label.md)
  • [no-label-var](./no-label-var.md)
  • [no-unused-labels](./no-unused-labels.md) Source: http://eslint.org/docs/rules/

Block is redundant.
Open

{

Disallow Unnecessary Nested Blocks (no-lone-blocks)

In JavaScript, prior to ES6, standalone code blocks delimited by curly braces do not create a new scope and have no use. For example, these curly braces do nothing to foo:

{
    var foo = bar();
}

In ES6, code blocks may create a new scope if a block-level binding (let and const), a class declaration or a function declaration (in strict mode) are present. A block is not considered redundant in these cases.

Rule Details

This rule aims to eliminate unnecessary and potentially confusing blocks at the top level of a script or within other blocks.

Examples of incorrect code for this rule:

/*eslint no-lone-blocks: "error"*/

{}

if (foo) {
    bar();
    {
        baz();
    }
}

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

{
    function foo() {}
}

{
    aLabel: {
    }
}

Examples of correct code for this rule with es6 environment:

/*eslint no-lone-blocks: "error"*/
/*eslint-env es6*/

while (foo) {
    bar();
}

if (foo) {
    if (bar) {
        baz();
    }
}

function bar() {
    baz();
}

{
    let x = 1;
}

{
    const y = 1;
}

{
    class Foo {}
}

aLabel: {
}

Examples of correct code for this rule with es6 environment and strict mode via "parserOptions": { "sourceType": "module" } in the ESLint configuration or "use strict" directive in the code:

/*eslint no-lone-blocks: "error"*/
/*eslint-env es6*/

"use strict";

{
    function foo() {}
}

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

Newline required at end of file but not found.
Open

}

Require file to end with single newline (eol-last)

(fixable) The --fix option on the [command line](../user-guide/command-line-interface#fix) automatically fixes problems reported by this rule.

Trailing newlines in non-empty files are a common UNIX idiom. Benefits of trailing newlines include the ability to concatenate or append to files as well as output files to the terminal without interfering with shell prompts.

Rule Details

This rule requires at least one newline at the end of non-empty files.

Prior to v0.16.0 this rule also enforced that there was only a single line at the end of the file. If you still want this behaviour, consider enabling [no-multiple-empty-lines](no-multiple-empty-lines.md) with maxEOF and/or [no-trailing-spaces](no-trailing-spaces.md).

Examples of incorrect code for this rule:

/*eslint eol-last: "error"*/

function doSmth() {
  var foo = 2;
}

Examples of correct code for this rule:

/*eslint eol-last: "error"*/

function doSmth() {
  var foo = 2;
}

Options

This rule has a string option:

  • "unix" (default) enforces line feed (LF) as newline
  • "windows" enforces carriage return line feed (CRLF) as newline Source: http://eslint.org/docs/rules/

There are no issues that match your filters.

Category
Status