Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dogodo-cc committed Jun 9, 2024
1 parent 3dfa79e commit 9cb2f13
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 1,098 deletions.
62 changes: 0 additions & 62 deletions .github/workflows/deploy-oss.yml

This file was deleted.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ cocos creator FE team

由于使用了 npm@7 的 workspace 功能,所以 `node` 版本需要在 16 以上。 推荐使用 `nvm` 来管理 `node` 版本。

[cocos-fe 官网](https://cocos-creator.github.io/fe-team/)
## Eslint

[npm 下载地址](https://www.npmjs.com/package/@cocos-fe/eslint-config)

## 构建插件

[ npm 下载地址 ](https://www.npmjs.com/package/@cocos-fe/hello-build)

## 本地引用

Expand Down
128 changes: 116 additions & 12 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,130 @@
# Eslint config
# Eslint 配置

## 安装

[使用教程](http://cocos.90s.co/core/eslint.html)
```
npm install @cocos-fe/eslint-config --save-dev
```

## 使用

出于约束规范 & 保持配置灵活性的原则,我们的公共配置里只包含了 `extends``rules` 两个配置,其他包括 `parser``plugins` 等一律由具体项目自行配置。

针对引擎项目和编辑器项目分别暴露了独立的拓展配置:

### 引擎项目

```js{9}
module.exports = {
"root": true,
"parser": '@typescript-eslint/parser',
"plugins": [
'@typescript-eslint',
],
"extends": [
'plugin:@typescript-eslint/recommended',
"@cocos-fe/eslint-config/engine",
],
};
```

### 编辑器项目

```js{9}
module.exports = {
"root": true,
"parser": '@typescript-eslint/parser',
"plugins": [
'@typescript-eslint',
],
"extends": [
'plugin:@typescript-eslint/recommended',
"@cocos-fe/eslint-config/editor",
],
};
```

### 编辑器甜点包

由于编辑器项目会使用到 `vue` 这类非常规后缀的文件,配置上稍显麻烦,所以我们提供了一份完备的针对 `vue3` 的拓展配置如下:

```js {6,12-14, 16, 18}
module.exports = {
env: {
browser: true,
node: true,
es2021: true,
'vue/setup-compiler-macros': true,
},
globals: {
Editor: 'readonly',
},
extends: ['plugin:vue/vue3-recommended', 'plugin:@typescript-eslint/recommended', './extend-editor.js'],
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
plugins: ['vue', '@typescript-eslint'],
};
```

所以编辑器项目如果不想自己做这些繁琐的配置,可以直接按照如下引入:

```js {4}
module.exports = {
root: true,
extends: ['@cocos-fe/eslint-config'],
};
```

## 规则定制哲学

定制团队的公共规范,并不是需要我们从头到位定制一份长长的 `rules`,我们需要的是一份`标准规范`,且一起遵守它。(定制规范不是我们的核心业务,大可不必浪费时间)

所以我们公共配置的原则就是统一引入业界的标准规范,并根据实际情况做一些规则复写。

所以我们的规则如下:

- 引入 Eslint 官方推荐的规则
- 引入 Vue 官方推荐的规则
- 引入 Ts 官方推荐规则
- 维护一份少量的自有规则,以达到我们的特殊目的

```js
module.exports = {
extends: ['eslint:recommended', 'plugin:vue/vue3-recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
// 额外定制一丢丢规则
},
};
```

仅此而已!

## 参考链接

- [node exports](https://nodejs.org/api/packages.html#package-entry-points)
- [eslint](https://eslint.org/)
- [typescritp-eslint](https://typescript-eslint.io/docs/linting/)
- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser)
- [node exports](https://nodejs.org/api/packages.html#package-entry-points)
- [eslint](https://eslint.org/)
- [typescritp-eslint](https://typescript-eslint.io/docs/linting/)
- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser)

## 备忘

**规则值说明**
- "off" or 0 - 关闭规则
- "warn" or 1 - 将规则视为一个警告(不会影响退出码)
- "error" or 2 - 将规则视为一个错误 (退出码为1)

- "off" or 0 - 关闭规则
- "warn" or 1 - 将规则视为一个警告(不会影响退出码)
- "error" or 2 - 将规则视为一个错误 (退出码为 1)

**关闭规则验证**
- 当前文件: /* eslint-disable no-console */
- 下一行: /* eslint-disable-next-line */
- 当前行: /* eslint-disable-line no-alert */

- 当前文件: /_ eslint-disable no-console _/
- 下一行: /_ eslint-disable-next-line _/
- 当前行: /_ eslint-disable-line no-alert _/

如果规则不生效,可以按 cmd + p 唤起功能搜索面板,按 F1,选择 Eslint: restart eslint server。
21 changes: 0 additions & 21 deletions projects/document/docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@ const config = defineConfig({
link: '/docs/',
activeMatch: '^/docs/',
},
{
text: '基建',
link: '/core/',
activeMatch: '^/core/',
},
],

sidebar: {
'/docs/': getArticleSidebar(),
'/core/': getCoreSidebar(),
},

footer: {
Expand Down Expand Up @@ -65,18 +59,3 @@ function getArticleSidebar() {
},
];
}

function getCoreSidebar() {
return [
{
text: '基建',
items: [
{ text: 'Eslint', link: '/core/eslint' },
{ text: 'Eslint 工作流', link: '/core/eslint-工作流' },
{ text: 'nvm 安装', link: '/core/nvm/install' },
{ text: 'nvm 命令行执行', link: '/core/nvm/nvm-spawn' },
{ text: '编辑器插件构建', link: '/core/hello-build' },
],
},
];
}
127 changes: 0 additions & 127 deletions projects/document/docs/core/eslint-工作流.md

This file was deleted.

Loading

0 comments on commit 9cb2f13

Please sign in to comment.