Skip to content

Latest commit

 

History

History
201 lines (197 loc) · 3.61 KB

ECMAScript6.md

File metadata and controls

201 lines (197 loc) · 3.61 KB

ECMAScript 6

Rule Description Snippet ESLint Default Link
arrow-parens Require parens in arrow function arguments
// Bad
a => {}
// Good
(a) => {}
Off [Link](http://eslint.org/docs/rules/arrow-parens)
arrow-spacing Require space before/after arrow function's arrow
// { "before": true, "after": true }
(a) => {}
// { "before": false, "after": false }
(a)=>{}
Off [Link](http://eslint.org/docs/rules/arrow-spacing)
constructor-super Verify calls of `super()` in constructors
class A {
    constructor() {
        super(); // unexpected `super()`.
    }
}
Off [Link](http://eslint.org/docs/rules/constructor-super)
generator-star-spacing Enforce spacing around the `*` in generator functions
function* generator() {}
function *generator() {}
function * generator() {}
Off [Link](http://eslint.org/docs/rules/generator-star-spacing)
no-class-assign Disallow modifying variables of class declarations
class A { }
A = 0;
Off [Link](http://eslint.org/docs/rules/no-class-assign)
no-const-assign Disallow modifying variables that are declared using `const`
const a = 0;
a = 1;
Off [Link](http://eslint.org/docs/rules/no-const-assign)
no-this-before-super Disallow use of `this`/`super` before calling `super()` in constructors
class A extends B {
    constructor() {
        this.a = 0; // this is before `super()`.
        super();
    }
}
Off [Link](http://eslint.org/docs/rules/no-this-before-super)
no-var Require `let` or `const` instead of `var`
var x = "y";
var CONFIG = {};

let x = "y"; const CONFIG = {};

Off [Link](http://eslint.org/docs/rules/no-var)
object-shorthand Require method and property shorthand syntax for object literals
var foo = {
    a: function() {},
    b: function() {}
};

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

Off [Link](http://eslint.org/docs/rules/object-shorthand)
prefer-const Suggest using `const` declaration for variables that are never modified after declared
for (let i in [1,2,3]) { // `i` is re-defined (not modified) on each loop step.
    console.log(i);
}
Off [Link](http://eslint.org/docs/rules/prefer-const)
prefer-spread Suggest using the spread operator instead of `.apply()`
var args = [1, 2, 3, 4];
Math.max.apply(Math, args);

var args = [1, 2, 3, 4]; Math.max(...args);

Off [Link](http://eslint.org/docs/rules/prefer-spread)
prefer-reflect Suggest using Reflect methods where applicable
foo.apply(undefined, args);
obj.foo.apply(obj, args);

foo.call(undefined, arg); obj.foo.call(obj, arg);

Off [Link](http://eslint.org/docs/rules/prefer-reflect)
require-yield Disallow generator functions that do not have `yield`
function* foo() {
  yield 5;
  return 10;
}
Off [Link](http://eslint.org/docs/rules/require-yield)