svtek/aws-sms-send

View on GitHub

Showing 59 of 59 total issues

Function exports has 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function () {
  function Sender(config) {
    _classCallCheck(this, Sender);

    this.AWS = AWS.config.update(config.AWS);
Severity: Major
Found in index.js - About 2 hrs to fix

    Function _createClass has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    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 - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Strings must use singlequote.
    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

    enforce the consistent use of either backticks, double, or single quotes (quotes)

    JavaScript allows you to define strings in one of three ways: double quotes, single quotes, and backticks (as of ECMAScript 6). For example:

    /*eslint-env es6*/
    
    var double = "double";
    var single = 'single';
    var backtick = `backtick`;    // ES6 only

    Each of these lines creates a string and, in some cases, can be used interchangeably. The choice of how to define strings in a codebase is a stylistic one outside of template literals (which allow embedded of expressions to be interpreted).

    Many codebases require strings to be defined in a consistent manner.

    Rule Details

    This rule enforces the consistent use of either backticks, double, or single quotes.

    Options

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

    String option:

    • "double" (default) requires the use of double quotes wherever possible
    • "single" requires the use of single quotes wherever possible
    • "backtick" requires the use of backticks wherever possible

    Object option:

    • "avoidEscape": true allows strings to use single-quotes or double-quotes so long as the string contains a quote that would have to be escaped otherwise
    • "allowTemplateLiterals": true allows strings to use backticks

    Deprecated: The object property avoid-escape is deprecated; please use the object property avoidEscape instead.

    double

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

    /*eslint quotes: ["error", "double"]*/
    
    var single = 'single';
    var unescaped = 'a string containing "double" quotes';

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

    /*eslint quotes: ["error", "double"]*/
    /*eslint-env es6*/
    
    var double = "double";
    var backtick = `back\ntick`;  // backticks are allowed due to newline
    var backtick = tag`backtick`; // backticks are allowed due to tag

    single

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

    /*eslint quotes: ["error", "single"]*/
    
    var double = "double";
    var unescaped = "a string containing 'single' quotes";

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

    /*eslint quotes: ["error", "single"]*/
    /*eslint-env es6*/
    
    var single = 'single';
    var backtick = `back${x}tick`; // backticks are allowed due to substitution

    backticks

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

    /*eslint quotes: ["error", "backtick"]*/
    
    var single = 'single';
    var double = "double";
    var unescaped = 'a string containing `backticks`';

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

    /*eslint quotes: ["error", "backtick"]*/
    /*eslint-env es6*/
    
    var backtick = `backtick`;

    avoidEscape

    Examples of additional correct code for this rule with the "double", { "avoidEscape": true } options:

    /*eslint quotes: ["error", "double", { "avoidEscape": true }]*/
    
    var single = 'a string containing "double" quotes';

    Examples of additional correct code for this rule with the "single", { "avoidEscape": true } options:

    /*eslint quotes: ["error", "single", { "avoidEscape": true }]*/
    
    var double = "a string containing 'single' quotes";

    Examples of additional correct code for this rule with the "backtick", { "avoidEscape": true } options:

    /*eslint quotes: ["error", "backtick", { "avoidEscape": true }]*/
    
    var double = "a string containing `backtick` quotes"

    allowTemplateLiterals

    Examples of additional correct code for this rule with the "double", { "allowTemplateLiterals": true } options:

    /*eslint quotes: ["error", "double", { "allowTemplateLiterals": true }]*/
    
    var double = "double";
    var double = `double`;

    Examples of additional correct code for this rule with the "single", { "allowTemplateLiterals": true } options:

    /*eslint quotes: ["error", "single", { "allowTemplateLiterals": true }]*/
    
    var single = 'single';
    var single = `single`;

    When Not To Use It

    If you do not need consistency in your string styles, you can safely disable this rule. Source: http://eslint.org/docs/rules/

    Unexpected unnamed function.
    Open

            _this2.sns.subscribe(subscribeParams, function (err, data) {
    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

    Unexpected var, use let or const instead.
    Open

          var PhoneNumber = arguments.length <= 3 || arguments[3] === undefined ? '' : arguments[3];
    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 unnamed function.
    Open

          return new Promise(function (resolve, reject) {
    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

    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

    Unary operator '++' used.
    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

    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/

    Wrap an immediate function invocation in parentheses.
    Open

    module.exports = function () {
    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/

    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 unnamed function.
    Open

          return new Promise(function (resolve, reject) {
    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

    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/

    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/

    Unexpected dangling '_' in '_classCallCheck'.
    Open

    function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
    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 var, use let or const instead.
    Open

            var params = {
    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 var, use let or const instead.
    Open

          var _this3 = 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/

    Missing trailing comma.
    Open

                TopicArn: _this3.topicArn
    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 dangling '_' in '_createClass'.
    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

    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/

    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

            _this.sns.addPermission(params, function (err, data) {
    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

    Severity
    Category
    Status
    Source
    Language