@frefly/eslint-config 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -2
- package/index.js +85 -0
- package/package.json +30 -3
package/README.md
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @frefly/eslint-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
前端 ESLint 共享配置,目前提供 uni-app Vue 3 预设。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @frefly/eslint-config eslint@10.14.0 @eslint/js@10.0.1 globals@17.14.0 eslint-plugin-simple-import-sort@14.0.0 eslint-plugin-vue@10.12.1 vue-eslint-parser@10.4.2 eslint-config-prettier@10.1.8
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
### 步骤一:创建配置文件
|
|
14
|
+
|
|
15
|
+
在项目根目录创建 `eslint.config.js`:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { createConfig } from '@frefly/eslint-config'
|
|
19
|
+
|
|
20
|
+
export default createConfig({
|
|
21
|
+
ignores: ['some/path/to/ignore']
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
也可以直接使用默认导出的配置:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
export { default } from '@frefly/eslint-config'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 步骤二:添加 lint 脚本
|
|
32
|
+
|
|
33
|
+
在 `package.json` 中添加:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"scripts": {
|
|
38
|
+
"lint": "eslint \"src/**/*.{js,vue}\""
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 步骤三:运行检查
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm lint
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 步骤四:配合 IDE 使用
|
|
50
|
+
|
|
51
|
+
安装 VS Code ESLint 扩展(`dbaeumer.vscode-eslint`),保存时自动修复:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"editor.codeActionsOnSave": {
|
|
56
|
+
"source.fixAll.eslint": "explicit"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 配置说明
|
|
62
|
+
|
|
63
|
+
配置基于 `@eslint/js` 推荐规则和 `eslint-plugin-vue` 的 `flat/recommended` 预设,仅作用于 `**/*.{js,vue}` 文件,并关闭与 Prettier 冲突的格式规则(通过 `eslint-config-prettier`)。
|
|
64
|
+
|
|
65
|
+
关键规则:
|
|
66
|
+
|
|
67
|
+
- `no-console: error` — 禁止 console 语句
|
|
68
|
+
- `no-debugger: error` — 禁止 debugger 语句
|
|
69
|
+
- `no-var: error` — 禁止 var 声明
|
|
70
|
+
- `no-unused-vars: error` — 禁止未使用变量
|
|
71
|
+
- `no-undef: error` — 禁止使用未声明变量
|
|
72
|
+
- `eqeqeq: error` — 必须使用全等
|
|
73
|
+
- `prefer-const: error` — 优先使用 const
|
|
74
|
+
- `camelcase: error` — 强制驼峰命名
|
|
75
|
+
- `vue/no-v-html: off` — 允许 v-html,业务中富文本渲染常见
|
|
76
|
+
- `vue/no-v-text-v-html-on-component: off` — 组件上允许 v-html
|
|
77
|
+
- `vue/multi-word-component-names: off` — 允许单词组件名(如 App、Layout)
|
|
78
|
+
- `simple-import-sort/exports: error` — 导出成员自动排序
|
|
79
|
+
- `simple-import-sort/imports` — 自定义分组排序:Node 内置模块 → @scoped → @/路径 → 副作用导入 → 父级 → 同级
|
|
80
|
+
|
|
81
|
+
全局变量包含 `browser` + `node` + uni-app 变量(`uni`、`wx`、`getCurrentPages`、`getApp`、`UniApp`,均 `readonly`)。
|
|
82
|
+
|
|
83
|
+
默认忽略目录:`node_modules`、`dist`、`.turbo`、`docs`、`types`、`__tests__`、`coverage`、`static`。
|
|
84
|
+
|
|
85
|
+
## API
|
|
86
|
+
|
|
87
|
+
### `createConfig(options?)`
|
|
88
|
+
|
|
89
|
+
创建 uni-app Vue 3 ESLint flat config,返回 `Linter.Config[]`。
|
|
90
|
+
|
|
91
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
92
|
+
| --------- | ---------- | ------ | ------------ |
|
|
93
|
+
| `ignores` | `string[]` | `[]` | 额外忽略路径 |
|
|
94
|
+
|
|
95
|
+
### 默认导出
|
|
96
|
+
|
|
97
|
+
`createConfig()` 的默认结果,等价于不带额外忽略项的配置。
|
package/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import importSort from 'eslint-plugin-simple-import-sort'
|
|
2
|
+
import pluginVue from 'eslint-plugin-vue'
|
|
3
|
+
import globals from 'globals'
|
|
4
|
+
|
|
5
|
+
import js from '@eslint/js'
|
|
6
|
+
import prettier from 'eslint-config-prettier'
|
|
7
|
+
|
|
8
|
+
const uniappGlobals = {
|
|
9
|
+
uni: 'readonly',
|
|
10
|
+
wx: 'readonly',
|
|
11
|
+
getCurrentPages: 'readonly',
|
|
12
|
+
getApp: 'readonly',
|
|
13
|
+
UniApp: 'readonly'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 创建 uniapp Vue 3 ESLint flat config
|
|
18
|
+
* @param {object} [options]
|
|
19
|
+
* @param {string[]} [options.ignores] - 忽略路径列表
|
|
20
|
+
* @returns {import('eslint').Linter.Config[]}
|
|
21
|
+
*/
|
|
22
|
+
export function createConfig(options = {}) {
|
|
23
|
+
const { ignores = [] } = options
|
|
24
|
+
|
|
25
|
+
return [
|
|
26
|
+
js.configs.recommended,
|
|
27
|
+
...pluginVue.configs['flat/recommended'],
|
|
28
|
+
{
|
|
29
|
+
files: ['**/*.{js,vue}'],
|
|
30
|
+
rules: {
|
|
31
|
+
'no-console': 'error',
|
|
32
|
+
'no-debugger': 'error',
|
|
33
|
+
'no-var': 'error',
|
|
34
|
+
'no-unused-vars': 'error',
|
|
35
|
+
'prefer-const': 'error',
|
|
36
|
+
eqeqeq: 'error',
|
|
37
|
+
camelcase: 'error',
|
|
38
|
+
'no-undef': 'error',
|
|
39
|
+
'vue/no-v-html': 'off',
|
|
40
|
+
'vue/no-v-text-v-html-on-component': 'off',
|
|
41
|
+
'vue/multi-word-component-names': 'off',
|
|
42
|
+
'simple-import-sort/exports': 'error',
|
|
43
|
+
'simple-import-sort/imports': [
|
|
44
|
+
'error',
|
|
45
|
+
{
|
|
46
|
+
groups: [
|
|
47
|
+
['^\\w'], // Node 内置模块(如 fs, path)
|
|
48
|
+
['^@\\w'], // @scoped 外部包(如 @vue/runtime-core)
|
|
49
|
+
['^@/'], // 项目别名路径(如 @/utils)
|
|
50
|
+
['^\\u0000'], // 副作用导入(如 import 'reset.css')
|
|
51
|
+
['^\\.\\.(?!/?$)', '^\\.\\./?$'], // 父级相对路径
|
|
52
|
+
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'] // 同级相对路径
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
languageOptions: {
|
|
58
|
+
globals: {
|
|
59
|
+
...globals.browser, // Vue 运行在浏览器环境
|
|
60
|
+
...globals.node, // 构建工具(Vite)运行在 Node 环境
|
|
61
|
+
...uniappGlobals // uniapp 全局变量
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
plugins: {
|
|
65
|
+
'simple-import-sort': importSort
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
ignores: [
|
|
70
|
+
'**/node_modules/**',
|
|
71
|
+
'**/dist/**',
|
|
72
|
+
'**/.turbo/**',
|
|
73
|
+
'**/docs/**',
|
|
74
|
+
'**/types/**',
|
|
75
|
+
'**/__tests__/**',
|
|
76
|
+
'**/coverage/**',
|
|
77
|
+
'**/static/**',
|
|
78
|
+
...ignores
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
prettier
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default createConfig()
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frefly/eslint-config",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "前端 ESLint 共享配置",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@eslint/js": "10.0.1",
|
|
19
|
+
"eslint": "10.14.0",
|
|
20
|
+
"eslint-config-prettier": "10.1.8",
|
|
21
|
+
"eslint-plugin-simple-import-sort": "14.0.0",
|
|
22
|
+
"eslint-plugin-vue": "10.12.1",
|
|
23
|
+
"vue-eslint-parser": "10.4.2",
|
|
24
|
+
"globals": "17.14.0"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.22.1"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"release": "pnpm publish --no-git-checks"
|
|
32
|
+
}
|
|
6
33
|
}
|