svtek/aws-sms-send

View on GitHub

Showing 59 of 59 total issues

Unexpected var, use let or const instead.
Open

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Severity: Minor
Found in index.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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Severity: Minor
Found in index.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 unnamed function.
Open

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Severity: Minor
Found in index.js by eslint

Require or disallow named function expressions (func-names)

A pattern that's becoming more common is to give function expressions names to aid in debugging. For example:

Foo.prototype.bar = function bar() {};

Adding the second bar in the above example is optional. If you leave off the function name then when the function throws an exception you are likely to get something similar to anonymous function in the stack trace. If you provide the optional name for a function expression then you will get the name of the function expression in the stack trace.

Rule Details

This rule can enforce or disallow the use of named function expressions.

Options

This rule has a string option:

  • "always" (default) requires function expressions to have a name
  • "as-needed" requires function expressions to have a name, if the name cannot be assigned automatically in an ES6 environment
  • "never" disallows named function expressions, except in recursive functions, where a name is needed

always

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

/*eslint func-names: ["error", "always"]*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

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

/*eslint func-names: ["error", "always"]*/

Foo.prototype.bar = function bar() {};

(function bar() {
    // ...
}())

as-needed

ECMAScript 6 introduced a name property on all functions. The value of name is determined by evaluating the code around the function to see if a name can be inferred. For example, a function assigned to a variable will automatically have a name property equal to the name of the variable. The value of name is then used in stack traces for easier debugging.

Examples of incorrect code for this rule with the default "as-needed" option:

/*eslint func-names: ["error", "as-needed"]*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

Examples of correct code for this rule with the default "as-needed" option:

/*eslint func-names: ["error", "as-needed"]*/

var bar = function() {};

(function bar() {
    // ...
}())

never

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

/*eslint func-names: ["error", "never"]*/

Foo.prototype.bar = function bar() {};

(function bar() {
    // ...
}())

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

/*eslint func-names: ["error", "never"]*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

Further Reading

Compatibility

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

var AWS = require('aws-sdk');
Severity: Minor
Found in index.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 function expression.
Open

      return new Promise(function (resolve, reject) {
Severity: Minor
Found in index.js by eslint

Suggest using arrow functions as callbacks. (prefer-arrow-callback)

Arrow functions are suited to callbacks, because:

  • this keywords in arrow functions bind to the upper scope's.
  • The notation of the arrow function is shorter than function expression's.

Rule Details

This rule is aimed to flag usage of function expressions in an argument list.

The following patterns are considered problems:

/*eslint prefer-arrow-callback: "error"*/

foo(function(a) { return a; });
foo(function() { return this.a; }.bind(this));

The following patterns are not considered problems:

/*eslint prefer-arrow-callback: "error"*/
/*eslint-env es6*/

foo(a => a);
foo(function*() { yield; });

// this is not a callback.
var foo = function foo(a) { return a; };

// using `this` without `.bind(this)`.
foo(function() { return this.a; });

// recursively.
foo(function bar(n) { return n && n + bar(n - 1); });

Options

This rule takes one optional argument, an object which is an options object.

allowNamedFunctions

This is a boolean option and it is false by default. When set to true, the rule doesn't warn on named functions used as callbacks.

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

/*eslint prefer-arrow-callback: ["error", { "allowNamedFunctions": true }]*/

foo(function bar() {});

allowUnboundThis

This is a boolean option and it is true by default. When set to false, this option allows the use of this without restriction and checks for dynamically assigned this values such as when using Array.prototype.map with a context argument. Normally, the rule will flag the use of this whenever a function does not use bind() to specify the value of this constantly.

Examples of incorrect code for the { "allowUnboundThis": false } option:

/*eslint prefer-arrow-callback: ["error", { "allowUnboundThis": false }]*/
/*eslint-env es6*/

foo(function() { this.a; });

foo(function() { (() => this); });

someArray.map(function (itm) { return this.doSomething(itm); }, someObject);

When Not To Use It

This rule should not be used in ES3/5 environments.

In ES2015 (ES6) or later, if you don't want to be notified about function expressions in an argument list, you can safely disable this rule. Source: http://eslint.org/docs/rules/

