@july_cm/eslint-config 2.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 July
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @july_cm/eslint-config
2
2
 
3
+ [简体中文](./README.zh-CN.md) | English
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![NPM Version](https://img.shields.io/npm/v/%40july_cm%2Feslint-config)](https://www.npmjs.com/package/@july_cm/eslint-config)
7
+ [![codecov](https://codecov.io/gh/JxJuly/eslint-config/branch/main/graph/badge.svg?token=T1E32RHZB7)](https://codecov.io/gh/JxJuly/eslint-config)
8
+
3
9
  This is my common ESlint configuration.
4
10
 
5
11
  It depends on ESLint v9 or later and is only compatible with Flat Configuration.
@@ -8,13 +14,17 @@ It depends on ESLint v9 or later and is only compatible with Flat Configuration.
8
14
 
9
15
  ✅ [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (new: `eslint.config.js`)
10
16
 
11
- ## 功能 | Features
17
+ ## Features
18
+
19
+ - ✅ Out-of-the-box and lightweight JavaScript ESLint configuration
20
+
21
+ - ✅ Out-of-the-box and lightweight TypeScript ESLint configuration
12
22
 
13
- - ✅ 开箱即用且轻量的 JavaScript ESLint 配置
23
+ - ✅ Out-of-the-box and lightweight CSS ESLint configuration
14
24
 
15
- - ✅ 开箱即用且轻量的 TypeScript ESLint 配置
25
+ - ✅ Support for package.json field sorting, especially dependencies and other fields
16
26
 
17
- - ✅ 支持 package.json 字段的排序,尤其是 dependencies 等字段
27
+ - ✅ Code style checking with Prettier rules
18
28
 
19
29
  ## Installation
20
30
 
@@ -24,11 +34,11 @@ npm install --save-dev eslint @july_cm/eslint-config
24
34
 
25
35
  `@july_cm/eslint-config` does not install ESLint for you. You must install these yourself.
26
36
 
27
- ## 快速开始
37
+ ## Quick Start
28
38
 
29
- 扁平化的配置,可以使用指定的编程语言配置或者直接使用推荐配置。
39
+ Flat configuration allows you to use specific programming language configurations or directly use the recommended configuration.
30
40
 
31
- 直接使用 `recommended` 也无需担心 `.ts` 文件被 `javascript` 规则命中,本包内部已经做了规则的隔离,以保证规则和性能的稳定。
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.
32
42
 
33
43
  ```javascript
34
44
  // eslint.config.js
@@ -49,11 +59,11 @@ export default config.typescript;
49
59
  export default config.recommended;
50
60
  ```
51
61
 
52
- ⚠️ 需要注意:若 `package.json` 中的 `type` 字段没有显示设置为 `module`,则文件名需要改为 `eslint.config.mjs`.
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`.
53
63
 
54
- ## 自定义规则
64
+ ## Custom Rules
55
65
 
56
- 支持自定义规则或者配置,建议使用 ESLint 官方的函数 `defineConfig` 作为合并函数:
66
+ Custom rules or configurations are supported. It is recommended to use ESLint's official `defineConfig` function as the merge function:
57
67
 
58
68
  ```javascript
59
69
  // eslint.config.js
@@ -109,7 +119,9 @@ The sorting functionality is implemented based on [eslint-plugin-jsonc](https://
109
119
  {
110
120
  "editor.codeActionsOnSave": {
111
121
  "source.fixAll.eslint": "explicit"
112
- }
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"]
113
125
  }
114
126
  ```
115
127
 
@@ -0,0 +1,135 @@
1
+ # @july_cm/eslint-config
2
+
3
+ 简体中文 | [English](./README.md)
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![NPM Version](https://img.shields.io/npm/v/%40july_cm%2Feslint-config)](https://www.npmjs.com/package/@july_cm/eslint-config)
7
+ [![codecov](https://codecov.io/gh/JxJuly/eslint-config/branch/main/graph/badge.svg?token=T1E32RHZB7)](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 ADDED
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const config = require("eslint/config");
4
+ const css$1 = require("@eslint/css");
5
+ const prettier = require("eslint-plugin-prettier");
6
+ const eslintJs = require("@eslint/js");
7
+ const eslintPluginImport = require("eslint-plugin-import");
8
+ const recommended$1 = require("eslint-plugin-prettier/recommended");
9
+ const eslintPluginJsonc = require("eslint-plugin-jsonc");
10
+ const typescriptEslint = require("typescript-eslint");
11
+ const cssConfig = config.defineConfig([
12
+ {
13
+ files: ["**/*.css"],
14
+ plugins: { css: css$1, prettier },
15
+ language: "css/css",
16
+ rules: {
17
+ "css/no-empty-blocks": "error",
18
+ "prettier/prettier": [
19
+ "warn",
20
+ {
21
+ tabWidth: 2
22
+ },
23
+ {
24
+ usePrettierrc: false
25
+ }
26
+ ]
27
+ }
28
+ }
29
+ ]);
30
+ const prettierConfig = [
31
+ recommended$1,
32
+ {
33
+ rules: {
34
+ "prettier/prettier": [
35
+ "warn",
36
+ {
37
+ // 优先使用单引号
38
+ singleQuote: true,
39
+ printWidth: 110,
40
+ // 需要分号
41
+ semi: true,
42
+ // 仅在 es5 中有效的结构尾随逗号
43
+ trailingComma: "es5"
44
+ },
45
+ {
46
+ // 不读取 prettier 配置文件,统一走 eslint 配置
47
+ usePrettierrc: false
48
+ }
49
+ ]
50
+ }
51
+ }
52
+ ];
53
+ const javascriptConfig = config.defineConfig({
54
+ extends: [eslintJs.configs.recommended, eslintPluginImport.flatConfigs.recommended, ...prettierConfig],
55
+ files: ["**/*.{js,mjs,cjs,jsx}"],
56
+ languageOptions: {
57
+ ecmaVersion: "latest"
58
+ },
59
+ rules: {
60
+ "import/order": [
61
+ "warn",
62
+ {
63
+ groups: ["builtin", "external", "internal", ["parent", "sibling"], "object", "type", "index"],
64
+ "newlines-between": "always",
65
+ pathGroupsExcludedImportTypes: ["builtin"],
66
+ alphabetize: { order: "asc", caseInsensitive: true },
67
+ pathGroups: [
68
+ {
69
+ pattern: "react**",
70
+ group: "external",
71
+ position: "before"
72
+ },
73
+ {
74
+ pattern: "{@/**,@**}",
75
+ group: "internal",
76
+ position: "before"
77
+ },
78
+ {
79
+ pattern: "**/*.{scss,json,svg,css,less}",
80
+ group: "index",
81
+ position: "after"
82
+ }
83
+ ]
84
+ }
85
+ ]
86
+ },
87
+ settings: {
88
+ "import/resolver": {
89
+ node: true,
90
+ /**
91
+ * https://github.com/import-js/eslint-plugin-import/issues/3140
92
+ * eslint-plugin-import-node 解析器不支持 export 字段,所以不得不使用 eslint-plugin-import-typescript
93
+ */
94
+ typescript: true
95
+ }
96
+ }
97
+ });
98
+ const packageJsonConfig = config.defineConfig({
99
+ extends: [...eslintPluginJsonc.configs["flat/prettier"]],
100
+ files: ["package.json"],
101
+ rules: {
102
+ "jsonc/sort-keys": [
103
+ "warn",
104
+ {
105
+ pathPattern: "^$",
106
+ order: [
107
+ "name",
108
+ "version",
109
+ "author",
110
+ "exports",
111
+ "types",
112
+ "main",
113
+ "module",
114
+ "scripts",
115
+ "dependencies",
116
+ "devDependencies"
117
+ ]
118
+ },
119
+ {
120
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies$",
121
+ order: { type: "asc" }
122
+ },
123
+ {
124
+ pathPattern: "exports",
125
+ // Prefer ESM (import) before CommonJS (require)
126
+ order: ["types", "import", "require"]
127
+ }
128
+ ]
129
+ }
130
+ });
131
+ const typescriptConfig = config.defineConfig({
132
+ extends: [
133
+ eslintJs.configs.recommended,
134
+ typescriptEslint.configs.stylistic,
135
+ eslintPluginImport.flatConfigs.recommended,
136
+ eslintPluginImport.flatConfigs.typescript,
137
+ prettierConfig
138
+ ],
139
+ files: ["**/*.{ts,tsx}"],
140
+ rules: {
141
+ "import/order": [
142
+ "warn",
143
+ {
144
+ groups: ["builtin", "external", "internal", ["parent", "sibling"], "object", "type", "index"],
145
+ "newlines-between": "always",
146
+ pathGroupsExcludedImportTypes: ["builtin"],
147
+ alphabetize: { order: "asc", caseInsensitive: true },
148
+ pathGroups: [
149
+ {
150
+ pattern: "react**",
151
+ group: "external",
152
+ position: "before"
153
+ },
154
+ {
155
+ pattern: "{@/**,@**}",
156
+ group: "internal",
157
+ position: "before"
158
+ },
159
+ {
160
+ pattern: "**/*.{scss,json,svg,css,less}",
161
+ group: "index",
162
+ position: "after"
163
+ }
164
+ ]
165
+ }
166
+ ],
167
+ "@typescript-eslint/consistent-type-imports": [
168
+ "error",
169
+ { disallowTypeAnnotations: true, prefer: "type-imports" }
170
+ ],
171
+ "@typescript-eslint/no-explicit-any": ["warn"]
172
+ },
173
+ settings: {
174
+ "import/resolver": {
175
+ node: true,
176
+ typescript: true
177
+ }
178
+ }
179
+ });
180
+ const recommended = config.defineConfig(javascriptConfig, typescriptConfig, packageJsonConfig, cssConfig);
181
+ const javascript = javascriptConfig;
182
+ const typescript = typescriptConfig;
183
+ const packageJson = packageJsonConfig;
184
+ const css = cssConfig;
185
+ const index = {
186
+ recommended,
187
+ javascript,
188
+ typescript,
189
+ packageJson,
190
+ css
191
+ };
192
+ exports.css = css;
193
+ exports.default = index;
194
+ exports.javascript = javascript;
195
+ exports.packageJson = packageJson;
196
+ exports.recommended = recommended;
197
+ exports.typescript = typescript;
package/lib/index.mjs ADDED
@@ -0,0 +1,197 @@
1
+ import { defineConfig } from "eslint/config";
2
+ import css$1 from "@eslint/css";
3
+ import prettier from "eslint-plugin-prettier";
4
+ import eslintJs from "@eslint/js";
5
+ import eslintPluginImport from "eslint-plugin-import";
6
+ import recommended$1 from "eslint-plugin-prettier/recommended";
7
+ import eslintPluginJsonc from "eslint-plugin-jsonc";
8
+ import { configs } from "typescript-eslint";
9
+ const cssConfig = defineConfig([
10
+ {
11
+ files: ["**/*.css"],
12
+ plugins: { css: css$1, prettier },
13
+ language: "css/css",
14
+ rules: {
15
+ "css/no-empty-blocks": "error",
16
+ "prettier/prettier": [
17
+ "warn",
18
+ {
19
+ tabWidth: 2
20
+ },
21
+ {
22
+ usePrettierrc: false
23
+ }
24
+ ]
25
+ }
26
+ }
27
+ ]);
28
+ const prettierConfig = [
29
+ recommended$1,
30
+ {
31
+ rules: {
32
+ "prettier/prettier": [
33
+ "warn",
34
+ {
35
+ // 优先使用单引号
36
+ singleQuote: true,
37
+ printWidth: 110,
38
+ // 需要分号
39
+ semi: true,
40
+ // 仅在 es5 中有效的结构尾随逗号
41
+ trailingComma: "es5"
42
+ },
43
+ {
44
+ // 不读取 prettier 配置文件,统一走 eslint 配置
45
+ usePrettierrc: false
46
+ }
47
+ ]
48
+ }
49
+ }
50
+ ];
51
+ const javascriptConfig = defineConfig({
52
+ extends: [eslintJs.configs.recommended, eslintPluginImport.flatConfigs.recommended, ...prettierConfig],
53
+ files: ["**/*.{js,mjs,cjs,jsx}"],
54
+ languageOptions: {
55
+ ecmaVersion: "latest"
56
+ },
57
+ rules: {
58
+ "import/order": [
59
+ "warn",
60
+ {
61
+ groups: ["builtin", "external", "internal", ["parent", "sibling"], "object", "type", "index"],
62
+ "newlines-between": "always",
63
+ pathGroupsExcludedImportTypes: ["builtin"],
64
+ alphabetize: { order: "asc", caseInsensitive: true },
65
+ pathGroups: [
66
+ {
67
+ pattern: "react**",
68
+ group: "external",
69
+ position: "before"
70
+ },
71
+ {
72
+ pattern: "{@/**,@**}",
73
+ group: "internal",
74
+ position: "before"
75
+ },
76
+ {
77
+ pattern: "**/*.{scss,json,svg,css,less}",
78
+ group: "index",
79
+ position: "after"
80
+ }
81
+ ]
82
+ }
83
+ ]
84
+ },
85
+ settings: {
86
+ "import/resolver": {
87
+ node: true,
88
+ /**
89
+ * https://github.com/import-js/eslint-plugin-import/issues/3140
90
+ * eslint-plugin-import-node 解析器不支持 export 字段,所以不得不使用 eslint-plugin-import-typescript
91
+ */
92
+ typescript: true
93
+ }
94
+ }
95
+ });
96
+ const packageJsonConfig = defineConfig({
97
+ extends: [...eslintPluginJsonc.configs["flat/prettier"]],
98
+ files: ["package.json"],
99
+ rules: {
100
+ "jsonc/sort-keys": [
101
+ "warn",
102
+ {
103
+ pathPattern: "^$",
104
+ order: [
105
+ "name",
106
+ "version",
107
+ "author",
108
+ "exports",
109
+ "types",
110
+ "main",
111
+ "module",
112
+ "scripts",
113
+ "dependencies",
114
+ "devDependencies"
115
+ ]
116
+ },
117
+ {
118
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies$",
119
+ order: { type: "asc" }
120
+ },
121
+ {
122
+ pathPattern: "exports",
123
+ // Prefer ESM (import) before CommonJS (require)
124
+ order: ["types", "import", "require"]
125
+ }
126
+ ]
127
+ }
128
+ });
129
+ const typescriptConfig = defineConfig({
130
+ extends: [
131
+ eslintJs.configs.recommended,
132
+ configs.stylistic,
133
+ eslintPluginImport.flatConfigs.recommended,
134
+ eslintPluginImport.flatConfigs.typescript,
135
+ prettierConfig
136
+ ],
137
+ files: ["**/*.{ts,tsx}"],
138
+ rules: {
139
+ "import/order": [
140
+ "warn",
141
+ {
142
+ groups: ["builtin", "external", "internal", ["parent", "sibling"], "object", "type", "index"],
143
+ "newlines-between": "always",
144
+ pathGroupsExcludedImportTypes: ["builtin"],
145
+ alphabetize: { order: "asc", caseInsensitive: true },
146
+ pathGroups: [
147
+ {
148
+ pattern: "react**",
149
+ group: "external",
150
+ position: "before"
151
+ },
152
+ {
153
+ pattern: "{@/**,@**}",
154
+ group: "internal",
155
+ position: "before"
156
+ },
157
+ {
158
+ pattern: "**/*.{scss,json,svg,css,less}",
159
+ group: "index",
160
+ position: "after"
161
+ }
162
+ ]
163
+ }
164
+ ],
165
+ "@typescript-eslint/consistent-type-imports": [
166
+ "error",
167
+ { disallowTypeAnnotations: true, prefer: "type-imports" }
168
+ ],
169
+ "@typescript-eslint/no-explicit-any": ["warn"]
170
+ },
171
+ settings: {
172
+ "import/resolver": {
173
+ node: true,
174
+ typescript: true
175
+ }
176
+ }
177
+ });
178
+ const recommended = defineConfig(javascriptConfig, typescriptConfig, packageJsonConfig, cssConfig);
179
+ const javascript = javascriptConfig;
180
+ const typescript = typescriptConfig;
181
+ const packageJson = packageJsonConfig;
182
+ const css = cssConfig;
183
+ const index = {
184
+ recommended,
185
+ javascript,
186
+ typescript,
187
+ packageJson,
188
+ css
189
+ };
190
+ export {
191
+ css,
192
+ index as default,
193
+ javascript,
194
+ packageJson,
195
+ recommended,
196
+ typescript
197
+ };
package/package.json CHANGED
@@ -1,30 +1,45 @@
1
1
  {
2
2
  "name": "@july_cm/eslint-config",
3
- "version": "2.3.0",
4
- "main": "./lib/index.js",
3
+ "version": "2.4.1",
4
+ "author": "July",
5
+ "exports": {
6
+ ".": {
7
+ "require": "./lib/index.cjs",
8
+ "import": "./lib/index.mjs"
9
+ }
10
+ },
11
+ "main": "./lib/index.cjs",
5
12
  "type": "module",
6
13
  "files": [
7
14
  "README.md",
8
- "lib"
15
+ "lib",
16
+ "package.json"
9
17
  ],
10
- "author": "July",
18
+ "scripts": {
19
+ "build": "vite build",
20
+ "test": "vitest run",
21
+ "test:cov": "vitest run --coverage",
22
+ "release": "release-it -ci"
23
+ },
11
24
  "dependencies": {
12
- "@eslint/js": "^9.22.0",
13
- "eslint-config-prettier": "^10.1.1",
25
+ "@eslint/css": "^0.14.1",
26
+ "@eslint/js": "^9.39.1",
27
+ "eslint-config-prettier": "^10.1.8",
14
28
  "eslint-import-resolver-node": "^0.3.9",
15
- "eslint-import-resolver-typescript": "^3.8.6",
16
- "eslint-plugin-import": "^2.31.0",
17
- "eslint-plugin-jsonc": "^2.19.1",
18
- "eslint-plugin-prettier": "^5.2.3",
19
- "typescript-eslint": "^8.26.1"
29
+ "eslint-import-resolver-typescript": "^4.4.4",
30
+ "eslint-plugin-import": "^2.32.0",
31
+ "eslint-plugin-jsonc": "^2.21.0",
32
+ "eslint-plugin-prettier": "^5.5.4",
33
+ "typescript-eslint": "^8.49.0"
20
34
  },
21
35
  "devDependencies": {
22
- "@release-it/conventional-changelog": "^10.0.0",
23
- "eslint": "^9.22.0",
24
- "release-it": "^18.1.2",
25
- "release-it-pnpm": "^4.6.4",
26
- "typescript": "^5.8.2",
27
- "vitest": "^3.0.9"
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"
28
43
  },
29
44
  "optionalPeerDependencies": {
30
45
  "eslint": "^9",
@@ -37,9 +52,5 @@
37
52
  "homepage": "https://github.com/JxJuly/eslint-config/blob/main/README.md",
38
53
  "bugs": {
39
54
  "url": "https://github.com/JxJuly/eslint-config/issues"
40
- },
41
- "scripts": {
42
- "test": "vitest run",
43
- "release": "release-it -ci"
44
55
  }
45
- }
56
+ }
@@ -1,58 +0,0 @@
1
- import eslintJs from '@eslint/js';
2
- import { defineConfig } from 'eslint/config';
3
- import importPlugin from 'eslint-plugin-import';
4
-
5
- import eslintPrettier from './prettier.js';
6
-
7
- /**
8
- * defineConfig 会 flat 一层 extends,并且将 files 字段赋值给所有 extends
9
- * 可以借助这个函数为所有插件添加 files 约束,防止语言之间的污染
10
- */
11
- const javascriptConfig = defineConfig({
12
- extends: [eslintJs.configs.recommended, importPlugin.flatConfigs.recommended, ...eslintPrettier],
13
- files: ['**/*.{js,mjs,cjs,jsx}'],
14
- languageOptions: {
15
- ecmaVersion: 'latest',
16
- },
17
- rules: {
18
- 'import/order': [
19
- 'warn',
20
- {
21
- groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'object', 'type', 'index'],
22
- 'newlines-between': 'always',
23
- pathGroupsExcludedImportTypes: ['builtin'],
24
- alphabetize: { order: 'asc', caseInsensitive: true },
25
- pathGroups: [
26
- {
27
- pattern: 'react**',
28
- group: 'external',
29
- position: 'before',
30
- },
31
- {
32
- pattern: '{@/**,@**}',
33
- group: 'internal',
34
- position: 'before',
35
- },
36
- {
37
- pattern: '**/*.{scss,json,svg,css,less}',
38
- group: 'index',
39
- position: 'after',
40
- },
41
- ],
42
- },
43
- ],
44
- },
45
- settings: {
46
- 'import/resolver': {
47
- node: true,
48
- /**
49
- * https://github.com/import-js/eslint-plugin-import/issues/3140
50
- * eslint-plugin-import-node 解析器不支持 export 字段,所以不得不使用 eslint-plugin-import-typescript
51
- */
52
- typescript: true,
53
- },
54
- },
55
- });
56
-
57
- export { javascriptConfig };
58
- export default javascriptConfig;
@@ -1,31 +0,0 @@
1
- import { defineConfig } from 'eslint/config';
2
- import eslintPluginJsonc from 'eslint-plugin-jsonc';
3
-
4
- /**
5
- * defineConfig 会 flat 一层 extends,并且将 files 字段赋值给所有 extends
6
- * 可以借助这个函数为所有插件添加 files 约束,防止语言之间的污染
7
- */
8
- const packageJsonConfig = defineConfig({
9
- extends: [...eslintPluginJsonc.configs['flat/prettier']],
10
- files: ['package.json'],
11
- rules: {
12
- 'jsonc/sort-keys': [
13
- 'warn',
14
- {
15
- pathPattern: '^$',
16
- order: ['name', 'version', 'author', 'exports', 'types', 'main', 'module', 'scripts', 'dependencies', 'devDependencies'],
17
- },
18
- {
19
- pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
20
- order: { type: 'asc' },
21
- },
22
- {
23
- pathPattern: 'exports',
24
- order: ['types', 'require', 'import']
25
- }
26
- ],
27
- },
28
- });
29
-
30
- export { packageJsonConfig };
31
- export default packageJsonConfig;
@@ -1,26 +0,0 @@
1
- import recommended from 'eslint-plugin-prettier/recommended';
2
-
3
- const prettierConfig = [
4
- recommended,
5
- {
6
- rules: {
7
- 'prettier/prettier': [
8
- 'warn',
9
- {
10
- // 优先使用单引号
11
- singleQuote: true,
12
- printWidth: 110,
13
- // 需要分号
14
- semi: true,
15
- // 仅在 es5 中有效的结构尾随逗号
16
- trailingComma: 'es5',
17
- // 不读取 prettier 配置文件,统一走 eslint 配置
18
- usePrettierrc: false,
19
- },
20
- ],
21
- },
22
- },
23
- ];
24
-
25
- export { prettierConfig };
26
- export default prettierConfig;
@@ -1,63 +0,0 @@
1
- import eslintJs from '@eslint/js';
2
- import { defineConfig } from 'eslint/config';
3
- import eslintPluginImport from 'eslint-plugin-import';
4
- import tsEslint from 'typescript-eslint';
5
-
6
- import eslintPrettier from './prettier.js';
7
- /**
8
- * defineConfig 会 flat 一层 extends,并且将 files 字段赋值给所有 extends
9
- * 可以借助这个函数为所有插件添加 files 约束,防止语言之间的污染
10
- */
11
- const typescriptConfig = defineConfig({
12
- extends: [
13
- eslintJs.configs.recommended,
14
- ...tsEslint.configs.recommended,
15
- ...tsEslint.configs.stylistic,
16
- eslintPluginImport.flatConfigs.recommended,
17
- eslintPluginImport.flatConfigs.typescript,
18
- ...eslintPrettier,
19
- ],
20
- files: ['**/*.{ts,tsx}'],
21
- rules: {
22
- 'import/order': [
23
- 'warn',
24
- {
25
- groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'object', 'type', 'index'],
26
- 'newlines-between': 'always',
27
- pathGroupsExcludedImportTypes: ['builtin'],
28
- alphabetize: { order: 'asc', caseInsensitive: true },
29
- pathGroups: [
30
- {
31
- pattern: 'react**',
32
- group: 'external',
33
- position: 'before',
34
- },
35
- {
36
- pattern: '{@/**,@**}',
37
- group: 'internal',
38
- position: 'before',
39
- },
40
- {
41
- pattern: '**/*.{scss,json,svg,css,less}',
42
- group: 'index',
43
- position: 'after',
44
- },
45
- ],
46
- },
47
- ],
48
- '@typescript-eslint/consistent-type-imports': [
49
- 'error',
50
- { disallowTypeAnnotations: true, prefer: 'type-imports' },
51
- ],
52
- '@typescript-eslint/no-explicit-any': ['warn'],
53
- },
54
- settings: {
55
- 'import/resolver': {
56
- node: true,
57
- typescript: true,
58
- },
59
- },
60
- });
61
-
62
- export { typescriptConfig };
63
- export default typescriptConfig;
package/lib/index.js DELETED
@@ -1,17 +0,0 @@
1
- import { defineConfig } from 'eslint/config';
2
-
3
- import { javascriptConfig } from './configs/javascript.js';
4
- import { packageJsonConfig } from './configs/package.js';
5
- import { typescriptConfig } from './configs/typescript.js';
6
-
7
- export const recommended = defineConfig(javascriptConfig, typescriptConfig, packageJsonConfig);
8
- export const javascript = javascriptConfig;
9
- export const typescript = typescriptConfig;
10
- export const packageJson = packageJsonConfig;
11
-
12
- export default {
13
- recommended,
14
- javascript,
15
- typescript,
16
- packageJson,
17
- };