Skip to content

Latest commit

 

History

History
615 lines (344 loc) · 7.39 KB

es6.md

File metadata and controls

615 lines (344 loc) · 7.39 KB

Es6

enforces no braces where they can be omitted

❌ Disabled

// Good
const a = () => 0;

// Bad
const b = () => {
	return 0;
};

require parens in arrow function arguments

✅ Enabled (error)

// Bad
/*
a => {};
a => a;
a => { '\n'; };
a.then(foo => {});
a.then(foo => a);
*/

// Good
() => {};
(a) => {};
(a) => a;
(a) => { '\n'; };
a.then((foo) => {});

require space before/after arrow function's arrow

✅ Enabled (error)

// Bad
/*
()=>{};
()=> {};
() =>{};
*/

// Good
() => {};

verify super() callings in constructors

❌ Disabled


enforce the spacing around the * in generator functions

✅ Enabled (error)

// Bad
/*
function *generator() {
	yield '44';
	yield '55';
}
*/

// Good
function* generator() {
	yield '44';
	yield '55';
}

disallow modifying variables of class declarations

✅ Enabled (error)

// Bad
/*
class A { }
A = 0;
*/

disallow arrow functions where they could be confused with comparisons

✅ Enabled (error)

// Bad
/*
var x = a => 1 ? 2 : 3;
var x = (a) => 1 ? 2 : 3;
*/

// Good
var x = a => { return 1 ? 2 : 3; };
var x = (a) => { return 1 ? 2 : 3; };

disallow modifying variables that are declared using const

✅ Enabled (error)

// Bad
/*
const a = 0;
a = 1;
*/

disallow duplicate class members

✅ Enabled (error)

// Bad
/*
class Foo {
	bar() { }
	bar() { }
}

class Foo {
	bar() { }
	get bar() { }
}
*/

disallow importing from the same path more than once

✅ Enabled (error)

// Bad
/*
import { merge } from 'module';
import something from 'another-module';
import { find } from 'module';
*/

// Good
import { merge, find } from 'module';
import something from 'another-module';

disallow symbol constructor

✅ Enabled (error)

// Bad
/*
const foo = new Symbol('foo');
*/

// Good
const foo = Symbol('foo');

disallow specific imports

❌ Disabled


disallow to use this/super before super() calling in constructors.

❌ Disabled


disallow useless computed property keys

✅ Enabled (error)


disallow unnecessary constructor

✅ Enabled (error)


disallow renaming import, export, and destructured assignments to the same name

✅ Enabled (error)

// Bad
/*
import { foo as foo } from 'bar';
export { foo as foo };
export { foo as foo } from 'bar';
let { foo: foo } = bar;
let { 'foo': foo } = bar;
*/

require let or const instead of var

✅ Enabled (error)

// Bad
/*
var test = 'a';
*/

require method and property shorthand syntax for object literals

✅ Enabled (error)

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

suggest using arrow functions as callbacks

✅ Enabled (error)

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

// Good
foo((a) => { return a; });
foo(() => { return this.a; });

suggest using of const declaration for variables that are never modified after declared

✅ Enabled (error)

// Bad
/*
let a;
a = 0;

// `i` is redefined (not reassigned) on each loop step.
for (let i in [1, 2, 3]) {

}
*/

suggest using Reflect methods where applicable

❌ Disabled


use rest parameters instead of arguments

✅ Enabled (error)

// Bad
/*
function foo() {
	console.log(arguments);
}

function bar(action) {
	const args = [].slice.call(arguments, 1);
	action.apply(null, args);
}
*/

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

function bar(action, ...args) {
	action(...args);
}

suggest using the spread operator instead of .apply()

✅ Enabled (error)

// Bad
/*
foo.apply(null, args);
*/

// Good
foo(...args);

suggest using template literals instead of string concatenation

✅ Enabled (error)

// Bad
/*
const str = 'Hello, ' + name + '!';
*/

// Good
const str = `Hello, ${name}!`;

do not require jsdoc

✅ Enabled (error)

// BAD
/*
class Test {

	constructor() {
		this.test = '12';
	}
}
*/

// GOOD
/**
 * @constructor Test
 */
class Test {

	/**
	 * @returns {void}
	 */
	constructor() {
		this.test = '12';
	}
}

// OKAY
const testArrow = () => 'testArrow';

disallow generator functions that do not have yield

❌ Disabled


import sorting

❌ Disabled


enforce usage of spacing in template strings

✅ Enabled (error)

// Bad
/*
`hello, ${ people.name}!`;
`hello, ${people.name }!`;
*/

// Good
`hello, ${people.name}!`;

enforce spacing around the * in yield* expressions

✅ Enabled (error)

// Bad
/*
function* generator() {
	yield *other();
}
*/