Use the rest parameters instead of 'arguments'.
Open

      var PhoneNumber = arguments.length <= 3 || arguments[3] === undefined ? '' : arguments[3];
Severity: Minor
Found in index.js by eslint

Suggest using the rest parameters instead of arguments (prefer-rest-params)

There are rest parameters in ES2015. We can use that feature for variadic functions instead of the arguments variable.

arguments does not have methods of Array.prototype, so it's a bit of an inconvenience.

Rule Details

This rule is aimed to flag usage of arguments variables.

Examples

Examples of incorrect code for this rule:

function foo() {
    console.log(arguments);
}

function foo(action) {
    var args = Array.prototype.slice.call(arguments, 1);
    action.apply(null, args);
}

function foo(action) {
    var args = [].slice.call(arguments, 1);
    action.apply(null, args);
}

Examples of correct code for this rule:

function foo(...args) {
    console.log(args);
}

function foo(action, ...args) {
    action.apply(null, args); // or `action(...args)`, related to the `prefer-spread` rule.
}

// Note: the implicit arguments can be overwritten.
function foo(arguments) {
    console.log(arguments); // This is the first argument.
}
function foo() {
    var arguments = 0;
    console.log(arguments); // This is a local variable.
}

When Not To Use It

This rule should not be used in ES3/5 environments.

In ES2015 (ES6) or later, if you don't want to be notified about arguments variables, then it's safe to disable this rule.

Related Rules

Unexpected var, use let or const instead.
Open

var AWS = require('aws-sdk');
Severity: Minor
Found in index.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/

Missing trailing comma.
Open

          Endpoint: Endpoint
Severity: Minor
Found in index.js by eslint

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/

Expected property shorthand.
Open

            Subject: Subject
Severity: Minor
Found in index.js by eslint

Require Object Literal Shorthand Syntax (object-shorthand)

EcmaScript 6 provides a concise form for defining object literal methods and properties. This syntax can make defining complex object literals much cleaner.

Here are a few common examples using the ES5 syntax:

// properties
var foo = {
    x: x,
    y: y,
    z: z,
};

// methods
var foo = {
    a: function() {},
    b: function() {}
};

Now here are ES6 equivalents:

/*eslint-env es6*/

// properties
var foo = {x, y, z};

// methods
var foo = {
    a() {},
    b() {}
};

Rule Details

This rule enforces the use of the shorthand syntax. This applies to all methods (including generators) defined in object literals and any properties defined where the key name matches name of the assigned variable.

Each of the following properties would warn:

/*eslint object-shorthand: "error"*/
/*eslint-env es6*/

var foo = {
    w: function() {},
    x: function *() {},
    [y]: function() {},
    z: z
};

In that case the expected syntax would have been:

/*eslint object-shorthand: "error"*/
/*eslint-env es6*/

var foo = {
    w() {},
    *x() {},
    [y]() {},
    z
};

This rule does not flag arrow functions inside of object literals. The following will not warn:

/*eslint object-shorthand: "error"*/
/*eslint-env es6*/

var foo = {
    x: (y) => y
};

Options

The rule takes an option which specifies when it should be applied. It can be set to one of the following values:

  • "always" (default) expects that the shorthand will be used whenever possible.
  • "methods" ensures the method shorthand is used (also applies to generators).
  • "properties" ensures the property shorthand is used (where the key and variable name match).
  • "never" ensures that no property or method shorthand is used in any object literal.
  • "consistent" ensures that either all shorthand or all longform will be used in an object literal.
  • "consistent-as-needed" ensures that either all shorthand or all longform will be used in an object literal, but ensures all shorthand whenever possible.

You can set the option in configuration like this:

{
    "object-shorthand": ["error", "always"]
}

Additionally, the rule takes an optional object configuration:

  • "avoidQuotes": true indicates that longform syntax is preferred whenever the object key is a string literal (default: false). Note that this option can only be enabled when the string option is set to "always", "methods", or "properties".
  • "ignoreConstructors": true can be used to prevent the rule from reporting errors for constructor functions. (By default, the rule treats constructors the same way as other functions.) Note that this option can only be enabled when the string option is set to "always" or "methods".
  • "avoidExplicitReturnArrows": true indicates that methods are preferred over explicit-return arrow functions for function properties. (By default, the rule allows either of these.) Note that this option can only be enabled when the string option is set to "always" or "methods".

avoidQuotes

{
    "object-shorthand": ["error", "always", { "avoidQuotes": true }]
}

Example of incorrect code for this rule with the "always", { "avoidQuotes": true } option:

/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/

var foo = {
    "bar-baz"() {}
};

Example of correct code for this rule with the "always", { "avoidQuotes": true } option:

/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/

var foo = {
    "bar-baz": function() {},
    "qux": qux
};

ignoreConstructors

{
    "object-shorthand": ["error", "always", { "ignoreConstructors": true }]
}

Example of correct code for this rule with the "always", { "ignoreConstructors": true } option:

/*eslint object-shorthand: ["error", "always", { "ignoreConstructors": true }]*/
/*eslint-env es6*/

var foo = {
    ConstructorFunction: function() {}
};

avoidExplicitReturnArrows

{
    "object-shorthand": ["error", "always", { "avoidExplicitReturnArrows": true }]
}

Example of incorrect code for this rule with the "always", { "avoidExplicitReturnArrows": true } option:

/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/

var foo = {
  foo: (bar, baz) => {
    return bar + baz;
  },

  qux: (foobar) => {
    return foobar * 2;
  }
};

Example of correct code for this rule with the "always", { "avoidExplicitReturnArrows": true } option:

/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/

var foo = {
  foo(bar, baz) {
    return bar + baz;
  },

  qux: foobar => foobar * 2
};

Example of incorrect code for this rule with the "consistent" option:

/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/

var foo = {
    a,
    b: "foo",
};

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

/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/

var foo = {
    a: a,
    b: "foo"
};

var bar = {
    a,
    b,
};

Example of incorrect code with the "consistent-as-needed" option, which is very similar to "consistent":

/*eslint object-shorthand: [2, "consistent-as-needed"]*/
/*eslint-env es6*/

var foo = {
    a: a,
    b: b,
};

When Not To Use It

Anyone not yet in an ES6 environment would not want to apply this rule. Others may find the terseness of the shorthand syntax harder to read and may not want to encourage it with this rule.

Further Reading

Object initializer - MDN Source: http://eslint.org/docs/rules/

Missing whitespace after semicolon.
Open

          if (err) reject(err, err.stack);else resolve(data);
Severity: Minor
Found in index.js by eslint

Enforce spacing before and after semicolons (semi-spacing)

JavaScript allows you to place unnecessary spaces before or after a semicolon.

Disallowing or enforcing space around a semicolon can improve the readability of your program.

var a = "b" ;

var c = "d";var e = "f";

Rule Details

This rule aims to enforce spacing around a semicolon. This rule prevents the use of spaces before a semicolon in expressions.

This rule doesn't check spacing in the following cases:

  • The spacing after the semicolon if it is the first token in the line.

  • The spacing before the semicolon if it is after an opening parenthesis (( or {), or the spacing after the semicolon if it is before a closing parenthesis () or }). That spacing is checked by space-in-parens or block-spacing.

  • The spacing around the semicolon in a for loop with an empty condition (for(;;)).

Options

The rule takes one option, an object, which has two keys before and after having boolean values true or false. If before is true, space is enforced before semicolons and if it's false, space is disallowed before semicolons. If after is true, space is enforced after semicolons and if it's false, space is disallowed after semicolons. The after option will be only applied if a semicolon is not at the end of line.

The default is {"before": false, "after": true}.

"semi-spacing": ["error", {"before": false, "after": true}]

{"before": false, "after": true}

This is the default option. It enforces spacing after semicolons and disallows spacing before semicolons.

Examples of incorrect code for this rule:

/*eslint semi-spacing: "error"*/

var foo ;
var foo;var bar;
throw new Error("error") ;
while (a) { break ; }
for (i = 0 ; i < 10 ; i++) {}
for (i = 0;i < 10;i++) {}

