Eslint JavaScript Format requirements

Source: Internet
Author: User
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:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.