retrohacker/add-listener-first

View on GitHub

Showing 4 of 4 total issues

Expected newline after "use strict" directive.
Open

'use strict'
Severity: Minor
Found in index.js by eslint

require or disallow newlines around directives (lines-around-directive)

Directives are used in JavaScript to indicate to the execution environment that a script would like to opt into a feature such as "strict mode". Directives are grouped together in a directive prologue at the top of either a file or function block and are applied to the scope in which they occur.

// Strict mode is invoked for the entire script
"use strict";

var foo;

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

function bar() {
  // Strict mode is only invoked within this function
  "use strict";

  var baz;
}

Rule Details

This rule requires or disallows blank newlines around directive prologues. This rule does not enforce any conventions about blank newlines between the individual directives. In addition, it does not require blank newlines before directive prologues unless they are preceded by a comment. Please use the [padded-blocks](padded-blocks.md) rule if this is a style you would like to enforce.

Options

This rule has one option. It can either be a string or an object:

  • "always" (default) enforces blank newlines around directives.
  • "never" disallows blank newlines around directives.

or

{
  "before": "always" or "never"
  "after": "always" or "never",
}

always

This is the default option.

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

/* eslint lines-around-directive: ["error", "always"] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment
"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment
  "use strict";
  var bar;
}

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

/* eslint lines-around-directive: ["error", "always"] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment

"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment

  "use strict";

  var bar;
}

never

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

/* eslint lines-around-directive: ["error", "never"] */

/* Top of file */

"use strict";

var foo;


/* Top of file */
// comment

"use strict";
"use asm";

var foo;


function foo() {
  "use strict";
  "use asm";

  var bar;
}


function foo() {
  // comment

  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", "never"] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment
"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment
  "use strict";
  var bar;
}

before & after

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

/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */

/* Top of file */

"use strict";
var foo;

/* Top of file */
// comment

"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment

  "use strict";
  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment
"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment
  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment
"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment
  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment

"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment

  "use strict";
  var bar;
}

When Not To Use It

You can safely disable this rule if you do not have any strict conventions about whether or not directive prologues should have blank newlines before or after them.

Related Rules

  • [lines-around-comment](lines-around-comment.md)
  • [padded-blocks](padded-blocks.md)

Compatibility

Expected newline after "use strict" directive.
Open

'use strict'
Severity: Minor
Found in examples/one.js by eslint

require or disallow newlines around directives (lines-around-directive)

Directives are used in JavaScript to indicate to the execution environment that a script would like to opt into a feature such as "strict mode". Directives are grouped together in a directive prologue at the top of either a file or function block and are applied to the scope in which they occur.

// Strict mode is invoked for the entire script
"use strict";

var foo;

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

function bar() {
  // Strict mode is only invoked within this function
  "use strict";

  var baz;
}

Rule Details

This rule requires or disallows blank newlines around directive prologues. This rule does not enforce any conventions about blank newlines between the individual directives. In addition, it does not require blank newlines before directive prologues unless they are preceded by a comment. Please use the [padded-blocks](padded-blocks.md) rule if this is a style you would like to enforce.

Options

This rule has one option. It can either be a string or an object:

  • "always" (default) enforces blank newlines around directives.
  • "never" disallows blank newlines around directives.

or

{
  "before": "always" or "never"
  "after": "always" or "never",
}

always

This is the default option.

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

/* eslint lines-around-directive: ["error", "always"] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment
"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment
  "use strict";
  var bar;
}

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

/* eslint lines-around-directive: ["error", "always"] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment

"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment

  "use strict";

  var bar;
}

never

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

/* eslint lines-around-directive: ["error", "never"] */

/* Top of file */

"use strict";

var foo;


/* Top of file */
// comment

"use strict";
"use asm";

var foo;


function foo() {
  "use strict";
  "use asm";

  var bar;
}


function foo() {
  // comment

  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", "never"] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment
"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment
  "use strict";
  var bar;
}

before & after

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

/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */

/* Top of file */

"use strict";
var foo;

/* Top of file */
// comment

"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment

  "use strict";
  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment
"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment
  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment
