Skip to content

Commit c689a80

Browse files
committed
更新
1 parent 95e3eed commit c689a80

File tree

7 files changed

+133
-8
lines changed

7 files changed

+133
-8
lines changed

.eslintrc.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,66 @@ module.exports = {
1212
parser: 'babel-eslint',
1313
installedESLint: true,
1414
parserOptions: {
15-
// ecmaVersion: 6,
15+
ecmaVersion: 8,
1616
sourceType: 'module',
17+
"ecmaFeatures": {
18+
"jsx": true,
19+
// lambda表达式
20+
"arrowFunctions": true,
21+
// 块级作用域,允许使用let const
22+
"blockBindings": true,
23+
// class
24+
"classes": true,
25+
// http://es6.ruanyifeng.com/#docs/function#函数参数的默认值
26+
"defaultParams": true,
27+
// 解构赋值
28+
"destructuring": true,
29+
// http://es6.ruanyifeng.com/#docs/object#对象的扩展运算符
30+
"experimentalObjectRestSpread": true,
31+
// http://es6.ruanyifeng.com/#docs/iterator#for---of循环
32+
"forOf": true,
33+
// http://es6.ruanyifeng.com/#docs/generator
34+
"generators": true,
35+
// 允许使用模块,模块内默认严格模式
36+
"modules": true,
37+
// 允许字面量定义对象时,用表达式做属性名
38+
// http://es6.ruanyifeng.com/#docs/object#属性名表达式
39+
"objectLiteralComputedProperties": true,
40+
// 允许对象字面量方法名简写
41+
/*var o = {
42+
method() {
43+
return "Hello!";
44+
}
45+
};
46+
47+
等同于
48+
49+
var o = {
50+
method: function() {
51+
return "Hello!";
52+
}
53+
};
54+
*/
55+
"objectLiteralShorthandMethods": true,
56+
/*
57+
对象字面量属性名简写
58+
var foo = "bar";
59+
var baz = {foo};
60+
baz // {foo: "bar"}
61+
62+
// 等同于
63+
var baz = {foo: foo};
64+
*/
65+
"objectLiteralShorthandProperties": true,
66+
// http://es6.ruanyifeng.com/#docs/function#rest参数
67+
"restParams": true,
68+
// http://es6.ruanyifeng.com/#docs/function#扩展运算符
69+
"spread": true,
70+
"superInFunctions": true,
71+
// http://es6.ruanyifeng.com/#docs/string#模板字符串
72+
"templateStrings": true,
73+
"unicodeCodePointEscapes": true,
74+
},
1775
},
1876
globals: {
1977
Vue: false,

docs/config-eslint.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ NOTE: 目前(20170216) VSCode 的提示不允许外链,所以 eslint 插件的
119119

120120
### 其他配置及使用
121121

122+
**编辑器快捷加载项目**
123+
122124
推荐使用 [zsh](http://ohmyz.sh/),配合插件[z](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/z)实现跟踪/跳转你最常用的目录,配置 plugins=(z)即可。
123125

124126
如此,想要打开一个项目 protest,直接如下即可
@@ -131,4 +133,38 @@ NOTE: 目前(20170216) VSCode 的提示不允许外链,所以 eslint 插件的
131133
# code .
132134
```
133135

136+
**同步配置**
137+
134138
推荐安装 Settings Sync 插件,同步自己的配置到云端。
139+
140+
**Code Runner**
141+
142+
使用 Code Runner 插件,支持右键运行代码(使用 node),由于有些新的语法,即使最新版的 node 也不支持,需要借助 babel-cli 以及如下插件来实现。
143+
144+
babel-cli 工具自带一个 babel-node 命令,提供一个支持ES6的REPL环境。它支持Node的REPL环境的所有功能,而且可以直接运行ES6代码。而配合 babel-preset-stage-0 则可以直接支持 ES2017
145+
146+
Code Runner 配置如下:
147+
148+
```
149+
"code-runner.executorMap": {
150+
"javascript": "babel-node --presets stage-0"
151+
}
152+
153+
NOTE: babel-preset-stage-0 必须要安装到项目目录才可以被引用,安装全局是不行的。
154+
```
155+
156+
其他插件参考:
157+
158+
```
159+
# ES2015转码规则
160+
$ npm install --save-dev babel-preset-es2015
161+
162+
# react转码规则
163+
$ npm install --save-dev babel-preset-react
164+
165+
# ES7不同阶段语法提案的转码规则(共有4个阶段),选装一个
166+
$ npm install --save-dev babel-preset-stage-0
167+
$ npm install --save-dev babel-preset-stage-1
168+
$ npm install --save-dev babel-preset-stage-2
169+
$ npm install --save-dev babel-preset-stage-3
170+
```

docs/es6.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ console.log(type122[0], type122[0])
3737

3838

3939
// [函数](#functions)
40+
(function anonymous() {
41+
// bad
42+
const original = { a: 1, b: 2 }
43+
const copy = Object.assign({}, original, { c: 3 })
44+
console.log(copy)
45+
})()
46+
47+
(function anonymous() {
48+
// bad
49+
const original = { a: 1, b: 2 }
50+
const copy = { ...original, c: 3 }
51+
// const { ...copy } = original
52+
console.log(copy)
53+
})()
4054

4155

4256
// [箭头函数](#arrow-functions)

docs/es6_zh-cn_v3.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66

77
翻译自 [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)
88

9-
NOTE: 本文对[Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) 略有调整具体如下,
9+
NOTE: Airbnb 规则非常超前,在编译时,ES6无法完全支持,如对象扩展运算符是 ES2017 引入的,此时,需要使用 [stage-0](http://www.cnblogs.com/chris-oil/p/5717544.html) 等设置来支持,另外使用规范时注意以下部分略有调整。
10+
11+
```
12+
// 使用右键 Run Code 时,有些语法是不支持的,这是因为 node 的环境还不支持
13+
// 此时可以使用 babel-node 加载 babel-preset-stage-0 来获得对新语法的支持
14+
15+
"code-runner.executorMap": {
16+
"javascript": "babel-node --presets stage-0"
17+
}
18+
19+
NOTE: babel-preset-stage-0 必须要安装到项目目录才可以被引用,安装全局是不行的。
20+
```
1021

1122
- 尾逗号单行不要有,多行必须有。修改规则 `comma-dangle: ['error', 'never']` 中 never 改为 always-multiline。
1223
- 行尾不要分号。调整后,代码更干净、整洁,但要注意 (, [, + , -, or ` 开头的语句,可能在“自动分号插入”机制(ASI)下会有问题。<br>
@@ -352,7 +363,9 @@ Other Style Guides
352363
<a name="objects--rest-spread"></a>
353364
- [3.8](#objects--rest-spread) 浅拷贝使用对象扩展符(rest operator)更好,相对于方法 [`Object.assign`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) 而言。
354365

355-
???: 可以深拷贝么?
366+
NOTE: Object.assign 实行的是浅拷贝,而不是深拷贝。其拷贝的属性是有限制的,只拷贝源对象的自身属性(不拷贝继承属性),也不拷贝不可枚举的属性(enumerable: false)。
367+
368+
扩展运算符可以深拷贝么?可以。
356369

357370
```javascript
358371
// very bad

linters/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module.exports = {
9999
// impliedStric
100100
// "impliedStrict": true,
101101
// 启用 JSX
102-
// "jsx": true
102+
"jsx": true,
103103
// lambda表达式
104104
"arrowFunctions": true,
105105
// 块级作用域,允许使用let const

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@
3131
"bugs": {
3232
"url": "https://github.com/airbnb/javascript/issues"
3333
},
34-
"homepage": "https://github.com/airbnb/javascript"
34+
"homepage": "https://github.com/airbnb/javascript",
35+
"devDependencies": {
36+
"babel-preset-es2015": "^6.22.0",
37+
"babel-preset-stage-0": "^6.22.0"
38+
}
3539
}

react/zh-cn.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ source: https://github.com/JasonBoy/javascript/tree/master/react
8484

8585
## Naming 命名
8686

87-
- **扩展名**: React模块使用 `.jsx` 扩展名.
88-
 - **文件名**: 文件名使用帕斯卡命名. 如, `ReservationCard.jsx`.
89-
 - **引用命名**: React模块名使用帕斯卡命名,实例使用骆驼式命名.
87+
- **扩展名**: React模块使用 `.jsx` 扩展名
88+
 - **文件名**: 文件名使用帕斯卡命名如, `ReservationCard.jsx`
89+
 - **引用命名**: React模块名使用帕斯卡命名,实例使用骆驼式命名
9090
eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md)
9191

9292
```jsx

0 commit comments

Comments
 (0)