@fast-china/eslint-config 2.0.2 → 2.0.4
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/CHANGELOG.md +23 -1
- package/README.md +77 -18
- package/README.zh.md +77 -18
- package/dist/configs/angular.d.mts +41 -0
- package/dist/configs/angular.d.mts.map +1 -0
- package/dist/configs/angular.mjs +33 -0
- package/dist/configs/angular.mjs.map +1 -0
- package/dist/configs/common.d.mts +11 -0
- package/dist/configs/common.d.mts.map +1 -0
- package/dist/configs/common.mjs +20 -0
- package/dist/configs/common.mjs.map +1 -0
- package/dist/configs/environment.d.mts +61 -0
- package/dist/configs/environment.d.mts.map +1 -0
- package/dist/configs/environment.mjs +33 -0
- package/dist/configs/environment.mjs.map +1 -0
- package/dist/configs/ignores.d.mts +15 -0
- package/dist/configs/ignores.d.mts.map +1 -0
- package/dist/configs/ignores.mjs +32 -0
- package/dist/configs/ignores.mjs.map +1 -0
- package/dist/configs/import.d.mts +11 -0
- package/dist/configs/import.d.mts.map +1 -0
- package/dist/configs/import.mjs +21 -0
- package/dist/configs/import.mjs.map +1 -0
- package/dist/configs/index.d.mts +17 -0
- package/dist/configs/index.mjs +17 -0
- package/dist/configs/javascript.d.mts +10 -0
- package/dist/configs/javascript.d.mts.map +1 -0
- package/dist/configs/javascript.mjs +24 -0
- package/dist/configs/javascript.mjs.map +1 -0
- package/dist/configs/json.d.mts +10 -0
- package/dist/configs/json.d.mts.map +1 -0
- package/dist/configs/json.mjs +35 -0
- package/dist/configs/json.mjs.map +1 -0
- package/dist/configs/lodash.d.mts +12 -0
- package/dist/configs/lodash.d.mts.map +1 -0
- package/dist/configs/lodash.mjs +18 -0
- package/dist/configs/lodash.mjs.map +1 -0
- package/dist/configs/markdown.d.mts +10 -0
- package/dist/configs/markdown.d.mts.map +1 -0
- package/dist/configs/markdown.mjs +18 -0
- package/dist/configs/markdown.mjs.map +1 -0
- package/dist/configs/prettier.d.mts +11 -0
- package/dist/configs/prettier.d.mts.map +1 -0
- package/dist/configs/prettier.mjs +17 -0
- package/dist/configs/prettier.mjs.map +1 -0
- package/dist/configs/react.d.mts +86 -0
- package/dist/configs/react.d.mts.map +1 -0
- package/dist/configs/react.mjs +31 -0
- package/dist/configs/react.mjs.map +1 -0
- package/dist/configs/regexp.d.mts +11 -0
- package/dist/configs/regexp.d.mts.map +1 -0
- package/dist/configs/regexp.mjs +19 -0
- package/dist/configs/regexp.mjs.map +1 -0
- package/dist/configs/sort-package.d.mts +11 -0
- package/dist/configs/sort-package.d.mts.map +1 -0
- package/dist/configs/sort-package.mjs +18 -0
- package/dist/configs/sort-package.mjs.map +1 -0
- package/dist/configs/sort-tsconfig.d.mts +10 -0
- package/dist/configs/sort-tsconfig.d.mts.map +1 -0
- package/dist/configs/sort-tsconfig.mjs +18 -0
- package/dist/configs/sort-tsconfig.mjs.map +1 -0
- package/dist/configs/typescript.d.mts +60 -0
- package/dist/configs/typescript.d.mts.map +1 -0
- package/dist/configs/typescript.mjs +44 -0
- package/dist/configs/typescript.mjs.map +1 -0
- package/dist/configs/vue.d.mts +43 -0
- package/dist/configs/vue.d.mts.map +1 -0
- package/dist/configs/vue.mjs +50 -0
- package/dist/configs/vue.mjs.map +1 -0
- package/dist/constants/index.d.mts +34 -0
- package/dist/constants/index.d.mts.map +1 -0
- package/dist/constants/index.mjs +52 -0
- package/dist/constants/index.mjs.map +1 -0
- package/dist/index.d.mts +20 -147
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +31 -402
- package/dist/index.mjs.map +1 -1
- package/dist/rules/angular.d.mts +46 -0
- package/dist/rules/angular.d.mts.map +1 -0
- package/dist/rules/angular.mjs +47 -0
- package/dist/rules/angular.mjs.map +1 -0
- package/dist/rules/common.d.mts +32 -0
- package/dist/rules/common.d.mts.map +1 -0
- package/dist/rules/common.mjs +38 -0
- package/dist/rules/common.mjs.map +1 -0
- package/dist/rules/import.d.mts +24 -0
- package/dist/rules/import.d.mts.map +1 -0
- package/dist/rules/import.mjs +35 -0
- package/dist/rules/import.mjs.map +1 -0
- package/dist/rules/index.d.mts +12 -309
- package/dist/rules/index.mjs +10 -1
- package/dist/rules/javascript.d.mts +48 -0
- package/dist/rules/javascript.d.mts.map +1 -0
- package/dist/rules/javascript.mjs +49 -0
- package/dist/rules/javascript.mjs.map +1 -0
- package/dist/rules/lodash.d.mts +40 -0
- package/dist/rules/lodash.d.mts.map +1 -0
- package/dist/rules/lodash.mjs +43 -0
- package/dist/rules/lodash.mjs.map +1 -0
- package/dist/rules/react.d.mts +26 -0
- package/dist/rules/react.d.mts.map +1 -0
- package/dist/rules/react.mjs +27 -0
- package/dist/rules/react.mjs.map +1 -0
- package/dist/rules/sort-package.d.mts +32 -0
- package/dist/rules/sort-package.d.mts.map +1 -0
- package/dist/rules/sort-package.mjs +75 -0
- package/dist/rules/sort-package.mjs.map +1 -0
- package/dist/rules/sort-tsconfig.d.mts +20 -0
- package/dist/rules/sort-tsconfig.d.mts.map +1 -0
- package/dist/rules/sort-tsconfig.mjs +122 -0
- package/dist/rules/sort-tsconfig.mjs.map +1 -0
- package/dist/rules/typescript.d.mts +34 -0
- package/dist/rules/typescript.d.mts.map +1 -0
- package/dist/rules/typescript.mjs +35 -0
- package/dist/rules/typescript.mjs.map +1 -0
- package/dist/rules/vue.d.mts +24 -0
- package/dist/rules/vue.d.mts.map +1 -0
- package/dist/rules/vue.mjs +33 -0
- package/dist/rules/vue.mjs.map +1 -0
- package/dist/typegen.d.mts +1 -1
- package/docs/engineering-audit.zh.md +25 -23
- package/docs/rules-risk.md +3 -3
- package/docs/rules-risk.zh.md +3 -3
- package/package.json +16 -6
- package/dist/rules/index.d.mts.map +0 -1
- package/dist/rules.mjs +0 -477
- package/dist/rules.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,393 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
//#region src/constants/index.ts
|
|
20
|
-
/** JavaScript 与 JSX 文件;扩展名列表与 Node.js ESM/CJS 约定保持一致。 */
|
|
21
|
-
const GLOBS_JAVASCRIPT = ["**/*.{js,cjs,mjs,jsx}"];
|
|
22
|
-
/** TypeScript 与 TSX 文件;包含 TypeScript 的 ESM/CJS 专用扩展名。 */
|
|
23
|
-
const GLOBS_TYPESCRIPT = ["**/*.{ts,cts,mts,tsx}"];
|
|
24
|
-
/** Vue 3 单文件组件。 */
|
|
25
|
-
const GLOB_VUE = "**/*.vue";
|
|
26
|
-
/** Angular 组件、指令、服务等框架源码;Angular CLI 项目以 `.ts` 为标准源码扩展名。 */
|
|
27
|
-
const GLOB_ANGULAR_TYPESCRIPT = "**/*.ts";
|
|
28
|
-
/** Angular 外部模板;内联模板由 Angular 处理器提取后复用同一模板配置。 */
|
|
29
|
-
const GLOB_ANGULAR_TEMPLATE = "**/*.html";
|
|
30
|
-
/** ESLint JSON language 支持的三种 JSON 方言。 */
|
|
31
|
-
const GLOB_JSON = "**/*.json";
|
|
32
|
-
const GLOB_JSONC = "**/*.jsonc";
|
|
33
|
-
const GLOB_JSON5 = "**/*.json5";
|
|
34
|
-
/** Markdown 文档。 */
|
|
35
|
-
const GLOB_MARKDOWN = "**/*.md";
|
|
36
|
-
/** 默认由 JavaScript、TypeScript 和 Vue 规则处理的全部代码文件。 */
|
|
37
|
-
const GLOBS_CODE = [
|
|
38
|
-
...GLOBS_JAVASCRIPT,
|
|
39
|
-
...GLOBS_TYPESCRIPT,
|
|
40
|
-
GLOB_VUE
|
|
41
|
-
];
|
|
42
|
-
/**
|
|
43
|
-
* 应额外获得 Node.js 全局变量的工程文件。
|
|
44
|
-
*
|
|
45
|
-
* 这些模式还会与当前已启用的 JavaScript/TypeScript 文件模式做 AND 匹配,
|
|
46
|
-
* 因而关闭 TypeScript 后不会意外让 ESLint 接管 `.ts` 文件。
|
|
47
|
-
*/
|
|
48
|
-
const GLOBS_NODE_TOOLING = [
|
|
49
|
-
"**/*.{config,setup}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
50
|
-
"**/{scripts,bin}/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
51
|
-
"**/{test,tests}/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
52
|
-
"**/*.{test,spec}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
53
|
-
"**/cli.{js,cjs,mjs,ts,cts,mts}"
|
|
54
|
-
];
|
|
55
|
-
/** TypeScript 配置文件;它们使用 JSONC 语法并允许注释。 */
|
|
56
|
-
const GLOBS_TSCONFIG = ["**/tsconfig.json", "**/tsconfig.*.json"];
|
|
57
|
-
/** 不应交给 JSON/Markdown 解析器处理的包管理器锁文件。 */
|
|
58
|
-
const GLOBS_LOCKFILES = [
|
|
59
|
-
"**/package-lock.json",
|
|
60
|
-
"**/yarn.lock",
|
|
61
|
-
"**/pnpm-lock.yaml",
|
|
62
|
-
"**/bun.lock",
|
|
63
|
-
"**/bun.lockb",
|
|
64
|
-
"**/deno.lock"
|
|
65
|
-
];
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/configs/angular.ts
|
|
68
|
-
/**
|
|
69
|
-
* 创建 Angular TypeScript、外部 HTML 模板与内联模板配置。
|
|
70
|
-
*
|
|
71
|
-
* Angular 支持依赖工厂的 TypeScript 配置先注册 typescript-eslint 解析器;模板由
|
|
72
|
-
* Angular 专用 parser 解析,内联模板通过官方 processor 复用同一套 HTML 规则。
|
|
73
|
-
*/
|
|
74
|
-
const createAngularConfigs = ({ inlineTemplates = true, templateAccessibility = true } = {}) => defineConfig([{
|
|
75
|
-
name: inlineTemplates ? "@fast-china/angular/typescript-with-inline-templates" : "@fast-china/angular/typescript",
|
|
76
|
-
files: [GLOB_ANGULAR_TYPESCRIPT],
|
|
77
|
-
plugins: { "@angular-eslint": angularPlugin },
|
|
78
|
-
...inlineTemplates ? { processor: angularTemplatePlugin.processors["extract-inline-html"] } : {},
|
|
79
|
-
rules: angularRules
|
|
80
|
-
}, {
|
|
81
|
-
name: templateAccessibility ? "@fast-china/angular/template-accessibility" : "@fast-china/angular/template",
|
|
82
|
-
files: [GLOB_ANGULAR_TEMPLATE],
|
|
83
|
-
languageOptions: { parser: angularTemplateParser },
|
|
84
|
-
plugins: { "@angular-eslint/template": angularTemplatePlugin },
|
|
85
|
-
rules: {
|
|
86
|
-
...angularTemplateRules,
|
|
87
|
-
...templateAccessibility ? angularTemplateAccessibilityRules : {}
|
|
88
|
-
}
|
|
89
|
-
}]);
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/configs/common.ts
|
|
92
|
-
/**
|
|
93
|
-
* 创建跨 JavaScript、TypeScript 与 Vue 脚本生效的基础配置。
|
|
94
|
-
*
|
|
95
|
-
* 除公共规则外,这里还把无效的 `eslint-disable` 指令提升为错误,避免规则被移除后
|
|
96
|
-
* 留下长期失效的抑制注释。
|
|
97
|
-
*/
|
|
98
|
-
const createBaseConfigs = (files = GLOBS_CODE) => defineConfig([{
|
|
99
|
-
name: "@fast-china/common",
|
|
100
|
-
files: [...files],
|
|
101
|
-
linterOptions: { reportUnusedDisableDirectives: "error" },
|
|
102
|
-
rules: commonRules
|
|
103
|
-
}]);
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region src/configs/environment.ts
|
|
106
|
-
/**
|
|
107
|
-
* 创建运行时环境相关的 ESLint 配置。
|
|
108
|
-
*
|
|
109
|
-
* 返回两个相互独立的 Flat Config 片段:第一个为应用源码配置所选环境和项目级全局
|
|
110
|
-
* 变量;第二个仅命中配置、脚本、测试与 CLI 等工程文件,为它们配置 Node.js 全局变量
|
|
111
|
-
* 并允许使用 `console`。分离范围可以减少跨运行时的假阴性。
|
|
112
|
-
*/
|
|
113
|
-
const createEnvironmentConfigs = ({ environment = "browser", files = GLOBS_CODE, nodeFiles = GLOBS_JAVASCRIPT, globals: projectGlobals = {} } = {}) => {
|
|
114
|
-
const runtimeGlobals = {
|
|
115
|
-
...environment !== "node" ? globals.browser : {},
|
|
116
|
-
...environment !== "browser" ? globals.node : {},
|
|
117
|
-
...projectGlobals
|
|
118
|
-
};
|
|
119
|
-
const nodeToolingFiles = GLOBS_NODE_TOOLING.flatMap((nodeGlob) => nodeFiles.map((fileGlob) => [nodeGlob, fileGlob]));
|
|
120
|
-
return defineConfig([{
|
|
121
|
-
name: `@fast-china/globals/${environment}`,
|
|
122
|
-
files: [...files],
|
|
123
|
-
languageOptions: { globals: runtimeGlobals }
|
|
124
|
-
}, {
|
|
125
|
-
name: "@fast-china/globals/node-tooling",
|
|
126
|
-
files: nodeToolingFiles,
|
|
127
|
-
languageOptions: { globals: globals.node },
|
|
128
|
-
rules: { "no-console": "off" }
|
|
129
|
-
}]);
|
|
130
|
-
};
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/configs/ignores.ts
|
|
133
|
-
/**
|
|
134
|
-
* 默认忽略依赖、构建结果、缓存、生成文件和包管理器锁文件。
|
|
135
|
-
*
|
|
136
|
-
* 不忽略 `src`、`public`、测试夹具或普通 Markdown 文档,避免共享配置静默漏检
|
|
137
|
-
* 应由项目维护的文件。
|
|
138
|
-
*/
|
|
139
|
-
const DEFAULT_IGNORE_PATTERNS = Object.freeze([
|
|
140
|
-
"**/node_modules/**",
|
|
141
|
-
"**/{dist,build,coverage,output,temp,tmp}/**",
|
|
142
|
-
"**/{.cache,.nuxt,.output,.vercel,.nitro}/**",
|
|
143
|
-
"**/{.vitepress/cache,.vite-inspect}/**",
|
|
144
|
-
"**/__snapshots__/**",
|
|
145
|
-
"**/*.min.*",
|
|
146
|
-
"**/auto-import?(s).d.ts",
|
|
147
|
-
"**/components.d.ts",
|
|
148
|
-
...GLOBS_LOCKFILES
|
|
149
|
-
]);
|
|
150
|
-
/** 创建全局忽略配置,并在默认集合之后追加项目自定义模式。 */
|
|
151
|
-
const createGlobalIgnores = (additionalPatterns = []) => globalIgnores([...DEFAULT_IGNORE_PATTERNS, ...additionalPatterns], "@fast-china/ignores/global");
|
|
152
|
-
/** 读取运行 ESLint 的项目根目录中的 `.gitignore`。 */
|
|
153
|
-
const createGitignoreConfigs = () => defineConfig([{
|
|
154
|
-
name: "@fast-china/ignores/git",
|
|
155
|
-
...eslintConfigFlatGitignore({ strict: false })
|
|
156
|
-
}]);
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/configs/import.ts
|
|
159
|
-
/**
|
|
160
|
-
* 创建模块导入规则配置。
|
|
161
|
-
*
|
|
162
|
-
* 共享库不猜测项目的路径别名或解析器,因此只继承 import-x 的推荐能力,
|
|
163
|
-
* 与 resolver 强耦合且容易误报的规则会在本地规则记录中显式关闭。
|
|
164
|
-
*/
|
|
165
|
-
const createImportConfigs = (files = GLOBS_CODE) => defineConfig([{
|
|
166
|
-
name: "@fast-china/import",
|
|
167
|
-
files: [...files],
|
|
168
|
-
extends: [eslintPluginImportX.flatConfigs.recommended],
|
|
169
|
-
rules: importRules
|
|
170
|
-
}]);
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/configs/javascript.ts
|
|
173
|
-
/**
|
|
174
|
-
* 创建 JavaScript/JSX 配置。
|
|
175
|
-
*
|
|
176
|
-
* `@eslint/js` 提供基础正确性规则,本仓库只在其后补充有明确维护理由的规则。
|
|
177
|
-
*/
|
|
178
|
-
const createJavaScriptConfigs = (files = GLOBS_JAVASCRIPT) => defineConfig([{
|
|
179
|
-
name: "@fast-china/javascript",
|
|
180
|
-
files: [...files],
|
|
181
|
-
extends: [eslint.configs.recommended],
|
|
182
|
-
languageOptions: {
|
|
183
|
-
ecmaVersion: "latest",
|
|
184
|
-
parserOptions: { ecmaFeatures: { jsx: true } }
|
|
185
|
-
},
|
|
186
|
-
rules: javascriptRules
|
|
187
|
-
}]);
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region src/configs/json.ts
|
|
190
|
-
/**
|
|
191
|
-
* 创建 JSON、JSONC 与 JSON5 配置。
|
|
192
|
-
*
|
|
193
|
-
* 三种方言使用各自的官方推荐预置,避免严格 JSON 规则错误覆盖允许注释或尾随逗号的文件。
|
|
194
|
-
*/
|
|
195
|
-
const createJsonConfigs = () => defineConfig([
|
|
196
|
-
{
|
|
197
|
-
name: "@fast-china/json/json",
|
|
198
|
-
files: [GLOB_JSON],
|
|
199
|
-
extends: [eslintPluginJsonc.configs["flat/recommended-with-json"]]
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
name: "@fast-china/json/jsonc",
|
|
203
|
-
files: [GLOB_JSONC],
|
|
204
|
-
extends: [eslintPluginJsonc.configs["flat/recommended-with-jsonc"]]
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
name: "@fast-china/json/json5",
|
|
208
|
-
files: [GLOB_JSON5],
|
|
209
|
-
extends: [eslintPluginJsonc.configs["flat/recommended-with-json5"]]
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
name: "@fast-china/json/vscode-settings",
|
|
213
|
-
files: ["**/.vscode/settings.json"],
|
|
214
|
-
rules: { "jsonc/no-comments": "off" }
|
|
215
|
-
}
|
|
216
|
-
]);
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/configs/lodash.ts
|
|
219
|
-
/**
|
|
220
|
-
* 创建 Lodash 静态导入约束。
|
|
221
|
-
*
|
|
222
|
-
* 该配置使用 ESLint 核心规则,因此不依赖 import-x 开关或额外插件。
|
|
223
|
-
*/
|
|
224
|
-
const createLodashConfigs = (preference, files = GLOBS_CODE) => defineConfig([{
|
|
225
|
-
name: `@fast-china/lodash/${preference}`,
|
|
226
|
-
files: [...files],
|
|
227
|
-
rules: preference === "lodash" ? preferLodashRules : preferLodashUnifiedRules
|
|
228
|
-
}]);
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/configs/markdown.ts
|
|
231
|
-
/**
|
|
232
|
-
* 创建 Markdown 结构与语法检查配置。
|
|
233
|
-
*
|
|
234
|
-
* 该配置检查 Markdown 文档本身;代码块是否接受额外语言规则由项目覆盖配置决定。
|
|
235
|
-
*/
|
|
236
|
-
const createMarkdownConfigs = () => defineConfig([{
|
|
237
|
-
name: "@fast-china/markdown",
|
|
238
|
-
files: [GLOB_MARKDOWN],
|
|
239
|
-
extends: [eslintMarkdown.configs.recommended]
|
|
240
|
-
}]);
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/configs/prettier.ts
|
|
243
|
-
/**
|
|
244
|
-
* 创建 Prettier 兼容层。
|
|
245
|
-
*
|
|
246
|
-
* 它只关闭与 Prettier 冲突的 ESLint 格式规则,不会在 ESLint 进程中执行 Prettier。
|
|
247
|
-
* 工厂始终把它放在内置配置之后,使上游预置的格式规则能够被正确覆盖。
|
|
248
|
-
*/
|
|
249
|
-
const createPrettierConfigs = () => defineConfig([{
|
|
250
|
-
...eslintConfigPrettierFlat,
|
|
251
|
-
name: "@fast-china/prettier"
|
|
252
|
-
}]);
|
|
253
|
-
//#endregion
|
|
254
|
-
//#region src/configs/react.ts
|
|
255
|
-
/**
|
|
256
|
-
* 创建 React、JSX/TSX 与 Hooks 配置。
|
|
257
|
-
*
|
|
258
|
-
* JavaScript 和 TypeScript 分别继承对应的 @eslint-react 推荐预置;Hooks 使用
|
|
259
|
-
* React 官方 Flat Config。组件、Hooks 即使不返回 JSX 也能在普通 `.js`/`.ts` 中
|
|
260
|
-
* 定义,因此规则覆盖全部已启用脚本扩展名,而不仅是 `.jsx`/`.tsx`。
|
|
261
|
-
*/
|
|
262
|
-
const createReactConfigs = ({ importSource = "react", polymorphicPropName = "as", version = "detect" } = {}, { javascript = true, typeChecked = false, typescript = true } = {}) => {
|
|
263
|
-
const createConfig = (name, files, preset) => ({
|
|
264
|
-
name,
|
|
265
|
-
files: [...files],
|
|
266
|
-
extends: [preset, eslintPluginReactHooks.configs.flat.recommended],
|
|
267
|
-
settings: { "react-x": {
|
|
268
|
-
importSource,
|
|
269
|
-
polymorphicPropName,
|
|
270
|
-
version
|
|
271
|
-
} },
|
|
272
|
-
rules: reactRules
|
|
273
|
-
});
|
|
274
|
-
return defineConfig([...javascript ? [createConfig("@fast-china/react/javascript", GLOBS_JAVASCRIPT, eslintReact.configs.recommended)] : [], ...typescript ? [createConfig(typeChecked ? "@fast-china/react/typescript-type-checked" : "@fast-china/react/typescript", GLOBS_TYPESCRIPT, typeChecked ? eslintReact.configs["recommended-type-checked"] : eslintReact.configs["recommended-typescript"])] : []]);
|
|
275
|
-
};
|
|
276
|
-
//#endregion
|
|
277
|
-
//#region src/configs/regexp.ts
|
|
278
|
-
/**
|
|
279
|
-
* 创建正则表达式正确性配置。
|
|
280
|
-
*
|
|
281
|
-
* 插件推荐规则会检查无效、冗余或容易产生回溯问题的正则结构;部分规则可修复,
|
|
282
|
-
* 批量修复后仍需运行覆盖真实输入的项目测试。
|
|
283
|
-
*/
|
|
284
|
-
const createRegexpConfigs = (files = GLOBS_CODE) => defineConfig([{
|
|
285
|
-
name: "@fast-china/regexp",
|
|
286
|
-
files: [...files],
|
|
287
|
-
extends: [eslintPluginRegexp.configs["flat/recommended"]]
|
|
288
|
-
}]);
|
|
289
|
-
//#endregion
|
|
290
|
-
//#region src/configs/sort-package.ts
|
|
291
|
-
/**
|
|
292
|
-
* 创建 package.json 排序配置。
|
|
293
|
-
*
|
|
294
|
-
* 该能力会产生较大的可修复 diff,因此必须显式启用;规则不会进入顺序具有
|
|
295
|
-
* 条件导出语义的 `exports` 对象内部。
|
|
296
|
-
*/
|
|
297
|
-
const createPackageJsonSortConfigs = () => defineConfig([{
|
|
298
|
-
name: "@fast-china/sort/package-json",
|
|
299
|
-
files: ["**/package.json"],
|
|
300
|
-
rules: packageJsonSortRules
|
|
301
|
-
}]);
|
|
302
|
-
//#endregion
|
|
303
|
-
//#region src/configs/sort-tsconfig.ts
|
|
304
|
-
/**
|
|
305
|
-
* 创建 tsconfig.json 排序配置。
|
|
306
|
-
*
|
|
307
|
-
* 排序只改变字段阅读顺序,不改变编译选项值;由于首次修复 diff 较大,默认关闭。
|
|
308
|
-
*/
|
|
309
|
-
const createTsconfigSortConfigs = () => defineConfig([{
|
|
310
|
-
name: "@fast-china/sort/tsconfig",
|
|
311
|
-
files: [...GLOBS_TSCONFIG],
|
|
312
|
-
rules: tsconfigJsonSortRules
|
|
313
|
-
}]);
|
|
314
|
-
//#endregion
|
|
315
|
-
//#region src/configs/typescript.ts
|
|
316
|
-
/**
|
|
317
|
-
* 返回 typescript-eslint 推荐预置。
|
|
318
|
-
*
|
|
319
|
-
* Vue SFC 需要移除上游仅匹配 `.ts` 的文件范围,否则这些关闭核心规则的配置会与
|
|
320
|
-
* `.vue` 外层范围形成不可能命中的 AND 条件。
|
|
321
|
-
*/
|
|
322
|
-
const getTypeScriptPresetConfigs = (typeChecked, removeFileScopes = false) => {
|
|
323
|
-
const configs = [...typeChecked ? tseslint.configs.recommendedTypeChecked : tseslint.configs.recommended, ...typeChecked ? tseslint.configs.stylisticTypeChecked : tseslint.configs.stylistic];
|
|
324
|
-
if (!removeFileScopes) return configs;
|
|
325
|
-
return configs.map((config) => {
|
|
326
|
-
const { files: _files, ...configWithoutFiles } = config;
|
|
327
|
-
return configWithoutFiles;
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
/** 创建启用 Project Service 时需要的解析器选项。 */
|
|
331
|
-
const createTypeScriptParserOptions = ({ typeChecked = false, tsconfigRootDir } = {}) => ({
|
|
332
|
-
...typeChecked ? { projectService: true } : {},
|
|
333
|
-
...typeChecked && tsconfigRootDir ? { tsconfigRootDir } : {}
|
|
334
|
-
});
|
|
1
|
+
import { GLOBS_JAVASCRIPT, GLOBS_TYPESCRIPT, GLOB_VUE } from "./constants/index.mjs";
|
|
2
|
+
import { createAngularConfigs } from "./configs/angular.mjs";
|
|
3
|
+
import { createCommonConfigs } from "./configs/common.mjs";
|
|
4
|
+
import { createEnvironmentConfigs } from "./configs/environment.mjs";
|
|
5
|
+
import { createGitignoreConfigs, createGlobalIgnores } from "./configs/ignores.mjs";
|
|
6
|
+
import { createImportConfigs } from "./configs/import.mjs";
|
|
7
|
+
import { createJavaScriptConfigs } from "./configs/javascript.mjs";
|
|
8
|
+
import { createJsonConfigs } from "./configs/json.mjs";
|
|
9
|
+
import { createMarkdownConfigs } from "./configs/markdown.mjs";
|
|
10
|
+
import { createPrettierConfigs } from "./configs/prettier.mjs";
|
|
11
|
+
import { createReactConfigs } from "./configs/react.mjs";
|
|
12
|
+
import { createRegexpConfigs } from "./configs/regexp.mjs";
|
|
13
|
+
import { createPackageJsonSortConfigs } from "./configs/sort-package.mjs";
|
|
14
|
+
import { createTsconfigSortConfigs } from "./configs/sort-tsconfig.mjs";
|
|
15
|
+
import { createTypeScriptConfigs } from "./configs/typescript.mjs";
|
|
16
|
+
import { createVueConfigs } from "./configs/vue.mjs";
|
|
17
|
+
import { defineConfig } from "eslint/config";
|
|
18
|
+
//#region src/index.ts
|
|
335
19
|
/**
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* 默认采用无需类型信息的 recommended + stylistic 预置;`typeChecked: true` 会切换为
|
|
339
|
-
* 对应的类型感知预置并启动 Project Service。
|
|
20
|
+
* 根入口提供面向 Vue 3 浏览器管理项目的默认配置工厂。
|
|
21
|
+
* 配置片段、glob 常量与原始规则分别由 `./configs`、`./constants` 与 `./rules` 子路径提供。
|
|
340
22
|
*/
|
|
341
|
-
const createTypeScriptConfigs = (options = {}, files = GLOBS_TYPESCRIPT) => defineConfig([{
|
|
342
|
-
name: options.typeChecked ? "@fast-china/typescript/type-checked" : "@fast-china/typescript",
|
|
343
|
-
files: [...files],
|
|
344
|
-
extends: getTypeScriptPresetConfigs(options.typeChecked ?? false),
|
|
345
|
-
languageOptions: {
|
|
346
|
-
ecmaVersion: "latest",
|
|
347
|
-
parserOptions: createTypeScriptParserOptions(options)
|
|
348
|
-
},
|
|
349
|
-
rules: typescriptRules
|
|
350
|
-
}]);
|
|
351
|
-
//#endregion
|
|
352
|
-
//#region src/configs/vue.ts
|
|
353
23
|
/**
|
|
354
|
-
*
|
|
24
|
+
* 为项目规则提供精确的规则名、严重级别和规则选项自动补全。
|
|
355
25
|
*
|
|
356
|
-
*
|
|
357
|
-
* 委托给 typescript-eslint;这是 Vue 官方推荐的自定义脚本解析器接入方式。
|
|
26
|
+
* 该函数不会修改传入对象;它只在 TypeScript 编译阶段拒绝未知规则和无效选项。
|
|
358
27
|
*/
|
|
359
|
-
const
|
|
360
|
-
const typeChecked = typescriptOptions.typeChecked ?? false;
|
|
361
|
-
const typeScriptConfigs = typescript ? getTypeScriptPresetConfigs(typeChecked, true) : [];
|
|
362
|
-
return defineConfig([{
|
|
363
|
-
name: typeChecked ? "@fast-china/vue/type-checked" : "@fast-china/vue",
|
|
364
|
-
files: [GLOB_VUE],
|
|
365
|
-
extends: [
|
|
366
|
-
eslint.configs.recommended,
|
|
367
|
-
...typeScriptConfigs,
|
|
368
|
-
...eslintPluginVue.configs["flat/recommended"]
|
|
369
|
-
],
|
|
370
|
-
languageOptions: {
|
|
371
|
-
ecmaVersion: "latest",
|
|
372
|
-
parser: vueEslintParser,
|
|
373
|
-
parserOptions: {
|
|
374
|
-
...typescript ? {
|
|
375
|
-
parser: tseslint.parser,
|
|
376
|
-
extraFileExtensions: [".vue"]
|
|
377
|
-
} : {},
|
|
378
|
-
ecmaFeatures: { jsx: true },
|
|
379
|
-
sourceType: "module",
|
|
380
|
-
...createTypeScriptParserOptions(typescriptOptions)
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
rules: {
|
|
384
|
-
...typescript ? typescriptRules : {},
|
|
385
|
-
...vueRules
|
|
386
|
-
}
|
|
387
|
-
}]);
|
|
388
|
-
};
|
|
389
|
-
//#endregion
|
|
390
|
-
//#region src/code/index.ts
|
|
28
|
+
const defineRules = (rules) => rules;
|
|
391
29
|
/** `fastConfig()` 使用的稳定默认值;对象被冻结,避免运行时被意外修改。 */
|
|
392
30
|
const defaultConfigOptions = Object.freeze({
|
|
393
31
|
angular: false,
|
|
@@ -396,8 +34,7 @@ const defaultConfigOptions = Object.freeze({
|
|
|
396
34
|
imports: true,
|
|
397
35
|
javascript: true,
|
|
398
36
|
json: true,
|
|
399
|
-
|
|
400
|
-
markdown: true,
|
|
37
|
+
markdown: false,
|
|
401
38
|
prettier: true,
|
|
402
39
|
react: false,
|
|
403
40
|
regexp: true,
|
|
@@ -407,10 +44,12 @@ const defaultConfigOptions = Object.freeze({
|
|
|
407
44
|
vue: true
|
|
408
45
|
});
|
|
409
46
|
/**
|
|
410
|
-
* 创建面向 Vue 3、
|
|
47
|
+
* 创建面向 Vue 3、Vite、TypeScript 与浏览器后台管理项目的 ESLint Flat Config。
|
|
411
48
|
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
49
|
+
* 默认启用浏览器环境、JavaScript、TypeScript、Vue 3、import、RegExp、JSON 和
|
|
50
|
+
* Prettier 兼容层。React、Angular、Markdown 与清单排序按需启用;Lodash 导入策略
|
|
51
|
+
* 通过 `@fast-china/eslint-config/configs` 独立组合。
|
|
52
|
+
* 额外配置参数会放在内置配置之后,因此项目可以按文件范围覆盖任何默认规则。
|
|
414
53
|
*/
|
|
415
54
|
const fastConfig = (options = {}, ...overrides) => {
|
|
416
55
|
const angular = options.angular ?? defaultConfigOptions.angular;
|
|
@@ -419,7 +58,6 @@ const fastConfig = (options = {}, ...overrides) => {
|
|
|
419
58
|
const imports = options.imports ?? defaultConfigOptions.imports;
|
|
420
59
|
const javascript = options.javascript ?? defaultConfigOptions.javascript;
|
|
421
60
|
const json = options.json ?? defaultConfigOptions.json;
|
|
422
|
-
const lodash = options.lodash ?? defaultConfigOptions.lodash;
|
|
423
61
|
const markdown = options.markdown ?? defaultConfigOptions.markdown;
|
|
424
62
|
const prettier = options.prettier ?? defaultConfigOptions.prettier;
|
|
425
63
|
const react = options.react ?? defaultConfigOptions.react;
|
|
@@ -440,17 +78,16 @@ const fastConfig = (options = {}, ...overrides) => {
|
|
|
440
78
|
const codeFiles = [...scriptFiles, ...vue ? [GLOB_VUE] : []];
|
|
441
79
|
const jsonEnabled = json || sortPackageJson || sortTsconfig;
|
|
442
80
|
return defineConfig([
|
|
443
|
-
createGlobalIgnores(options.ignores),
|
|
81
|
+
...createGlobalIgnores(options.ignores),
|
|
444
82
|
...gitignore ? createGitignoreConfigs() : [],
|
|
445
83
|
...codeFiles.length ? [...createEnvironmentConfigs({
|
|
446
84
|
environment,
|
|
447
85
|
files: codeFiles,
|
|
448
86
|
globals: options.globals,
|
|
449
87
|
nodeFiles: scriptFiles
|
|
450
|
-
}), ...
|
|
88
|
+
}), ...createCommonConfigs(codeFiles)] : [],
|
|
451
89
|
...javascript ? createJavaScriptConfigs() : [],
|
|
452
90
|
...imports && codeFiles.length ? createImportConfigs(codeFiles) : [],
|
|
453
|
-
...lodash && codeFiles.length ? createLodashConfigs(lodash, codeFiles) : [],
|
|
454
91
|
...regexp && codeFiles.length ? createRegexpConfigs(codeFiles) : [],
|
|
455
92
|
...typeScriptEnabled ? createTypeScriptConfigs(typeScriptOptions) : [],
|
|
456
93
|
...jsonEnabled ? createJsonConfigs() : [],
|
|
@@ -477,14 +114,6 @@ const fastConfig = (options = {}, ...overrides) => {
|
|
|
477
114
|
]);
|
|
478
115
|
};
|
|
479
116
|
//#endregion
|
|
480
|
-
//#region src/index.ts
|
|
481
|
-
/**
|
|
482
|
-
* 为项目规则提供精确的规则名、严重级别和规则选项自动补全。
|
|
483
|
-
*
|
|
484
|
-
* 该函数不会修改传入对象;它只在 TypeScript 编译阶段拒绝未知规则和无效选项。
|
|
485
|
-
*/
|
|
486
|
-
const defineRules = (rules) => rules;
|
|
487
|
-
//#endregion
|
|
488
117
|
export { fastConfig as default, fastConfig, defaultConfigOptions, defineRules };
|
|
489
118
|
|
|
490
119
|
//# sourceMappingURL=index.mjs.map
|