Indent 2 spaces in first line eslint:indent
Functionhello (name) {
console.log (' Hi ', name)
}
Strings use single quotes (except to avoid escaping) eslint:quotes
Console.log (' Hello there ')
$ ("<div class= ' box ' >")
Prohibit unused variables Eslint:no-unused-vars
Functionmyfunction () {
var result =something () //✗avoid
}
Add a space after the keyword eslint:keyword-spacing
if (condition) {...} ✓ok
if (condition) {...} ✗avoid
Add a space before the parentheses of the function declaration Eslint:space-before-function-paren
functionname (ARG) {...} ✓ok
functionname (ARG) {...} ✗avoid
Run (function () {...}) ✓ok
Run (function () {...}) ✗avoid
Use strict operator = = = Replace equality operator = = except obj = null allow check NULL | | Undefined Eslint:eqeqeq
if (name = = = ' john ') //✓ok
if (name = = ' John ') //✗avoid
if (name!== ' John ') //✓ok
if (name!= ' John ') //✗avoid
Infix operators must use a single space to separate eslint:space-infix-ops
✓ok
var x = 2
var message = ' Hello, ' + name + '! '
✗avoid
var x=2
var message = ' Hello, ' +name+ '! '
The comma immediately follows a space 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) {...}
Else and the back brackets remain on the same line Eslint:brace-style
✓ok
if (condition) {//...
} else {/
/...
}
✗avoid
if (condition) {
//...
}
else {
//...
}
Multiline if declaration, using curly braces eslint:curly
✓ok
if (Options.quiet!== true) console.log (' Done ')
✓ok
if (Options.quiet!== true) {
console.log (' Done ')
}
✗avoid
if (Options.quiet!== true)
console.log (' Done ')
function parameter err must handle Eslint:handle-callback-err
✓ok
Run (function (err) {
if (err) throw err
window.alert (' Done ')
})
✗avoid
Run (function (err) {
window.alert (' Done ')
})
You must use the browser Global parameter window. prefix except Document,console,navigator eslint:no-undef
Window.alert (' Hi ') //✓ok
Multiple blank lines are not allowed Eslint:no-multiple-empty-lines
✓ok
var value = ' Hello World '
console.log (value)
✗avoid
var value = ' Hello World '
console.log (value)
When using multiple lines to write ternary expressions,? And: Placed in the owning row eslint: