@july_cm/eslint-config 2.4.0 → 2.4.1
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 +17 -13
- package/README.zh-CN.md +135 -0
- package/lib/index.cjs +2 -2
- package/lib/index.mjs +2 -2
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @july_cm/eslint-config
|
|
2
2
|
|
|
3
|
+
[简体中文](./README.zh-CN.md) | English
|
|
4
|
+
|
|
3
5
|
[](LICENSE)
|
|
4
6
|
[](https://www.npmjs.com/package/@july_cm/eslint-config)
|
|
5
7
|
[](https://codecov.io/gh/JxJuly/eslint-config)
|
|
@@ -12,17 +14,17 @@ It depends on ESLint v9 or later and is only compatible with Flat Configuration.
|
|
|
12
14
|
|
|
13
15
|
✅ [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (new: `eslint.config.js`)
|
|
14
16
|
|
|
15
|
-
##
|
|
17
|
+
## Features
|
|
16
18
|
|
|
17
|
-
- ✅
|
|
19
|
+
- ✅ Out-of-the-box and lightweight JavaScript ESLint configuration
|
|
18
20
|
|
|
19
|
-
- ✅
|
|
21
|
+
- ✅ Out-of-the-box and lightweight TypeScript ESLint configuration
|
|
20
22
|
|
|
21
|
-
- ✅
|
|
23
|
+
- ✅ Out-of-the-box and lightweight CSS ESLint configuration
|
|
22
24
|
|
|
23
|
-
- ✅
|
|
25
|
+
- ✅ Support for package.json field sorting, especially dependencies and other fields
|
|
24
26
|
|
|
25
|
-
- ✅
|
|
27
|
+
- ✅ Code style checking with Prettier rules
|
|
26
28
|
|
|
27
29
|
## Installation
|
|
28
30
|
|
|
@@ -32,11 +34,11 @@ npm install --save-dev eslint @july_cm/eslint-config
|
|
|
32
34
|
|
|
33
35
|
`@july_cm/eslint-config` does not install ESLint for you. You must install these yourself.
|
|
34
36
|
|
|
35
|
-
##
|
|
37
|
+
## Quick Start
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
Flat configuration allows you to use specific programming language configurations or directly use the recommended configuration.
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
When using `recommended` directly, you don't need to worry about `.ts` files being matched by `javascript` rules. This package has internally isolated the rules to ensure stable rules and performance.
|
|
40
42
|
|
|
41
43
|
```javascript
|
|
42
44
|
// eslint.config.js
|
|
@@ -57,11 +59,11 @@ export default config.typescript;
|
|
|
57
59
|
export default config.recommended;
|
|
58
60
|
```
|
|
59
61
|
|
|
60
|
-
⚠️
|
|
62
|
+
⚠️ Note: If the `type` field in `package.json` is not explicitly set to `module`, the filename needs to be changed to `eslint.config.mjs`.
|
|
61
63
|
|
|
62
|
-
##
|
|
64
|
+
## Custom Rules
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
Custom rules or configurations are supported. It is recommended to use ESLint's official `defineConfig` function as the merge function:
|
|
65
67
|
|
|
66
68
|
```javascript
|
|
67
69
|
// eslint.config.js
|
|
@@ -117,7 +119,9 @@ The sorting functionality is implemented based on [eslint-plugin-jsonc](https://
|
|
|
117
119
|
{
|
|
118
120
|
"editor.codeActionsOnSave": {
|
|
119
121
|
"source.fixAll.eslint": "explicit"
|
|
120
|
-
}
|
|
122
|
+
},
|
|
123
|
+
// ESLint does not validate css, json, jsonc by default, needs to be added manually
|
|
124
|
+
"eslint.validate": ["css", "json", "jsonc", "javascript", "javascriptreact", "typescript", "typescriptreact"]
|
|
121
125
|
}
|
|
122
126
|
```
|
|
123
127
|
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# @july_cm/eslint-config
|
|
2
|
+
|
|
3
|
+
简体中文 | [English](./README.md)
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/@july_cm/eslint-config)
|
|
7
|
+
[](https://codecov.io/gh/JxJuly/eslint-config)
|
|
8
|
+
|
|
9
|
+
这是我的通用 ESLint 配置。
|
|
10
|
+
|
|
11
|
+
它依赖于 ESLint v9 或更高版本,并且仅兼容扁平化配置。
|
|
12
|
+
|
|
13
|
+
❌ [传统配置](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated) (legacy: `.eslintrc*`)
|
|
14
|
+
|
|
15
|
+
✅ [扁平化配置](https://eslint.org/docs/latest/use/configure/configuration-files-new) (new: `eslint.config.js`)
|
|
16
|
+
|
|
17
|
+
## 功能
|
|
18
|
+
|
|
19
|
+
- ✅ 开箱即用且轻量的 JavaScript ESLint 配置
|
|
20
|
+
|
|
21
|
+
- ✅ 开箱即用且轻量的 TypeScript ESLint 配置
|
|
22
|
+
|
|
23
|
+
- ✅ 开箱即用且轻量的 CSS ESLint 配置
|
|
24
|
+
|
|
25
|
+
- ✅ 支持 package.json 字段的排序,尤其是 dependencies 等字段
|
|
26
|
+
|
|
27
|
+
- ✅ 搭配 Prettier 规则的代码风格检查
|
|
28
|
+
|
|
29
|
+
## 安装
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install --save-dev eslint @july_cm/eslint-config
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`@july_cm/eslint-config` 不会为你安装 ESLint,你必须自己安装。
|
|
36
|
+
|
|
37
|
+
## 快速开始
|
|
38
|
+
|
|
39
|
+
扁平化的配置,可以使用指定的编程语言配置或者直接使用推荐配置。
|
|
40
|
+
|
|
41
|
+
直接使用 `recommended` 也无需担心 `.ts` 文件被 `javascript` 规则命中,本包内部已经做了规则的隔离,以保证规则和性能的稳定。
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
// eslint.config.js
|
|
45
|
+
const * as config from '@july_cm/eslint-config';
|
|
46
|
+
|
|
47
|
+
// only javascript
|
|
48
|
+
export default config.javascript;
|
|
49
|
+
|
|
50
|
+
// only typescript
|
|
51
|
+
export default config.typescript;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* recommended
|
|
55
|
+
* - javascript
|
|
56
|
+
* - typescript
|
|
57
|
+
* - package.json
|
|
58
|
+
*/
|
|
59
|
+
export default config.recommended;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
⚠️ 需要注意:若 `package.json` 中的 `type` 字段没有显示设置为 `module`,则文件名需要改为 `eslint.config.mjs`。
|
|
63
|
+
|
|
64
|
+
## 自定义规则
|
|
65
|
+
|
|
66
|
+
支持自定义规则或者配置,建议使用 ESLint 官方的函数 `defineConfig` 作为合并函数:
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
// eslint.config.js
|
|
70
|
+
import { recommended } from '@july_cm/eslint-config';
|
|
71
|
+
import { defineConfig } from 'eslint/config';
|
|
72
|
+
|
|
73
|
+
export default defineConfig(recommended, {
|
|
74
|
+
ignores: ["dist"],
|
|
75
|
+
rules: {}
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## 中止 `package.json` 键排序
|
|
81
|
+
|
|
82
|
+
排序功能基于 [eslint-plugin-jsonc](https://github.com/ota-meshi/eslint-plugin-jsonc) 和 [prettier](https://github.com/prettier/prettier) 实现。
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
[{
|
|
86
|
+
pathPattern: '^$',
|
|
87
|
+
order: ['name', 'version', 'author', 'exports', 'types', 'main', 'module', 'scripts', 'dependencies', 'devDependencies'],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
|
|
91
|
+
order: { type: 'asc' },
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
pathPattern: 'exports',
|
|
95
|
+
order: ['types', 'require', 'import']
|
|
96
|
+
}]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 配合 `Visual Studio Code` 使用
|
|
100
|
+
|
|
101
|
+
1. 安装 [VS Code ESLint 扩展](https://github.com/microsoft/vscode-eslint)。
|
|
102
|
+
|
|
103
|
+
检查编辑器中是否有其他插件被设置为默认格式化程序。如果有,需要将它们移除或替换为 ESLint:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
如果 Prettier 扩展在此工作区中也处于活动状态,应该禁用它。这是因为两者会相互冲突,导致格式化问题。
|
|
112
|
+
|
|
113
|
+
`@july_cm/eslint-config` 已经集成了 `eslint-plugin-prettier`,确保两者可以同时工作而不会冲突。
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
2. 保存时自动修复
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"editor.codeActionsOnSave": {
|
|
121
|
+
"source.fixAll.eslint": "explicit"
|
|
122
|
+
},
|
|
123
|
+
// ESLint 默认不对 css, json, jsonc 进行校验,需要手动添加
|
|
124
|
+
"eslint.validate": ["css", "json", "jsonc", "javascript", "javascriptreact", "typescript", "typescriptreact"]
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
3. 调试
|
|
129
|
+
|
|
130
|
+
打开 VSCode 命令面板(Ctrl + Shift + P / Cmd + Shift + P)并运行:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
ESLint: Show Output Channel
|
|
134
|
+
```
|
|
135
|
+
如果存在错误,请修复它们。
|
package/lib/index.cjs
CHANGED
|
@@ -122,7 +122,8 @@ const packageJsonConfig = config.defineConfig({
|
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
124
|
pathPattern: "exports",
|
|
125
|
-
|
|
125
|
+
// Prefer ESM (import) before CommonJS (require)
|
|
126
|
+
order: ["types", "import", "require"]
|
|
126
127
|
}
|
|
127
128
|
]
|
|
128
129
|
}
|
|
@@ -130,7 +131,6 @@ const packageJsonConfig = config.defineConfig({
|
|
|
130
131
|
const typescriptConfig = config.defineConfig({
|
|
131
132
|
extends: [
|
|
132
133
|
eslintJs.configs.recommended,
|
|
133
|
-
// @ts-expect-error - https://github.com/eslint/rewrite/issues/234
|
|
134
134
|
typescriptEslint.configs.stylistic,
|
|
135
135
|
eslintPluginImport.flatConfigs.recommended,
|
|
136
136
|
eslintPluginImport.flatConfigs.typescript,
|
package/lib/index.mjs
CHANGED
|
@@ -120,7 +120,8 @@ const packageJsonConfig = defineConfig({
|
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
122
|
pathPattern: "exports",
|
|
123
|
-
|
|
123
|
+
// Prefer ESM (import) before CommonJS (require)
|
|
124
|
+
order: ["types", "import", "require"]
|
|
124
125
|
}
|
|
125
126
|
]
|
|
126
127
|
}
|
|
@@ -128,7 +129,6 @@ const packageJsonConfig = defineConfig({
|
|
|
128
129
|
const typescriptConfig = defineConfig({
|
|
129
130
|
extends: [
|
|
130
131
|
eslintJs.configs.recommended,
|
|
131
|
-
// @ts-expect-error - https://github.com/eslint/rewrite/issues/234
|
|
132
132
|
configs.stylistic,
|
|
133
133
|
eslintPluginImport.flatConfigs.recommended,
|
|
134
134
|
eslintPluginImport.flatConfigs.typescript,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@july_cm/eslint-config",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"author": "July",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -22,24 +22,24 @@
|
|
|
22
22
|
"release": "release-it -ci"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@eslint/css": "^0.
|
|
26
|
-
"@eslint/js": "^9.
|
|
25
|
+
"@eslint/css": "^0.14.1",
|
|
26
|
+
"@eslint/js": "^9.39.1",
|
|
27
27
|
"eslint-config-prettier": "^10.1.8",
|
|
28
28
|
"eslint-import-resolver-node": "^0.3.9",
|
|
29
29
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
30
30
|
"eslint-plugin-import": "^2.32.0",
|
|
31
|
-
"eslint-plugin-jsonc": "^2.
|
|
31
|
+
"eslint-plugin-jsonc": "^2.21.0",
|
|
32
32
|
"eslint-plugin-prettier": "^5.5.4",
|
|
33
|
-
"typescript-eslint": "^8.
|
|
33
|
+
"typescript-eslint": "^8.49.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
37
|
-
"@vitest/coverage-v8": "^
|
|
38
|
-
"eslint": "^9.
|
|
39
|
-
"release-it": "^19.0
|
|
40
|
-
"typescript": "^5.9.
|
|
41
|
-
"vite": "^7.
|
|
42
|
-
"vitest": "^
|
|
36
|
+
"@release-it/conventional-changelog": "^10.0.3",
|
|
37
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
38
|
+
"eslint": "^9.39.1",
|
|
39
|
+
"release-it": "^19.1.0",
|
|
40
|
+
"typescript": "^5.9.3",
|
|
41
|
+
"vite": "^7.2.7",
|
|
42
|
+
"vitest": "^4.0.15"
|
|
43
43
|
},
|
|
44
44
|
"optionalPeerDependencies": {
|
|
45
45
|
"eslint": "^9",
|