Skip to content

Commit

Permalink
add: 补充 eslint 规则说明
Browse files Browse the repository at this point in the history
  • Loading branch information
hzm0321 committed Jul 5, 2023
1 parent 5db2bbd commit e149838
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/10.community/10.2.antv_x6.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 10

# 10.2. antv/x6

### 10.2.1. 注册
### 注册
x6 提供了注册布局、节点、边、工具栏、右键菜单等功能,但这些功能都是挂载在全局的。因此,**在退出组件的时候应当同时销毁挂载在全局的内容**,以免对其他组件造成影响。

推荐对于注册的内容,使用方法进行封装,并在返回值中包含销毁方法,以便在组件销毁时调用。例:
Expand Down
32 changes: 24 additions & 8 deletions docs/11.eslint/11.eslint.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,34 @@ sidebar_position: 11

# 11. 规范检测 eslint 插件

`eslint-plugin-hand-apaas`,用于检测汉得中台 aPaaS 项目的 TypeScript 代码的违规、错误和/或样式问题的最佳实践。请参阅配置,了解如何使用配置启用推荐的规则。
`eslint-plugin-hand-apaas`,用于检测汉得中台 aPaaS 项目的 TypeScript 代码的违规、错误和样式问题的最佳实践。请参阅配置,了解如何使用配置启用推荐的规则。

## 支持的规则


| 规则名 | 说明 | 配置项 | 提示级别 | 修复工具函数 |
|:---------------------------------------------------------------------------------:|:-----------------------------------------------------------|:---------------------------------------:|:----:|:------:|
| [hand-apaas/enum-declaration-uppercase](./eslint/11.1.enum-declaration-uppercase) | 枚举值的命名必须以大写字母开头 || 错误 | |
| [hand-apaas/no-ds-name-string](./eslint/11.2.no-ds-name-string) | DataSet 定义中不应使用字面量 string 类型作为 field 的 name 值 || 警告 | |
| [hand-apaas/import-c7n-record](./eslint/11.3.import-c7n-record) | 使用 C7NRecord 替换 Record 作为 dataSet 记录类型 || 错误 ||
| [hand-apaas/ds-event-listen](./eslint/11.4.ds-event-listen) | 在对 DataSet 的数据监听中推荐使用 useDataSetEvents 替代 addEventListener || 警告 | |
| [hand-apaas/ds-event-listen](./eslint/11.5.max-lines) | 限制 React 组件代码行数 | { warnLine: number, errorLine: number } | 警告 | |
| 规则名 | 说明 | 配置项 | 提示级别 | 修复工具函数 |
|:---------------------------------------------------------------------------------:|:-----------------------------------------------------------|:---------------------------------------:|:-------:|:------:|
| [hand-apaas/enum-declaration-uppercase](./eslint/11.1.enum-declaration-uppercase) | 枚举值的命名必须以大写字母开头 || | |
| [hand-apaas/no-ds-name-string](./eslint/11.2.no-ds-name-string) | DataSet 定义中不应使用字面量 string 类型作为 field 的 name 值 || <warn/> | |
| [hand-apaas/import-c7n-record](./eslint/11.3.import-c7n-record) | 使用 C7NRecord 替换 Record 作为 dataSet 记录类型 || ||
| [hand-apaas/ds-event-listen](./eslint/11.4.ds-event-listen) | 在对 DataSet 的数据监听中推荐使用 useDataSetEvents 替代 addEventListener || <warn/> | |
| [hand-apaas/ds-event-listen](./eslint/11.5.max-lines) | 限制 React 组件代码行数 | { warnLine: number, errorLine: number } | <warn/> | |

## 其他规则


