@july_cm/eslint-config 2.4.0 → 2.4.2
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 +6 -2
- package/lib/index.mjs +6 -2
- package/package.json +14 -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
|
@@ -3,6 +3,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
3
3
|
const config = require("eslint/config");
|
|
4
4
|
const css$1 = require("@eslint/css");
|
|
5
5
|
const prettier = require("eslint-plugin-prettier");
|
|
6
|
+
const tailwindCsstree = require("tailwind-csstree");
|
|
6
7
|
const eslintJs = require("@eslint/js");
|
|
7
8
|
const eslintPluginImport = require("eslint-plugin-import");
|
|
8
9
|
const recommended$1 = require("eslint-plugin-prettier/recommended");
|
|
@@ -13,6 +14,9 @@ const cssConfig = config.defineConfig([
|
|
|
13
14
|
files: ["**/*.css"],
|
|
14
15
|
plugins: { css: css$1, prettier },
|
|
15
16
|
language: "css/css",
|
|
17
|
+
languageOptions: {
|
|
18
|
+
customSyntax: tailwindCsstree.tailwind4
|
|
19
|
+
},
|
|
16
20
|
rules: {
|
|
17
21
|
"css/no-empty-blocks": "error",
|
|
18
22
|
"prettier/prettier": [
|
|
@@ -122,7 +126,8 @@ const packageJsonConfig = config.defineConfig({
|
|
|
122
126
|
},
|
|
123
127
|
{
|
|
124
128
|
pathPattern: "exports",
|
|
125
|
-
|
|
129
|
+
// Prefer ESM (import) before CommonJS (require)
|
|
130
|
+
order: ["types", "import", "require"]
|
|
126
131
|
}
|
|
127
132
|
]
|
|
128
133
|
}
|
|
@@ -130,7 +135,6 @@ const packageJsonConfig = config.defineConfig({
|
|
|
130
135
|
const typescriptConfig = config.defineConfig({
|
|
131
136
|
extends: [
|
|
132
137
|
eslintJs.configs.recommended,
|
|
133
|
-
// @ts-expect-error - https://github.com/eslint/rewrite/issues/234
|
|
134
138
|
typescriptEslint.configs.stylistic,
|
|
135
139
|
eslintPluginImport.flatConfigs.recommended,
|
|
136
140
|
eslintPluginImport.flatConfigs.typescript,
|
package/lib/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineConfig } from "eslint/config";
|
|
2
2
|
import css$1 from "@eslint/css";
|
|
3
3
|
import prettier from "eslint-plugin-prettier";
|
|
4
|
+
import { tailwind4 } from "tailwind-csstree";
|
|
4
5
|
import eslintJs from "@eslint/js";
|
|
5
6
|
import eslintPluginImport from "eslint-plugin-import";
|
|
6
7
|
import recommended$1 from "eslint-plugin-prettier/recommended";
|
|
@@ -11,6 +12,9 @@ const cssConfig = defineConfig([
|
|
|
11
12
|
files: ["**/*.css"],
|
|
12
13
|
plugins: { css: css$1, prettier },
|
|
13
14
|
language: "css/css",
|
|
15
|
+
languageOptions: {
|
|
16
|
+
customSyntax: tailwind4
|
|
17
|
+
},
|
|
14
18
|
rules: {
|
|
15
19
|
"css/no-empty-blocks": "error",
|
|
16
20
|
"prettier/prettier": [
|
|
@@ -120,7 +124,8 @@ const packageJsonConfig = defineConfig({
|
|
|
120
124
|
},
|
|
121
125
|
{
|
|
122
126
|
pathPattern: "exports",
|
|
123
|
-
|
|
127
|
+
// Prefer ESM (import) before CommonJS (require)
|
|
128
|
+
order: ["types", "import", "require"]
|
|
124
129
|
}
|
|
125
130
|
]
|
|
126
131
|
}
|
|
@@ -128,7 +133,6 @@ const packageJsonConfig = defineConfig({
|
|
|
128
133
|
const typescriptConfig = defineConfig({
|
|
129
134
|
extends: [
|
|
130
135
|
eslintJs.configs.recommended,
|
|
131
|
-
// @ts-expect-error - https://github.com/eslint/rewrite/issues/234
|
|
132
136
|
configs.stylistic,
|
|
133
137
|
eslintPluginImport.flatConfigs.recommended,
|
|
134
138
|
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.2",
|
|
4
4
|
"author": "July",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -21,25 +21,27 @@
|
|
|
21
21
|
"test:cov": "vitest run --coverage",
|
|
22
22
|
"release": "release-it -ci"
|
|
23
23
|
},
|
|
24
|
+
"packageManager": "pnpm@10.26.1",
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@eslint/css": "^0.
|
|
26
|
-
"@eslint/js": "^9.
|
|
26
|
+
"@eslint/css": "^0.14.1",
|
|
27
|
+
"@eslint/js": "^9.39.1",
|
|
27
28
|
"eslint-config-prettier": "^10.1.8",
|
|
28
29
|
"eslint-import-resolver-node": "^0.3.9",
|
|
29
30
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
30
31
|
"eslint-plugin-import": "^2.32.0",
|
|
31
|
-
"eslint-plugin-jsonc": "^2.
|
|
32
|
+
"eslint-plugin-jsonc": "^2.21.0",
|
|
32
33
|
"eslint-plugin-prettier": "^5.5.4",
|
|
33
|
-
"
|
|
34
|
+
"tailwind-csstree": "^0.1.4",
|
|
35
|
+
"typescript-eslint": "^8.49.0"
|
|
34
36
|
},
|
|
35
37
|
"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": "^
|
|
38
|
+
"@release-it/conventional-changelog": "^10.0.3",
|
|
39
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
40
|
+
"eslint": "^9.39.1",
|
|
41
|
+
"release-it": "^19.1.0",
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"vite": "^7.2.7",
|
|
44
|
+
"vitest": "^4.0.15"
|
|
43
45
|
},
|
|
44
46
|
"optionalPeerDependencies": {
|
|
45
47
|
"eslint": "^9",
|