XOJavaScript 樣式
XO 是 JavaScript 幸福樣式,強(qiáng)制執(zhí)行嚴(yán)格代碼風(fēng)格,pull request 的時(shí)候不會(huì)再討論代碼風(fēng)格。沒(méi)有 .eslintrc,.jshintrc,.jscsrc 管理。
基于 ESLint 使用。
代碼風(fēng)格:
-
Tab 縮進(jìn) 或者空格
-
分號(hào)
-
單引號(hào)
-
沒(méi)有未使用的變量
-
關(guān)鍵字后面加空格
if (condition) {} -
總是使用
===代替==
安裝:
$ npm install --global xo
使用:
$ xo --help Usage $ xo [<file|glob> ...] Options --init Add XO to your project --compact Compact output --stdin Validate code from stdin --esnext Enable ES2015 support and rules --env Environment preset [Can be set multiple times] --global Global variable [Can be set multiple times] --ignore Additional paths to ignore [Can be set multiple times] --space Use space indent instead of tabs [Default: 2] --no-semicolon Prevent use of semicolons Examples $ xo $ xo index.js $ xo *.js !foo.js $ xo --esnext --space $ xo --env=node --env=mocha $ xo --init --esnext Tips Put options in package.json instead of using flags so other tools can read it.
之前:
{
"name": "awesome-package",
"scripts": {
"test": "mocha"
},
"devDependencies": {
"mocha": "^2.0.0"
}
}
之后:
{
"name": "awesome-package",
"scripts": {
"test": "xo && mocha"
},
"devDependencies": {
"mocha": "^2.0.0",
"xo": "^0.8.0"
}
}
配置:
{
"name": "awesome-package",
"xo": {
"envs": [
"node",
"mocha"
]
}
}評(píng)論
圖片
表情
