XOJavaScript 样式
XO 是 JavaScript 幸福样式,强制执行严格代码风格,pull request 的时候不会再讨论代码风格。没有 .eslintrc,.jshintrc,.jscsrc 管理。
基于 ESLint 使用。
代码风格:
-
Tab 缩进 或者空格
-
分号
-
单引号
-
没有未使用的变量
-
关键字后面加空格
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"
]
}
}评论
