30
30
本工具通过以下三种方式为你(及你的团队)节省大量时间:
31
31
32
32
- ** 无须配置。** 史上最便捷的统一代码风格的方式,轻松拥有。
33
- - ** 自动的代码格式化 。** 只需运行 ` standard --fix ` 从此和脏乱差的代码说再见。
34
- - ** 提前发现风格及程序问题。** 减少代码审查时的反反复复修改过程 ,节约时间。
33
+ - ** 自动代码格式化 。** 只需运行 ` standard --fix ` 从此和脏乱差的代码说再见。
34
+ - ** 提前发现风格及程序问题。** 减少代码审查过程中反反复复的修改过程 ,节约时间。
35
35
36
- 无须犹豫。也不用维护 ` .eslintrc ` , ` .jshintrc ` , or ` .jscsrc ` 。开箱即用。
36
+ 无须犹豫。再也不用维护 ` .eslintrc ` , ` .jshintrc ` , or ` .jscsrc ` 。开箱即用。
37
37
38
38
安装:
39
39
@@ -52,7 +52,7 @@ npm install standard --save-dev
52
52
- [ 详情] [ 4 ]
53
53
- ** 关键字后加空格** ` if (condition) { ... } `
54
54
- ** 函数名后加空格** ` function name (arg) { ... } `
55
- - 坚持使用全等 ` === ` 摒弃 ` == ` – 但在需要检查 ` null || undefined ` 时可以使用 ` obj == null ` 。
55
+ - 坚持使用全等 ` === ` 摒弃 ` == ` 一但在需要检查 ` null || undefined ` 时可以使用 ` obj == null ` 。
56
56
- 一定要处理 Node.js 中错误回调传递进来的 ` err ` 参数。
57
57
- 使用浏览器全局变量时加上 ` window ` 前缀 – ` document ` 和 ` navigator ` 除外
58
58
- 避免无意中使用到了这些命名看上去很普通的全局变量, ` open ` , ` length ` ,
@@ -157,20 +157,15 @@ $ standard "src/util/**/*.js" "test/**/*.js"
157
157
158
158
## 为何要使用 JavaScript Standard 规范?
159
159
160
- 本规范特点之一是简洁。谁也不想为每个项目维护一分有成百上千行语句的代码风格配置文件 。有此规范就够了。
160
+ 本规范特点之一是简洁。谁也不想为每个项目维护一份有成百上千行语句的代码风格配置文件 。有此规范就够了。
161
161
162
162
本工具通过以下三种方式为你(及你的团队)节省大量时间:
163
163
164
164
- ** 无须配置。** 史上最便捷的统一代码风格的方式,轻松拥有。
165
165
- ** 自动的代码格式化。** 只需运行 ` standard --fix ` 从此和脏乱差的代码说再见。
166
166
- ** 提前发现风格及程序问题。** 减少代码审查时的反反复复修改过程,节约时间。
167
167
168
- Adopting ` standard ` style means ranking the importance of code clarity and
169
- community conventions higher than personal style. This might not make sense for
170
- 100% of projects and development cultures, however open source can be a hostile
171
- place for newbies. Setting up clear, automated contributor expectations makes a
172
- project healthier.
173
- 一旦使用 ` standard ` 规范表明代码的简明性及社区的约定要高于个人的编码风格。这不一定100%适用于所有项目和从多的编程文化,但开源项目代码容易受到新手的影响。把规范讲明,严格执行对于项目的长远维护不无裨益。
168
+ 一旦使用 ` standard ` 规范表明代码的简明性及社区的约定要高于个人的编码风格。这不一定100%适用于所有项目和多元的编程文化,但开源项目代码容易受到新手的影响。把规范讲明,严格执行对于项目的长远维护不无裨益。
174
169
175
170
## 谁在用 JavaScript Standard 规范?
176
171
@@ -196,8 +191,6 @@ project healthier.
196
191
197
192
除公司组织外,[ 很多个人] ( https://raw.githubusercontent.com/feross/standard-packages/master/all.json ) 也在项目中使用,这里就不一一罗列了。
198
193
199
- ` standard ` is also the top-starred linter in GitHub's
200
- [ Clean Code Linter] ( https://github.com/showcases/clean-code-linters ) showcase.
201
194
并且 ` standard ` 在 GitHub 的[ 代码检查类工具] ( https://github.com/showcases/clean-code-linters ) 展示列表中也排名第一。
202
195
203
196
## 有现成的编辑器插件吗?
@@ -220,7 +213,7 @@ project healthier.
220
213
221
214
安装 ** [ linter-js-standard] [ atom-1 ] ** 。
222
215
223
- 如果想要保存时自动格式化,还需安装 ** [ standard-formatter] [ atom-2 ] ** 。安装 ** [ standardjs-snippets] [ atom-3 ] ** 可以获得 snippets。
216
+ 如果想要保存时自动格式化,还需安装 ** [ standard-formatter] [ atom-2 ] ** 。安装 ** [ standardjs-snippets] [ atom-3 ] ** 可以获得 snippets 特性 。
224
217
225
218
[ atom-1 ] : https://atom.io/packages/linter-js-standard
226
219
[ atom-2 ] : https://atom.io/packages/standard-formatter
@@ -317,14 +310,11 @@ WebStorm [最近宣布](https://blog.jetbrains.com/webstorm/2017/01/webstorm-201
317
310
318
311
` standard --fix ` 可以修正大部分约定俗成的问题,但有些错误(譬如忘记了错误处理)只能手动去修复了。
319
312
320
- To save you time, ` standard ` outputs the message "`Run standard --fix to
321
- automatically fix some problems`" when it detects problems that can be fixed
322
- automatically.
323
313
为了使用方便,` standard ` 会在检测到有能够自动被修复的问题的时候,给出相应的提示 "` 运行 standard --fix 来自动修正一些问题 ` "。
324
314
325
315
## 如何排除某些文件?
326
316
327
- ` node_modules/ ` , ` coverage/ ` , ` vendor/ ` , ` *.min.js ` , ` bundle.js ` 这些目录,还有以 ` . ` 开头的文件(譬如 ` .git/ ` )或者文件夹自动被排除在外。
317
+ ` node_modules/ ` 、 ` coverage/ ` 、 ` vendor/ ` 、 ` *.min.js ` 、 ` bundle.js ` 这些目录,还有以 ` . ` 开头的文件(譬如 ` .git/ ` )或者文件夹自动被排除在外。
328
318
329
319
` .gitignore ` 里配置的文件也会自动排除掉。
330
320
@@ -343,7 +333,7 @@ automatically.
343
333
344
334
## 如何隐藏某类警告?
345
335
346
- 很少的情况下你需要绕开 ` standard ` ,隐藏某些警告信息 。
336
+ 很少的情况下你需要绕开 ` standard ` 以隐藏某些警告信息 。
347
337
348
338
JavaScript Standard 代码规范底层使用的是 [ ESLint] ( http://eslint.org/ ) 。所以如果你想隐藏某些警告,方法和使用 ESLint 时一样。
349
339
@@ -479,8 +469,6 @@ $ standard --env mocha
479
469
/* eslint-env serviceworker */
480
470
```
481
471
482
- This lets ` standard ` (as well as humans reading your code) know that ` self ` is a
483
- global in web worker code.
484
472
这样可以让 ` standard ` 知道 ` self ` 是 web worker 中的全局变量(同时也让人更容易看懂)。
485
473
486
474
## Markdown 或者 HTML 文件中的代码能检查到吗?
@@ -515,7 +503,7 @@ $ standard --plugin html '**/*.html'
515
503
516
504
## 有为 git 添加 ` pre-commit ` 钩子么?
517
505
518
- 很高兴你问了 !
506
+ 这个问题问得好 !
519
507
520
508
``` sh
521
509
#! /bin/sh
0 commit comments