Examples of correct code for this rule:

/*eslint semi-spacing: "error"*/

var foo;
var foo; var bar;
throw new Error("error");
while (a) { break; }
for (i = 0; i < 10; i++) {}
for (;;) {}
if (true) {;}
;foo();

{"before": true, "after": false}

This option enforces spacing before semicolons and disallows spacing after semicolons.

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

/*eslint semi-spacing: ["error", { "before": true, "after": false }]*/

var foo;
var foo ; var bar;
throw new Error("error");
while (a) { break; }
for (i = 0;i < 10;i++) {}
for (i = 0; i < 10; i++) {}

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

/*eslint semi-spacing: ["error", { "before": true, "after": false }]*/

var foo ;
var foo ;var bar ;
throw new Error("error") ;
while (a) {break ;}
for (i = 0 ;i < 10 ;i++) {}

When Not To Use It

You can turn this rule off if you are not concerned with the consistency of spacing before or after semicolons.

Related Rules

  • [semi](semi.md)
  • [no-extra-semi](no-extra-semi.md)
  • [comma-spacing](comma-spacing.md)
  • [block-spacing](block-spacing.md)
  • [space-in-parens](space-in-parens.md) Source: http://eslint.org/docs/rules/

Unexpected var, use let or const instead.
Open

      var _this = this;
Severity: Minor
Found in index.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 dangling '_' in '_this'.
Open

      var _this = this;
Severity: Minor
Found in index.js by eslint

disallow dangling underscores in identifiers (no-underscore-dangle)

As far as naming conventions for identifiers go, dangling underscores may be the most polarizing in JavaScript. Dangling underscores are underscores at either the beginning or end of an identifier, such as:

var _foo;