| 规则名 | 说明 | 配置项 | 提示级别 | 修复工具函数 |
|:--------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------:|:-------:|:------:|
| [@typescript-eslint/adjacent-overload-signatures](https://typescript-eslint.io/rules/adjacent-overload-signatures) | 要求函数重载签名是连续的 ||| |
| [@typescript-eslint/array-type](https://typescript-eslint.io/rules/array-type) | 对简单类型(即只是原始类型或类型引用的类型)使用 `T[]``readonly T[]` 。将 `Array<T>``ReadonlyArray<T>` 用于所有其他类型(联合类型、交集类型、对象类型、函数类型等) | {"default": "array-simple","readonly": "array-simple"} || |
| [@typescript-eslint/consistent-type-definitions](https://typescript-eslint.io/rules/consistent-type-definitions) | 类型定义一致地使用 interface 或 type || <warn/> | |
| [@typescript-eslint/member-ordering](https://typescript-eslint.io/rules/member-ordering) | 需要一致的成员声明顺序 | {"default": {"optionalityOrder": "required-first","order": "alphabetically"}} || |
| [@typescript-eslint/no-confusing-non-null-assertion](https://typescript-eslint.io/rules/no-confusing-non-null-assertion) | 禁止在可能造成混淆的位置使用非空断言 ||| |
| [@typescript-eslint/no-duplicate-enum-values](https://typescript-eslint.io/rules/no-confusing-non-null-assertion) | 不允许重复的枚举成员值 ||| |
| [@typescript-eslint/no-extra-non-null-assertion](https://typescript-eslint.io/rules/no-extra-non-null-assertion) | 不允许额外的非空断言 ||| |
| [@typescript-eslint/no-non-null-asserted-optional-chain](https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain) | 不允许在可选链表达式之后使用非空断言 ||| |
| [@typescript-eslint/no-redundant-type-constituents](https://typescript-eslint.io/rules/no-redundant-type-constituents) | 禁止不执行任何操作或覆盖类型信息的联合和交叉点的成员 ||| |
| [@typescript-eslint/no-unnecessary-boolean-literal-compare](https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare) | 不允许对布尔文本进行不必要的相等比较 ||| |
| [@typescript-eslint/no-unnecessary-type-constraint](https://typescript-eslint.io/rules/no-unnecessary-type-constraint) | 不允许对泛型类型进行不必要的约束 ||| |

<maintainer authors={["hzm"]}/>
21 changes: 21 additions & 0 deletions docs/3.language-featuremd.md
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,27 @@ function func() {
const list = ['a', 'b', 'c'] as const; // 只读的元组属性 readonly ['a', 'b', 'c']
```

#### 3.19.4. 非空断言不与等于检查相邻
<intro type="forbidden" />

禁止非空断言(`!`)与等于检查( `=``==``===` )相邻,因为这样会造成歧义。它看起来类似于不等于检查( `!=` `!==` )。

```ts
interface Foo {
bar?: string;
num?: number;
}

const foo: Foo = getFoo();
// 以下写法会造成歧义å
const isEqualsBar = foo.bar! == 'hello';
const isEqualsNum = 1 + foo.num! == 2;

// 必须使用下面这种写法
const isEqualsBar = foo.bar == 'hello';
const isEqualsNum = (1 + foo.num!) == 2;
```

### 3.20. 成员属性声明

<intro type="must" />
Expand Down
7 changes: 7 additions & 0 deletions src/theme/MDXComponents/IconWarn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React, { useMemo } from 'react';
import {WarningFilled} from '@ant-design/icons';

export default function MDXWarn() {

return <WarningFilled style={{ color: '#ffcd36', fontSize: 20 }} />;
}
2 changes: 2 additions & 0 deletions src/theme/MDXComponents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import MDXImg from '@theme/MDXComponents/Img';
import Admonition from '@theme/Admonition';
import Intro from './Intro';
import Maintainer from './Maintainer';
import IconWarn from './IconWarn';
const MDXComponents = {
head: MDXHead,
code: MDXCode,
Expand All @@ -27,5 +28,6 @@ const MDXComponents = {
admonition: Admonition,
intro: Intro,
maintainer: Maintainer,
warn: IconWarn,
};
export default MDXComponents;

0 comments on commit e149838

Please sign in to comment.