@july_cm/eslint-config 2.1.0 → 2.3.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 +40 -6
- package/lib/configs/javascript.js +3 -0
- package/lib/configs/package.js +5 -1
- package/lib/configs/typescript.js +1 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -8,6 +8,14 @@ It depends on ESLint v9 or later and is only compatible with Flat Configuration.
|
|
|
8
8
|
|
|
9
9
|
✅ [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (new: `eslint.config.js`)
|
|
10
10
|
|
|
11
|
+
## 功能 | Features
|
|
12
|
+
|
|
13
|
+
- ✅ 开箱即用且轻量的 JavaScript ESLint 配置
|
|
14
|
+
|
|
15
|
+
- ✅ 开箱即用且轻量的 TypeScript ESLint 配置
|
|
16
|
+
|
|
17
|
+
- ✅ 支持 package.json 字段的排序,尤其是 dependencies 等字段
|
|
18
|
+
|
|
11
19
|
## Installation
|
|
12
20
|
|
|
13
21
|
```sh
|
|
@@ -16,9 +24,14 @@ npm install --save-dev eslint @july_cm/eslint-config
|
|
|
16
24
|
|
|
17
25
|
`@july_cm/eslint-config` does not install ESLint for you. You must install these yourself.
|
|
18
26
|
|
|
19
|
-
##
|
|
27
|
+
## 快速开始
|
|
28
|
+
|
|
29
|
+
扁平化的配置,可以使用指定的编程语言配置或者直接使用推荐配置。
|
|
30
|
+
|
|
31
|
+
直接使用 `recommended` 也无需担心 `.ts` 文件被 `javascript` 规则命中,本包内部已经做了规则的隔离,以保证规则和性能的稳定。
|
|
20
32
|
|
|
21
33
|
```javascript
|
|
34
|
+
// eslint.config.js
|
|
22
35
|
const * as config from '@july_cm/eslint-config';
|
|
23
36
|
|
|
24
37
|
// only javascript
|
|
@@ -36,20 +49,41 @@ export default config.typescript;
|
|
|
36
49
|
export default config.recommended;
|
|
37
50
|
```
|
|
38
51
|
|
|
52
|
+
⚠️ 需要注意:若 `package.json` 中的 `type` 字段没有显示设置为 `module`,则文件名需要改为 `eslint.config.mjs`.
|
|
53
|
+
|
|
54
|
+
## 自定义规则
|
|
55
|
+
|
|
56
|
+
支持自定义规则或者配置,建议使用 ESLint 官方的函数 `defineConfig` 作为合并函数:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
// eslint.config.js
|
|
60
|
+
import { recommended } from '@july_cm/eslint-config';
|
|
61
|
+
import { defineConfig } from 'eslint/config';
|
|
62
|
+
|
|
63
|
+
export default defineConfig(recommended, {
|
|
64
|
+
ignores: ["dist"],
|
|
65
|
+
rules: {}
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
39
69
|
|
|
40
70
|
## Abort `package.json` key order
|
|
41
71
|
|
|
42
72
|
The sorting functionality is implemented based on [eslint-plugin-jsonc](https://github.com/ota-meshi/eslint-plugin-jsonc) and [prettier](https://github.com/prettier/prettier).
|
|
43
73
|
|
|
44
74
|
```javascript
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
75
|
+
[{
|
|
76
|
+
pathPattern: '^$',
|
|
77
|
+
order: ['name', 'version', 'author', 'exports', 'types', 'main', 'module', 'scripts', 'dependencies', 'devDependencies'],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
50
80
|
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
|
|
51
81
|
order: { type: 'asc' },
|
|
52
82
|
},
|
|
83
|
+
{
|
|
84
|
+
pathPattern: 'exports',
|
|
85
|
+
order: ['types', 'require', 'import']
|
|
86
|
+
}]
|
|
53
87
|
```
|
|
54
88
|
|
|
55
89
|
## With `Visual Studio Code`
|
|
@@ -11,6 +11,9 @@ import eslintPrettier from './prettier.js';
|
|
|
11
11
|
const javascriptConfig = defineConfig({
|
|
12
12
|
extends: [eslintJs.configs.recommended, importPlugin.flatConfigs.recommended, ...eslintPrettier],
|
|
13
13
|
files: ['**/*.{js,mjs,cjs,jsx}'],
|
|
14
|
+
languageOptions: {
|
|
15
|
+
ecmaVersion: 'latest',
|
|
16
|
+
},
|
|
14
17
|
rules: {
|
|
15
18
|
'import/order': [
|
|
16
19
|
'warn',
|
package/lib/configs/package.js
CHANGED
|
@@ -13,12 +13,16 @@ const packageJsonConfig = defineConfig({
|
|
|
13
13
|
'warn',
|
|
14
14
|
{
|
|
15
15
|
pathPattern: '^$',
|
|
16
|
-
order: ['name', 'version', 'author', 'scripts', 'dependencies', 'devDependencies'],
|
|
16
|
+
order: ['name', 'version', 'author', 'exports', 'types', 'main', 'module', 'scripts', 'dependencies', 'devDependencies'],
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
|
|
20
20
|
order: { type: 'asc' },
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
pathPattern: 'exports',
|
|
24
|
+
order: ['types', 'require', 'import']
|
|
25
|
+
}
|
|
22
26
|
],
|
|
23
27
|
},
|
|
24
28
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@july_cm/eslint-config",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"eslint": "^9.22.0",
|
|
24
24
|
"release-it": "^18.1.2",
|
|
25
25
|
"release-it-pnpm": "^4.6.4",
|
|
26
|
-
"typescript": "^5.8.2"
|
|
26
|
+
"typescript": "^5.8.2",
|
|
27
|
+
"vitest": "^3.0.9"
|
|
27
28
|
},
|
|
28
29
|
"optionalPeerDependencies": {
|
|
29
30
|
"eslint": "^9",
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
"url": "https://github.com/JxJuly/eslint-config/issues"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
42
|
+
"test": "vitest run",
|
|
41
43
|
"release": "release-it -ci"
|
|
42
44
|
}
|
|
43
45
|
}
|