# eslint-config-alloy
**Repository Path**: ctrlv-git/alloy
## Basic Information
- **Project Name**: eslint-config-alloy
- **Description**: eslint-config-alloy
- **Primary Language**: 其他
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2018-12-07
- **Last Updated**: 2025-07-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: forked
## README
# [eslint-config-alloy][网站]
**最新特性:eslint-config-alloy 现已支持 TypeScript 5.0**
如果你使用的是 TypeScript 4.0,请安装旧版 `npm install --save-dev eslint-config-alloy@4`
**最新特性:eslint-config-alloy 现已支持 Vue 3.0**
如果你使用的是 Vue 2.0,请安装旧版 `npm install --save-dev eslint-config-alloy@3`
AlloyTeam ESLint 规则不仅是一套先进的适用于 React/Vue/Typescript 项目的 ESLint 配置规范,而且也是你配置个性化 ESLint 规则的最佳参考。
## 快速开始
请根据你的项目使用的技术栈选择以下配置:
- [内置规则](#内置规则)
- [React](#react)
- [Vue](#vue)
- [TypeScript](#typescript)
- [TypeScript React](#typescript-react)
- [TypeScript Vue](#typescript-vue)
## 设计理念
- 样式相关的规则交给 [Prettier][] 管理
- 传承 ESLint 的理念,帮助大家建立自己的规则
- 高度的自动化:先进的规则管理,测试即文档即[网站][]
- 与时俱进,第一时间跟进最新的规则
详细说明
### 样式相关的规则交给 [Prettier][] 管理
Prettier 是一个代码格式化工具,相比于 ESLint 中的代码格式规则,它提供了更少的选项,但是却更加专业。
如今 Prettier 已经成为前端项目中的必备工具,eslint-config-alloy 也没有必要再去维护 ESLint 中的代码格式相关的规则了,所以我们在 v3 版本中彻底去掉了所有 Prettier 相关的规则,用 ESLint 来检查它更擅长的逻辑错误。
至于缩进要两个空格还是四个空格,末尾要不要分号,可以在项目的 `.prettierrc.js` 中去配置,当然我们也提供了一份推荐的 Prettier 配置供大家参考。
### 传承 [ESLint 的理念][],帮助大家建立自己的规则
大家还记得 ESLint 是怎么打败 JSHint 成为最受欢迎的 js 代码检查工具吗?就是因为 ESLint 推崇的插件化、配置化,满足了不同团队不同技术栈的个性的需求。
所以 eslint-config-alloy 也传承了 ESLint 的设计理念,不会强调必须要使用我们这套规则,而是通过文档、示例、测试、网站等方便大家参考 alloy 的规则,在此基础上做出自己的个性化。
由于 React/Vue/TypeScript 插件的文档没有中文化(或中文的版本很滞后),所以 alloy 的文档很大程度上帮助了国内开发者理解和配置个性化的规则。
实际上国内有很多团队或个人的 ESLint 配置,都参考了 alloy 的文档。
### 高度的自动化:先进的规则管理,测试即文档即[网站][]
> 无情的推动自动化
eslint-config-alloy 通过高度的自动化,将一切能自动化管理的过程都交给脚本处理,其中包括了:
- 通过 GitHub Actions,自动每周检查 ESLint 及相关插件是否有新版本,新版本中是否有新规则需要我们添加
- 自动检查我们的规则是否包含了 Prettier 的规则
- 自动检查我们的规则是否包含了已废弃(deprecated)的规则
除此之外,通过自动化的脚本,我们甚至可以将成百上千个 ESLint 配置文件分而治之,每个规则在一个单独的目录下管理:
- 通过脚本将单个的配置整合成最终的一个配置
- 通过脚本将单个配置中的 description 和 reason 构建成文档[网站][],方便大家查看
- 通过脚本将单个配置中的 `bad.js` 和 `good.js` 输出到[网站][]中,甚至可以直接在[网站][]中看到 `bad.js` 的(真实运行 ESLint 脚本后的)报错信息
这样的好处是显而易见的,测试即文档即[网站][],我们可以只在一个地方维护规则和测试,其他工作都交给自动化脚本,极大的降低了维护的成本。简单来说,当我们有个新规则需要添加时,只需要写三个文件 `test/index/another-rule/.eslintrc.js`, `test/index/another-rule/bad.js`, `test/index/another-rule/good.js` 即可。
### 与时俱进,第一时间跟进最新的规则
ESLint 的更新很快,几乎每周都有一个新版本,有时有新规则,有时会废弃已有规则,而且相关插件(React/Vue/TypeScript)也会时而更新,没有自动化工具的话,实在是难以跟进。
而 eslint-config-alloy 通过上述的自动化工具,可以在第一时间就收到 GitHub Actions 的通知,告诉我们哪些规则需要添加:

这样就实现了,在前端社区快速更迭的时候能够及时跟进最新的规则,永远保持 eslint-config-alloy 的活力和先进。
## 使用方法
### 内置规则
```bash
npm install --save-dev eslint @babel/core @babel/eslint-parser eslint-config-alloy
```
在你的项目的根目录下创建一个 `.eslintrc.js` 文件,并将以下内容复制进去:
```js
module.exports = {
extends: [
'alloy',
],
env: {
// 你的环境变量(包含多个预定义的全局变量)
//
// browser: true,
// node: true,
// mocha: true,
// jest: true,
// jquery: true
},
globals: {
// 你的全局变量(设置为 false 表示它不允许被重新赋值)
//
// myGlobal: false
},
rules: {
// 自定义你的规则
},
};
```
### React
```bash
npm install --save-dev eslint @babel/core @babel/eslint-parser @babel/preset-react@latest eslint-plugin-react eslint-config-alloy
```
在你的项目的根目录下创建一个 `.eslintrc.js` 文件,并将以下内容复制进去:
```js
module.exports = {
extends: [
'alloy',
'alloy/react',
],
env: {
// 你的环境变量(包含多个预定义的全局变量)
//
// browser: true,
// node: true,
// mocha: true,
// jest: true,
// jquery: true
},
globals: {
// 你的全局变量(设置为 false 表示它不允许被重新赋值)
//
// myGlobal: false
},
rules: {
// 自定义你的规则
},
};
```
### Vue
```bash
npm install --save-dev eslint @babel/core @babel/eslint-parser vue-eslint-parser eslint-plugin-vue eslint-config-alloy
```
在你的项目的根目录下创建一个 `.eslintrc.js` 文件,并将以下内容复制进去:
```js
module.exports = {
extends: [
'alloy',
'alloy/vue',
],
env: {
// 你的环境变量(包含多个预定义的全局变量)
//
// browser: true,
// node: true,
// mocha: true,
// jest: true,
// jquery: true
},
globals: {
// 你的全局变量(设置为 false 表示它不允许被重新赋值)
//
// myGlobal: false
},
rules: {
// 自定义你的规则
},
};
```
### TypeScript
```bash
npm install --save-dev eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-alloy
```
在你的项目的根目录下创建一个 `.eslintrc.js` 文件,并将以下内容复制进去:
```js
module.exports = {
extends: [
'alloy',
'alloy/typescript',
],
env: {
// 你的环境变量(包含多个预定义的全局变量)
//
// browser: true,
// node: true,
// mocha: true,
// jest: true,
// jquery: true
},
globals: {
// 你的全局变量(设置为 false 表示它不允许被重新赋值)
//
// myGlobal: false
},
rules: {
// 自定义你的规则
},
};
```
### TypeScript React
```bash
npm install --save-dev eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-config-alloy
```
在你的项目的根目录下创建一个 `.eslintrc.js` 文件,并将以下内容复制进去:
```js
module.exports = {
extends: [
'alloy',
'alloy/react',
'alloy/typescript',
],
env: {
// 你的环境变量(包含多个预定义的全局变量)
//
// browser: true,
// node: true,
// mocha: true,
// jest: true,
// jquery: true
},
globals: {
// 你的全局变量(设置为 false 表示它不允许被重新赋值)
//
// myGlobal: false
},
rules: {
// 自定义你的规则
},
};
```
### TypeScript Vue
建议使用 `npm init vue@3` 创建集成了 Vue, TypeScript 和 ESLint 的项目,然后再参考[此示例](./examples/typescript-vue/.eslintrc.js)调整其 ESLint 配置。
常规方法如下:
```bash
npm install --save-dev @babel/core @babel/eslint-parser @typescript-eslint/eslint-plugin @typescript-eslint/parser @vue/eslint-config-typescript eslint eslint-config-alloy eslint-plugin-vue vue-eslint-parser
```
在你的项目的根目录下创建一个 `.eslintrc.js` 文件,并将以下内容复制进去:
```js
module.exports = {
extends: ['alloy', 'alloy/vue', 'alloy/typescript'],
parser: 'vue-eslint-parser',
parserOptions: {
parser: {
js: '@babel/eslint-parser',
jsx: '@babel/eslint-parser',
ts: '@typescript-eslint/parser',
tsx: '@typescript-eslint/parser',
// Leave the template parser unspecified, so that it could be determined by `