eslint: semi
var x = 5 // ✗ avoid
var x = 5; // ✓ ok
eslint: indent
// ✗ avoid
function hello(name) {
console.log('hi', name);
}
// ✓ ok
function hello(name) {
console.log('hi', name);
}
eslint: id-length
eslint: camelcase
// ✗ avoid
const OBJEcttsssss = {};
const this_is_my_object = {};`
const miObjecto = {};
function c() {}
// ✓ ok
const thisIsMyObject = {};
function thisIsMyFunction() {}
eslint: keyword-spacing
if (condition) { ... } // ✓ ok
if(condition) { ... } // ✗ avoid
Except increment and decrement operators (for example, i++
or i--
).
eslint: space-infix-ops
// ✗ avoid
var x=2;
var message = 'hello, '+name+'!';
// ✓ ok
var x = 2;
var message = 'hello, ' + name + '!';
Except at the end of the line.
eslint: comma-spacing
// ✓ ok
var list = [1, 2, 3, 4];
function greet(name, options) { ... }
// ✗ avoid
var list = [1,2,3,4];
function greet(name,options) { ... }
eslint: space-before-blocks
if (admin){...} // ✗ avoid
if (admin) {...} // ✓ ok
eslint: spaced-comment
//comment // ✗ avoid
// comment // ✓ ok
/*comment*/ // ✗ avoid
/* comment */ // ✓ ok
eslint: key-spacing
var obj = { 'key' : 'value' }; // ✗ avoid
var obj = { 'key' :'value' }; // ✗ avoid
var obj = { 'key':'value' }; // ✗ avoid
var obj = { 'key': 'value' }; // ✓ ok
eslint: no-multi-spaces
const id = 1234; // ✗ avoid
const id = 1234; // ✓ ok
eslint: space-in-parens
getName( name ) // ✗ avoid
getName(name) // ✓ ok
eslint: space-before-function-paren
function name (arg) { ... } // ✗ avoid
function name(arg) { ... } // ✓ ok
run(function () { ... }) // ✗ avoid
run(function() { ... }) // ✓ ok
eslint: func-call-spacing
console.log ('hello'); // ✗ avoid
console.log('hello'); // ✓ ok
eslint: no-multiple-empty-lines
// ✗ avoid
var value = 'hello world';
console.log(value);
// ✓ ok
var value = 'hello world';
console.log(value);
eslint: padded-blocks
if (user) {
// ✗ avoid
const name = getName();
}
if (user) {
const name = getName(); // ✓ ok
}
Except when you need to use single quotes in your string.
eslint: quotes
var str = "hi"; // ✗ avoid
var str = 'hi'; // ✓ ok
eslint: no-floating-decimal
const discount = .5; // ✗ avoid
const discount = 0.5; // ✓ ok
eslint: object-property-newline
const user = {
name: 'Jane Doe', age: 30,
username: 'jdoe86' // ✗ avoid
};
const user = { name: 'Jane Doe', age: 30, username: 'jdoe86' }; // ✗ avoid
const user = {
name: 'Jane Doe',
age: 30,
username: 'jdoe86' // ✓ ok
};
eslint: brace-style
// ✗ avoid
if (condition) {
// ...
}
else {
// ...
}
// ✓ ok
if (condition) {
// ...
} else {
// ...
}
Exception: obj == null is allowed to check for null || undefined.
eslint: eqeqeq
if (name == 'John') // ✗ avoid
if (name === 'John') // ✓ ok
if (name != 'John') // ✗ avoid
if (name !== 'John') // ✓ ok
eslint: no-array-constructor
var nums = new Array(1, 2, 3); // ✗ avoid
var nums = [1, 2, 3]; // ✓ ok