Skip to content

Commit d636f4f

Browse files
committed
improve(eslilnt-config-ts-lib): 新增 arrow-body-style 规则
1 parent 4151042 commit d636f4f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# arrow-body-style
2+
3+
> 来自 [eslint](https://eslint.org/docs/rules/) 的规则。
4+
5+
> ts-lib-scripts 推荐使用。遵循简洁的原则。
6+
7+
> 当箭头函数体的大括号是可以省略的,则强制不使用它们。
8+
9+
## 示例
10+
11+
### 错误用法
12+
13+
```javascript
14+
const foo = () => {
15+
return 0;
16+
};
17+
18+
const foo = () => {
19+
return {
20+
bar: {
21+
foo: 1,
22+
bar: 2,
23+
},
24+
};
25+
};
26+
```
27+
28+
### 正确用法
29+
30+
```javascript
31+
let foo = () => 0;
32+
let foo = () => ({
33+
bar: {
34+
foo: 1,
35+
bar: 2,
36+
},
37+
});
38+
```
39+
40+
## 参考文档
41+
42+
- [arrow-body-style 官方文档](https://eslint.org/docs/rules/arrow-body-style)
43+
- [arrow-body-style 中文教程](https://eslint.cn/docs/rules/arrow-body-style)

packages/eslint-config-ts-lib/rules/function-rules.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const functionRules = {
2525
],
2626
'@typescript-eslint/explicit-function-return-type': 0,
2727
'no-empty-function': 'off',
28+
'arrow-body-style': ['error', 'as-needed'],
2829
};
2930

3031
module.exports = functionRules;

0 commit comments

Comments
 (0)