"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment
  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment

"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment

  "use strict";
  var bar;
}

When Not To Use It

You can safely disable this rule if you do not have any strict conventions about whether or not directive prologues should have blank newlines before or after them.

Related Rules

  • [lines-around-comment](lines-around-comment.md)
  • [padded-blocks](padded-blocks.md)

Compatibility

Expected newline before "use strict" directive.
Open

'use strict'
Severity: Minor
Found in index.js by eslint

require or disallow newlines around directives (lines-around-directive)

Directives are used in JavaScript to indicate to the execution environment that a script would like to opt into a feature such as "strict mode". Directives are grouped together in a directive prologue at the top of either a file or function block and are applied to the scope in which they occur.

// Strict mode is invoked for the entire script
"use strict";

var foo;

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

function bar() {
  // Strict mode is only invoked within this function
  "use strict";

  var baz;
}

Rule Details

This rule requires or disallows blank newlines around directive prologues. This rule does not enforce any conventions about blank newlines between the individual directives. In addition, it does not require blank newlines before directive prologues unless they are preceded by a comment. Please use the [padded-blocks](padded-blocks.md) rule if this is a style you would like to enforce.

Options

This rule has one option. It can either be a string or an object:

  • "always" (default) enforces blank newlines around directives.
  • "never" disallows blank newlines around directives.

or

{
  "before": "always" or "never"
  "after": "always" or "never",
}

always

This is the default option.

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

/* eslint lines-around-directive: ["error", "always"] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment
"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment
  "use strict";
  var bar;
}

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

/* eslint lines-around-directive: ["error", "always"] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment

"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment

  "use strict";

  var bar;
}

never

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

/* eslint lines-around-directive: ["error", "never"] */

/* Top of file */

"use strict";

var foo;


/* Top of file */
// comment

"use strict";
"use asm";

var foo;


function foo() {
  "use strict";
  "use asm";

  var bar;
}


function foo() {
  // comment

  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", "never"] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment
"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment
  "use strict";
  var bar;
}

before & after

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

/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */

/* Top of file */

"use strict";
var foo;

/* Top of file */
// comment

"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment

  "use strict";
  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment
"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment
  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */

/* Top of file */
"use strict";

var foo;

/* Top of file */
// comment
"use strict";
"use asm";

var foo;

function foo() {
  "use strict";
  "use asm";

  var bar;
}

function foo() {
  // comment
  "use strict";

  var bar;
}

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

/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment

"use strict";
"use asm";
var foo;

function foo() {
  "use strict";
  "use asm";
  var bar;
}

function foo() {
  // comment

  "use strict";
  var bar;
}

When Not To Use It

You can safely disable this rule if you do not have any strict conventions about whether or not directive prologues should have blank newlines before or after them.

Related Rules

  • [lines-around-comment](lines-around-comment.md)
  • [padded-blocks](padded-blocks.md)

Compatibility

Unary operator '++' used.
Open

  for (let i = 0; i < listeners.length; i++) {
Severity: Minor
Found in index.js by eslint

disallow the unary operators ++ and -- (no-plusplus)

Because the unary ++ and -- operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code.

var i = 10;
var j = 20;

i ++
j
// i = 11, j = 20
var i = 10;
var j = 20;

i
++
j
// i = 10, j = 21

Rule Details

This rule disallows the unary operators ++ and --.

Examples of incorrect code for this rule:

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

var foo = 0;
foo++;

var bar = 42;
bar--;

for (i = 0; i < l; i++) {
    return;
}

Examples of correct code for this rule:

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

var foo = 0;
foo += 1;

var bar = 42;
bar -= 1;

for (i = 0; i < l; i += 1) {
    return;
}

Options

This rule has an object option.

  • "allowForLoopAfterthoughts": true allows unary operators ++ and -- in the afterthought (final expression) of a for loop.

allowForLoopAfterthoughts

Examples of correct code for this rule with the { "allowForLoopAfterthoughts": true } option:

/*eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }]*/

for (i = 0; i < l; i++) {
    return;
}

for (i = 0; i < l; i--) {
    return;
}

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

Severity
Category
Status
Source
Language