There is actually a long history of using dangling underscores to indicate "private" members of objects in JavaScript (though JavaScript doesn't have truly private members, this convention served as a warning). This began with SpiderMonkey adding nonstandard methods such as __defineGetter__(). The intent with the underscores was to make it obvious that this method was special in some way. Since that time, using a single underscore prefix has become popular as a way to indicate "private" members of objects.

Whether or not you choose to allow dangling underscores in identifiers is purely a convention and has no effect on performance, readability, or complexity. It's purely a preference.

Rule Details

This rule disallows dangling underscores in identifiers.

Examples of incorrect code for this rule:

/*eslint no-underscore-dangle: "error"*/

var foo_;
var __proto__ = {};
foo._bar();

Examples of correct code for this rule:

/*eslint no-underscore-dangle: "error"*/

var _ = require('underscore');
var obj = _.contains(items, item);
obj.__proto__ = {};
var file = __filename;

Options

This rule has an object option:

  • "allow" allows specified identifiers to have dangling underscores
  • "allowAfterThis": false (default) disallows dangling underscores in members of the this object
  • "allowAfterSuper": false (default) disallows dangling underscores in members of the super object

allow

Examples of additional correct code for this rule with the { "allow": ["foo_", "_bar"] } option:

/*eslint no-underscore-dangle: ["error", { "allow": ["foo_", "_bar"] }]*/

var foo_;
foo._bar();

allowAfterThis

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

/*eslint no-underscore-dangle: ["error", { "allowAfterThis": true }]*/

var a = this.foo_;
this._bar();

allowAfterSuper

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

/*eslint no-underscore-dangle: ["error", { "allowAfterSuper": true }]*/

var a = super.foo_;
super._bar();

When Not To Use It

If you want to allow dangling underscores in identifiers, then you can safely turn this rule off. Source: http://eslint.org/docs/rules/

Unexpected function expression.
Open

        _this.sns.addPermission(params, function (err, data) {
Severity: Minor
Found in index.js by eslint

Suggest using arrow functions as callbacks. (prefer-arrow-callback)

Arrow functions are suited to callbacks, because:

  • this keywords in arrow functions bind to the upper scope's.
  • The notation of the arrow function is shorter than function expression's.

Rule Details

This rule is aimed to flag usage of function expressions in an argument list.

The following patterns are considered problems:

/*eslint prefer-arrow-callback: "error"*/

foo(function(a) { return a; });
foo(function() { return this.a; }.bind(this));

The following patterns are not considered problems:

/*eslint prefer-arrow-callback: "error"*/
/*eslint-env es6*/

foo(a => a);
foo(function*() { yield; });

// this is not a callback.
var foo = function foo(a) { return a; };

// using `this` without `.bind(this)`.
foo(function() { return this.a; });

// recursively.
foo(function bar(n) { return n && n + bar(n - 1); });

Options

This rule takes one optional argument, an object which is an options object.

allowNamedFunctions

This is a boolean option and it is false by default. When set to true, the rule doesn't warn on named functions used as callbacks.

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

/*eslint prefer-arrow-callback: ["error", { "allowNamedFunctions": true }]*/

foo(function bar() {});

allowUnboundThis

This is a boolean option and it is true by default. When set to false, this option allows the use of this without restriction and checks for dynamically assigned this values such as when using Array.prototype.map with a context argument. Normally, the rule will flag the use of this whenever a function does not use bind() to specify the value of this constantly.

Examples of incorrect code for the { "allowUnboundThis": false } option:

/*eslint prefer-arrow-callback: ["error", { "allowUnboundThis": false }]*/
/*eslint-env es6*/

foo(function() { this.a; });

foo(function() { (() => this); });

someArray.map(function (itm) { return this.doSomething(itm); }, someObject);

When Not To Use It

This rule should not be used in ES3/5 environments.

In ES2015 (ES6) or later, if you don't want to be notified about function expressions in an argument list, you can safely disable this rule. Source: http://eslint.org/docs/rules/

Missing whitespace after semicolon.
Open

          if (err) reject(err, err.stack);else resolve(data);
Severity: Minor
Found in index.js by eslint

Enforce spacing before and after semicolons (semi-spacing)

JavaScript allows you to place unnecessary spaces before or after a semicolon.

Disallowing or enforcing space around a semicolon can improve the readability of your program.

var a = "b" ;

var c = "d";var e = "f";

Rule Details

This rule aims to enforce spacing around a semicolon. This rule prevents the use of spaces before a semicolon in expressions.

This rule doesn't check spacing in the following cases:

  • The spacing after the semicolon if it is the first token in the line.

  • The spacing before the semicolon if it is after an opening parenthesis (( or {), or the spacing after the semicolon if it is before a closing parenthesis () or }). That spacing is checked by space-in-parens or block-spacing.

  • The spacing around the semicolon in a for loop with an empty condition (for(;;)).

Options

The rule takes one option, an object, which has two keys before and after having boolean values true or false. If before is true, space is enforced before semicolons and if it's false, space is disallowed before semicolons. If after is true, space is enforced after semicolons and if it's false, space is disallowed after semicolons. The after option will be only applied if a semicolon is not at the end of line.

The default is {"before": false, "after": true}.

"semi-spacing": ["error", {"before": false, "after": true}]

{"before": false, "after": true}

This is the default option. It enforces spacing after semicolons and disallows spacing before semicolons.

Examples of incorrect code for this rule:

/*eslint semi-spacing: "error"*/

var foo ;
var foo;var bar;
throw new Error("error") ;
while (a) { break ; }
for (i = 0 ; i < 10 ; i++) {}
for (i = 0;i < 10;i++) {}

Examples of correct code for this rule:

/*eslint semi-spacing: "error"*/

var foo;
var foo; var bar;
throw new Error("error");
while (a) { break; }
for (i = 0; i < 10; i++) {}
for (;;) {}
if (true) {;}
;foo();

{"before": true, "after": false}

This option enforces spacing before semicolons and disallows spacing after semicolons.

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

/*eslint semi-spacing: ["error", { "before": true, "after": false }]*/

var foo;
var foo ; var bar;
throw new Error("error");
while (a) { break; }
for (i = 0;i < 10;i++) {}
for (i = 0; i < 10; i++) {}

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

/*eslint semi-spacing: ["error", { "before": true, "after": false }]*/

var foo ;
var foo ;var bar ;
throw new Error("error") ;
while (a) {break ;}
for (i = 0 ;i < 10 ;i++) {}

When Not To Use It

You can turn this rule off if you are not concerned with the consistency of spacing before or after semicolons.

Related Rules

  • [semi](semi.md)
  • [no-extra-semi](no-extra-semi.md)
  • [comma-spacing](comma-spacing.md)
  • [block-spacing](block-spacing.md)
  • [space-in-parens](space-in-parens.md) Source: http://eslint.org/docs/rules/

Missing trailing comma.
Open

    }
Severity: Minor
Found in index.js by eslint

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/

Unexpected function expression.
Open

      return new Promise(function (resolve, reject) {
Severity: Minor
Found in index.js by eslint

Suggest using arrow functions as callbacks. (prefer-arrow-callback)

Arrow functions are suited to callbacks, because:

  • this keywords in arrow functions bind to the upper scope's.
  • The notation of the arrow function is shorter than function expression's.

Rule Details

This rule is aimed to flag usage of function expressions in an argument list.

The following patterns are considered problems:

/*eslint prefer-arrow-callback: "error"*/

foo(function(a) { return a; });
foo(function() { return this.a; }.bind(this));

The following patterns are not considered problems:

/*eslint prefer-arrow-callback: "error"*/
/*eslint-env es6*/

foo(a => a);
foo(function*() { yield; });

// this is not a callback.
var foo = function foo(a) { return a; };

// using `this` without `.bind(this)`.
foo(function() { return this.a; });

// recursively.
foo(function bar(n) { return n && n + bar(n - 1); });

Options

This rule takes one optional argument, an object which is an options object.

allowNamedFunctions

This is a boolean option and it is false by default. When set to true, the rule doesn't warn on named functions used as callbacks.

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

/*eslint prefer-arrow-callback: ["error", { "allowNamedFunctions": true }]*/

foo(function bar() {});

allowUnboundThis

This is a boolean option and it is true by default. When set to false, this option allows the use of this without restriction and checks for dynamically assigned this values such as when using Array.prototype.map with a context argument. Normally, the rule will flag the use of this whenever a function does not use bind() to specify the value of this constantly.

Examples of incorrect code for the { "allowUnboundThis": false } option:

/*eslint prefer-arrow-callback: ["error", { "allowUnboundThis": false }]*/
/*eslint-env es6*/

foo(function() { this.a; });

foo(function() { (() => this); });

someArray.map(function (itm) { return this.doSomething(itm); }, someObject);

When Not To Use It

This rule should not be used in ES3/5 environments.

In ES2015 (ES6) or later, if you don't want to be notified about function expressions in an argument list, you can safely disable this rule. Source: http://eslint.org/docs/rules/

Wrap an immediate function invocation in parentheses.
Open

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Severity: Minor
Found in index.js by eslint

Require IIFEs to be Wrapped (wrap-iife)

You can immediately invoke function expressions, but not function declarations. A common technique to create an immediately-invoked function expression (IIFE) is to wrap a function declaration in parentheses. The opening parentheses causes the contained function to be parsed as an expression, rather than a declaration.

// function expression could be unwrapped
var x = function () { return { y: 1 };}();

// function declaration must be wrapped
function () { /* side effects */ }(); // SyntaxError

Rule Details

This rule requires all immediately-invoked function expressions to be wrapped in parentheses.

Options

This rule has two options, a string option and an object option.

String option:

  • "outside" enforces always wrapping the call expression. The default is "outside".
  • "inside" enforces always wrapping the function expression.
  • "any" enforces always wrapping, but allows either style.

Object option:

  • "functionPrototypeMethods": true additionally enforces wrapping function expressions invoked using .call and .apply. The default is false.

outside

Examples of incorrect code for the default "outside" option:

/*eslint wrap-iife: ["error", "outside"]*/

var x = function () { return { y: 1 };}(); // unwrapped
var x = (function () { return { y: 1 };})(); // wrapped function expression

Examples of correct code for the default "outside" option:

/*eslint wrap-iife: ["error", "outside"]*/

var x = (function () { return { y: 1 };}()); // wrapped call expression

inside

Examples of incorrect code for the "inside" option:

/*eslint wrap-iife: ["error", "inside"]*/

var x = function () { return { y: 1 };}(); // unwrapped
var x = (function () { return { y: 1 };}()); // wrapped call expression

Examples of correct code for the "inside" option:

/*eslint wrap-iife: ["error", "inside"]*/

var x = (function () { return { y: 1 };})(); // wrapped function expression

any

Examples of incorrect code for the "any" option:

/*eslint wrap-iife: ["error", "any"]*/

var x = function () { return { y: 1 };}(); // unwrapped

Examples of correct code for the "any" option:

/*eslint wrap-iife: ["error", "any"]*/

var x = (function () { return { y: 1 };}()); // wrapped call expression
var x = (function () { return { y: 1 };})(); // wrapped function expression

functionPrototypeMethods

Examples of incorrect code for this rule with the "inside", { "functionPrototypeMethods": true } options:

/* eslint wrap-iife: [2, "inside", { functionPrototypeMethods: true }] */

var x = function(){ foo(); }()
var x = (function(){ foo(); }())
var x = function(){ foo(); }.call(bar)
var x = (function(){ foo(); }.call(bar))

Examples of correct code for this rule with the "inside", { "functionPrototypeMethods": true } options:

/* eslint wrap-iife: [2, "inside", { functionPrototypeMethods: true }] */

var x = (function(){ foo(); })()
var x = (function(){ foo(); }).call(bar)

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

Unexpected unnamed function.
Open

module.exports = function () {
Severity: Minor
Found in index.js by eslint

Require or disallow named function expressions (func-names)

A pattern that's becoming more common is to give function expressions names to aid in debugging. For example:

Foo.prototype.bar = function bar() {};

Adding the second bar in the above example is optional. If you leave off the function name then when the function throws an exception you are likely to get something similar to anonymous function in the stack trace. If you provide the optional name for a function expression then you will get the name of the function expression in the stack trace.

Rule Details

This rule can enforce or disallow the use of named function expressions.

Options

This rule has a string option:

  • "always" (default) requires function expressions to have a name
  • "as-needed" requires function expressions to have a name, if the name cannot be assigned automatically in an ES6 environment
  • "never" disallows named function expressions, except in recursive functions, where a name is needed

always

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

/*eslint func-names: ["error", "always"]*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

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

/*eslint func-names: ["error", "always"]*/

Foo.prototype.bar = function bar() {};

(function bar() {
    // ...
}())

as-needed

ECMAScript 6 introduced a name property on all functions. The value of name is determined by evaluating the code around the function to see if a name can be inferred. For example, a function assigned to a variable will automatically have a name property equal to the name of the variable. The value of name is then used in stack traces for easier debugging.

Examples of incorrect code for this rule with the default "as-needed" option:

/*eslint func-names: ["error", "as-needed"]*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

Examples of correct code for this rule with the default "as-needed" option:

/*eslint func-names: ["error", "as-needed"]*/

var bar = function() {};

(function bar() {
    // ...
}())

never

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

/*eslint func-names: ["error", "never"]*/

Foo.prototype.bar = function bar() {};

(function bar() {
    // ...
}())

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

/*eslint func-names: ["error", "never"]*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

Further Reading

Compatibility

Expected property shorthand.
Open

          Label: Label,
Severity: Minor
Found in index.js by eslint

Require Object Literal Shorthand Syntax (object-shorthand)

EcmaScript 6 provides a concise form for defining object literal methods and properties. This syntax can make defining complex object literals much cleaner.

Here are a few common examples using the ES5 syntax:

// properties
var foo = {
    x: x,
    y: y,
    z: z,
};

// methods
var foo = {
    a: function() {},
    b: function() {}
};

Now here are ES6 equivalents:

/*eslint-env es6*/

// properties
var foo = {x, y, z};

// methods
var foo = {
    a() {},
    b() {}
};

Rule Details

This rule enforces the use of the shorthand syntax. This applies to all methods (including generators) defined in object literals and any properties defined where the key name matches name of the assigned variable.

Each of the following properties would warn:

/*eslint object-shorthand: "error"*/
/*eslint-env es6*/

var foo = {
    w: function() {},
    x: function *() {},
    [y]: function() {},
    z: z
};

In that case the expected syntax would have been:

/*eslint object-shorthand: "error"*/
/*eslint-env es6*/

var foo = {
    w() {},
    *x() {},
    [y]() {},
    z
};

This rule does not flag arrow functions inside of object literals. The following will not warn:

/*eslint object-shorthand: "error"*/
/*eslint-env es6*/

var foo = {
    x: (y) => y
};

Options

The rule takes an option which specifies when it should be applied. It can be set to one of the following values:

  • "always" (default) expects that the shorthand will be used whenever possible.
  • "methods" ensures the method shorthand is used (also applies to generators).
  • "properties" ensures the property shorthand is used (where the key and variable name match).
  • "never" ensures that no property or method shorthand is used in any object literal.
  • "consistent" ensures that either all shorthand or all longform will be used in an object literal.
  • "consistent-as-needed" ensures that either all shorthand or all longform will be used in an object literal, but ensures all shorthand whenever possible.

You can set the option in configuration like this:

{
    "object-shorthand": ["error", "always"]
}

Additionally, the rule takes an optional object configuration:

  • "avoidQuotes": true indicates that longform syntax is preferred whenever the object key is a string literal (default: false). Note that this option can only be enabled when the string option is set to "always", "methods", or "properties".
  • "ignoreConstructors": true can be used to prevent the rule from reporting errors for constructor functions. (By default, the rule treats constructors the same way as other functions.) Note that this option can only be enabled when the string option is set to "always" or "methods".
  • "avoidExplicitReturnArrows": true indicates that methods are preferred over explicit-return arrow functions for function properties. (By default, the rule allows either of these.) Note that this option can only be enabled when the string option is set to "always" or "methods".

avoidQuotes

{
    "object-shorthand": ["error", "always", { "avoidQuotes": true }]
}

Example of incorrect code for this rule with the "always", { "avoidQuotes": true } option:

/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/

var foo = {
    "bar-baz"() {}
};

Example of correct code for this rule with the "always", { "avoidQuotes": true } option:

/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/

var foo = {
    "bar-baz": function() {},
    "qux": qux
};

ignoreConstructors

{
    "object-shorthand": ["error", "always", { "ignoreConstructors": true }]
}

Example of correct code for this rule with the "always", { "ignoreConstructors": true } option:

/*eslint object-shorthand: ["error", "always", { "ignoreConstructors": true }]*/
/*eslint-env es6*/

var foo = {
    ConstructorFunction: function() {}
};

avoidExplicitReturnArrows

{
    "object-shorthand": ["error", "always", { "avoidExplicitReturnArrows": true }]
}

Example of incorrect code for this rule with the "always", { "avoidExplicitReturnArrows": true } option:

/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/

var foo = {
  foo: (bar, baz) => {
    return bar + baz;
  },

  qux: (foobar) => {
    return foobar * 2;
  }
};

Example of correct code for this rule with the "always", { "avoidExplicitReturnArrows": true } option:

/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/

var foo = {
  foo(bar, baz) {
    return bar + baz;
  },

  qux: foobar => foobar * 2
};

Example of incorrect code for this rule with the "consistent" option:

/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/

var foo = {
    a,
    b: "foo",
};

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

/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/

var foo = {
    a: a,
    b: "foo"
};

var bar = {
    a,
    b,
};

Example of incorrect code with the "consistent-as-needed" option, which is very similar to "consistent":

/*eslint object-shorthand: [2, "consistent-as-needed"]*/
/*eslint-env es6*/

var foo = {
    a: a,
    b: b,
};

When Not To Use It

Anyone not yet in an ES6 environment would not want to apply this rule. Others may find the terseness of the shorthand syntax harder to read and may not want to encourage it with this rule.

Further Reading

Object initializer - MDN Source: http://eslint.org/docs/rules/

Severity
Category
Status
Source
Language