@fast-china/eslint-config 2.1.6 → 2.1.8
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 +35 -0
- package/CONTRIBUTING.md +2 -2
- package/README.md +66 -142
- package/README.zh.md +64 -142
- package/dist/configs/environment.mjs +2 -0
- package/dist/configs/environment.mjs.map +1 -1
- package/dist/configs/ignores.mjs +0 -1
- package/dist/configs/ignores.mjs.map +1 -1
- package/dist/configs/import.mjs +4 -1
- package/dist/configs/import.mjs.map +1 -1
- package/dist/configs/index.d.mts +2 -2
- package/dist/configs/index.mjs +2 -2
- package/dist/configs/javascript.mjs +3 -1
- package/dist/configs/javascript.mjs.map +1 -1
- package/dist/configs/json.mjs +3 -1
- package/dist/configs/json.mjs.map +1 -1
- package/dist/configs/markdown.d.mts +2 -1
- package/dist/configs/markdown.mjs +4 -2
- package/dist/configs/markdown.mjs.map +1 -1
- package/dist/configs/prettier.mjs +1 -1
- package/dist/configs/prettier.mjs.map +1 -1
- package/dist/configs/sort-package.d.mts +1 -1
- package/dist/configs/sort-package.mjs +1 -1
- package/dist/configs/sort-package.mjs.map +1 -1
- package/dist/configs/sort-tsconfig.d.mts +2 -2
- package/dist/configs/sort-tsconfig.mjs +2 -2
- package/dist/configs/sort-tsconfig.mjs.map +1 -1
- package/dist/configs/typescript.d.mts +11 -7
- package/dist/configs/typescript.mjs +26 -19
- package/dist/configs/typescript.mjs.map +1 -1
- package/dist/configs/uniapp.mjs +19 -13
- package/dist/configs/uniapp.mjs.map +1 -1
- package/dist/configs/vue.d.mts +18 -3
- package/dist/configs/vue.mjs +60 -9
- package/dist/configs/vue.mjs.map +1 -1
- package/dist/constants/index.d.mts +4 -0
- package/dist/constants/index.mjs +5 -1
- package/dist/constants/index.mjs.map +1 -1
- package/dist/index.d.mts +37 -58
- package/dist/index.mjs +43 -47
- package/dist/index.mjs.map +1 -1
- package/dist/rules/angular.d.mts +28 -0
- package/dist/rules/angular.mjs +28 -0
- package/dist/rules/angular.mjs.map +1 -1
- package/dist/rules/common.d.mts +19 -6
- package/dist/rules/common.mjs +19 -13
- package/dist/rules/common.mjs.map +1 -1
- package/dist/rules/import.d.mts +9 -0
- package/dist/rules/import.mjs +24 -0
- package/dist/rules/import.mjs.map +1 -1
- package/dist/rules/index.d.mts +2 -2
- package/dist/rules/index.mjs +2 -2
- package/dist/rules/javascript.d.mts +18 -0
- package/dist/rules/javascript.mjs +18 -0
- package/dist/rules/javascript.mjs.map +1 -1
- package/dist/rules/lodash.d.mts +2 -0
- package/dist/rules/lodash.mjs +6 -2
- package/dist/rules/lodash.mjs.map +1 -1
- package/dist/rules/react.d.mts +13 -0
- package/dist/rules/react.mjs +13 -0
- package/dist/rules/react.mjs.map +1 -1
- package/dist/rules/regexp.d.mts +25 -0
- package/dist/rules/regexp.mjs +25 -0
- package/dist/rules/regexp.mjs.map +1 -1
- package/dist/rules/sort-package.d.mts +3 -1
- package/dist/rules/sort-package.mjs +3 -1
- package/dist/rules/sort-package.mjs.map +1 -1
- package/dist/rules/sort-tsconfig.d.mts +3 -1
- package/dist/rules/sort-tsconfig.mjs +3 -1
- package/dist/rules/sort-tsconfig.mjs.map +1 -1
- package/dist/rules/typescript.d.mts +82 -13
- package/dist/rules/typescript.mjs +85 -16
- package/dist/rules/typescript.mjs.map +1 -1
- package/dist/rules/vue.d.mts +67 -10
- package/dist/rules/vue.mjs +43 -14
- package/dist/rules/vue.mjs.map +1 -1
- package/docs/engineering-audit.zh.md +45 -49
- package/docs/rules/angular.zh.md +721 -0
- package/docs/rules/core.zh.md +3031 -0
- package/docs/rules/index.zh.md +38 -0
- package/docs/rules/json.zh.md +784 -0
- package/docs/rules/markdown.zh.md +449 -0
- package/docs/rules/react.zh.md +2091 -0
- package/docs/rules/typescript.zh.md +2051 -0
- package/docs/rules/vue.zh.md +3016 -0
- package/docs/rules-risk.md +85 -90
- package/docs/rules-risk.zh.md +76 -81
- package/package.json +4 -2
|
@@ -2,7 +2,7 @@ import { defineConfig } from "eslint/config";
|
|
|
2
2
|
import { Linter } from "eslint";
|
|
3
3
|
//#region src/configs/typescript.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* 返回 typescript-eslint
|
|
5
|
+
* 返回 typescript-eslint 通用且类型感知的官方预置。
|
|
6
6
|
*
|
|
7
7
|
* @returns ESLint 核心推荐规则与对应的 typescript-eslint 推荐预置。
|
|
8
8
|
*/
|
|
@@ -11,22 +11,26 @@ export declare const getTypeScriptPresetConfigs: () => Linter.Config[];
|
|
|
11
11
|
* 创建 TypeScript 解析器的 Project Service 选项。
|
|
12
12
|
*
|
|
13
13
|
* @remarks
|
|
14
|
-
* TypeScript
|
|
15
|
-
* TypeScript Server 会因扩展名集合变化而反复重载整个项目。
|
|
14
|
+
* 同一个项目组合中的 TypeScript 与框架文件必须使用完全一致的 `extraFileExtensions`。
|
|
15
|
+
* 否则混合检查文件时,TypeScript Server 会因扩展名集合变化而反复重载整个项目。
|
|
16
16
|
*
|
|
17
|
-
* @
|
|
17
|
+
* @param extraFileExtensions - 当前项目组合需要交给 TypeScript Project Service 的额外扩展名。
|
|
18
|
+
* @returns 始终启用 `projectService` 的解析器选项。
|
|
18
19
|
*/
|
|
19
|
-
export declare const createTypeScriptParserOptions: () => Linter.ParserOptions;
|
|
20
|
+
export declare const createTypeScriptParserOptions: (extraFileExtensions?: readonly string[]) => Linter.ParserOptions;
|
|
20
21
|
/**
|
|
21
22
|
* 创建 TypeScript 配置。
|
|
22
23
|
*
|
|
23
24
|
* @remarks
|
|
24
|
-
* 始终采用 ESLint 与 typescript-eslint 的 `
|
|
25
|
+
* 始终采用 ESLint 与 typescript-eslint 的 `recommendedTypeChecked` 预置并启动 Project Service,
|
|
26
|
+
* 再由本地规则补充公共模块契约、简洁写法和高价值正确性检查。普通 TypeScript 文件
|
|
27
|
+
* 按 SDK 式模块边界检查;TSX 保留同等类型安全,但允许组件返回类型使用上下文推断。
|
|
25
28
|
* 被检查文件必须属于可发现的 tsconfig。特殊项目可在后置 Flat Config 中覆盖解析器选项。
|
|
26
29
|
*
|
|
27
30
|
* @param files - 应用 TypeScript 配置的 ESLint glob 列表。
|
|
31
|
+
* @param extraFileExtensions - 与同一项目组合中的框架解析器保持一致的额外扩展名。
|
|
28
32
|
* @returns 包含 TypeScript 预置、解析器选项与本地规则的 Flat Config 数组。
|
|
29
33
|
*/
|
|
30
|
-
export declare const createTypeScriptConfigs: (files?: readonly string[]) => ReturnType<typeof defineConfig>;
|
|
34
|
+
export declare const createTypeScriptConfigs: (files?: readonly string[], extraFileExtensions?: readonly string[]) => ReturnType<typeof defineConfig>;
|
|
31
35
|
//#endregion
|
|
32
36
|
//# sourceMappingURL=typescript.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GLOBS_TYPESCRIPT } from "../constants/index.mjs";
|
|
1
|
+
import { GLOBS_TYPESCRIPT, GLOB_TSX } from "../constants/index.mjs";
|
|
2
2
|
import { javascriptRules } from "../rules/javascript.mjs";
|
|
3
3
|
import { typescriptRules, typescriptTypeCheckedRules } from "../rules/typescript.mjs";
|
|
4
4
|
import { defineConfig } from "eslint/config";
|
|
@@ -6,54 +6,61 @@ import eslint from "@eslint/js";
|
|
|
6
6
|
import tseslint from "typescript-eslint";
|
|
7
7
|
//#region src/configs/typescript.ts
|
|
8
8
|
/**
|
|
9
|
-
* 返回 typescript-eslint
|
|
9
|
+
* 返回 typescript-eslint 通用且类型感知的官方预置。
|
|
10
10
|
*
|
|
11
11
|
* @returns ESLint 核心推荐规则与对应的 typescript-eslint 推荐预置。
|
|
12
12
|
*/
|
|
13
|
-
const getTypeScriptPresetConfigs = () => [
|
|
14
|
-
eslint.configs.recommended,
|
|
15
|
-
{
|
|
16
|
-
name: "@fast-china/typescript/javascript-rules",
|
|
17
|
-
rules: javascriptRules
|
|
18
|
-
},
|
|
19
|
-
...tseslint.configs.strictTypeChecked,
|
|
20
|
-
...tseslint.configs.stylisticTypeChecked
|
|
21
|
-
];
|
|
13
|
+
const getTypeScriptPresetConfigs = () => [eslint.configs.recommended, ...tseslint.configs.recommendedTypeChecked];
|
|
22
14
|
/**
|
|
23
15
|
* 创建 TypeScript 解析器的 Project Service 选项。
|
|
24
16
|
*
|
|
25
17
|
* @remarks
|
|
26
|
-
* TypeScript
|
|
27
|
-
* TypeScript Server 会因扩展名集合变化而反复重载整个项目。
|
|
18
|
+
* 同一个项目组合中的 TypeScript 与框架文件必须使用完全一致的 `extraFileExtensions`。
|
|
19
|
+
* 否则混合检查文件时,TypeScript Server 会因扩展名集合变化而反复重载整个项目。
|
|
28
20
|
*
|
|
29
|
-
* @
|
|
21
|
+
* @param extraFileExtensions - 当前项目组合需要交给 TypeScript Project Service 的额外扩展名。
|
|
22
|
+
* @returns 始终启用 `projectService` 的解析器选项。
|
|
30
23
|
*/
|
|
31
|
-
const createTypeScriptParserOptions = () => ({
|
|
24
|
+
const createTypeScriptParserOptions = (extraFileExtensions = []) => ({
|
|
32
25
|
projectService: true,
|
|
33
|
-
extraFileExtensions: [
|
|
26
|
+
...extraFileExtensions.length > 0 ? { extraFileExtensions: [...extraFileExtensions] } : {}
|
|
34
27
|
});
|
|
35
28
|
/**
|
|
36
29
|
* 创建 TypeScript 配置。
|
|
37
30
|
*
|
|
38
31
|
* @remarks
|
|
39
|
-
* 始终采用 ESLint 与 typescript-eslint 的 `
|
|
32
|
+
* 始终采用 ESLint 与 typescript-eslint 的 `recommendedTypeChecked` 预置并启动 Project Service,
|
|
33
|
+
* 再由本地规则补充公共模块契约、简洁写法和高价值正确性检查。普通 TypeScript 文件
|
|
34
|
+
* 按 SDK 式模块边界检查;TSX 保留同等类型安全,但允许组件返回类型使用上下文推断。
|
|
40
35
|
* 被检查文件必须属于可发现的 tsconfig。特殊项目可在后置 Flat Config 中覆盖解析器选项。
|
|
41
36
|
*
|
|
42
37
|
* @param files - 应用 TypeScript 配置的 ESLint glob 列表。
|
|
38
|
+
* @param extraFileExtensions - 与同一项目组合中的框架解析器保持一致的额外扩展名。
|
|
43
39
|
* @returns 包含 TypeScript 预置、解析器选项与本地规则的 Flat Config 数组。
|
|
44
40
|
*/
|
|
45
|
-
const createTypeScriptConfigs = (files = GLOBS_TYPESCRIPT) => defineConfig([{
|
|
41
|
+
const createTypeScriptConfigs = (files = GLOBS_TYPESCRIPT, extraFileExtensions = []) => defineConfig([{
|
|
46
42
|
name: "@fast-china/typescript/type-checked",
|
|
47
43
|
files: [...files],
|
|
48
44
|
extends: getTypeScriptPresetConfigs(),
|
|
49
45
|
languageOptions: {
|
|
50
46
|
ecmaVersion: "latest",
|
|
51
|
-
parserOptions: createTypeScriptParserOptions()
|
|
47
|
+
parserOptions: createTypeScriptParserOptions(extraFileExtensions)
|
|
52
48
|
},
|
|
53
49
|
rules: {
|
|
50
|
+
...javascriptRules,
|
|
54
51
|
...typescriptRules,
|
|
55
52
|
...typescriptTypeCheckedRules
|
|
56
53
|
}
|
|
54
|
+
}, {
|
|
55
|
+
name: "@fast-china/typescript/tsx",
|
|
56
|
+
/** 与调用方传入的 TypeScript 范围取交集,避免独立组合时意外接管范围外的 TSX 文件。 */
|
|
57
|
+
files: files.map((file) => [file, GLOB_TSX]),
|
|
58
|
+
rules: {
|
|
59
|
+
/** TSX 通常用于 UI 组件,不强制为导出组件补写可由 TypeScript 稳定推断的 JSX 返回类型。 */
|
|
60
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
61
|
+
/** TSX 事件属性由框架接管异步结果,允许把 Promise 返回函数传给 `void` 回调属性;其他误用继续检查。 */
|
|
62
|
+
"@typescript-eslint/no-misused-promises": ["error", { checksVoidReturn: { attributes: false } }]
|
|
63
|
+
}
|
|
57
64
|
}]);
|
|
58
65
|
//#endregion
|
|
59
66
|
export { createTypeScriptConfigs, createTypeScriptParserOptions, getTypeScriptPresetConfigs };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.mjs","names":[],"sources":["../../src/configs/typescript.ts"],"sourcesContent":["import eslint from \"@eslint/js\";\nimport { defineConfig } from \"eslint/config\";\nimport tseslint from \"typescript-eslint\";\nimport { GLOBS_TYPESCRIPT } from \"../constants\";\nimport { javascriptRules, typescriptRules, typescriptTypeCheckedRules } from \"../rules\";\nimport type { Linter } from \"eslint\";\n\n/**\n * 返回 typescript-eslint
|
|
1
|
+
{"version":3,"file":"typescript.mjs","names":[],"sources":["../../src/configs/typescript.ts"],"sourcesContent":["import eslint from \"@eslint/js\";\nimport { defineConfig } from \"eslint/config\";\nimport tseslint from \"typescript-eslint\";\nimport { GLOBS_TYPESCRIPT, GLOB_TSX } from \"../constants\";\nimport { javascriptRules, typescriptRules, typescriptTypeCheckedRules } from \"../rules\";\nimport type { Linter } from \"eslint\";\n\n/**\n * 返回 typescript-eslint 通用且类型感知的官方预置。\n *\n * @returns ESLint 核心推荐规则与对应的 typescript-eslint 推荐预置。\n */\nexport const getTypeScriptPresetConfigs = (): Linter.Config[] =>\n\t[eslint.configs.recommended, ...tseslint.configs.recommendedTypeChecked] as Linter.Config[];\n\n/**\n * 创建 TypeScript 解析器的 Project Service 选项。\n *\n * @remarks\n * 同一个项目组合中的 TypeScript 与框架文件必须使用完全一致的 `extraFileExtensions`。\n * 否则混合检查文件时,TypeScript Server 会因扩展名集合变化而反复重载整个项目。\n *\n * @param extraFileExtensions - 当前项目组合需要交给 TypeScript Project Service 的额外扩展名。\n * @returns 始终启用 `projectService` 的解析器选项。\n */\nexport const createTypeScriptParserOptions = (extraFileExtensions: readonly string[] = []): Linter.ParserOptions => ({\n\tprojectService: true,\n\t...(extraFileExtensions.length > 0 ? { extraFileExtensions: [...extraFileExtensions] } : {}),\n});\n\n/**\n * 创建 TypeScript 配置。\n *\n * @remarks\n * 始终采用 ESLint 与 typescript-eslint 的 `recommendedTypeChecked` 预置并启动 Project Service,\n * 再由本地规则补充公共模块契约、简洁写法和高价值正确性检查。普通 TypeScript 文件\n * 按 SDK 式模块边界检查;TSX 保留同等类型安全,但允许组件返回类型使用上下文推断。\n * 被检查文件必须属于可发现的 tsconfig。特殊项目可在后置 Flat Config 中覆盖解析器选项。\n *\n * @param files - 应用 TypeScript 配置的 ESLint glob 列表。\n * @param extraFileExtensions - 与同一项目组合中的框架解析器保持一致的额外扩展名。\n * @returns 包含 TypeScript 预置、解析器选项与本地规则的 Flat Config 数组。\n */\nexport const createTypeScriptConfigs = (\n\tfiles: readonly string[] = GLOBS_TYPESCRIPT,\n\textraFileExtensions: readonly string[] = []\n): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/typescript/type-checked\",\n\t\t\tfiles: [...files],\n\t\t\textends: getTypeScriptPresetConfigs(),\n\t\t\tlanguageOptions: {\n\t\t\t\tecmaVersion: \"latest\",\n\t\t\t\tparserOptions: createTypeScriptParserOptions(extraFileExtensions),\n\t\t\t},\n\t\t\trules: {\n\t\t\t\t...javascriptRules,\n\t\t\t\t...typescriptRules,\n\t\t\t\t...typescriptTypeCheckedRules,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/typescript/tsx\",\n\t\t\t/** 与调用方传入的 TypeScript 范围取交集,避免独立组合时意外接管范围外的 TSX 文件。 */\n\t\t\tfiles: files.map((file) => [file, GLOB_TSX]),\n\t\t\trules: {\n\t\t\t\t/** TSX 通常用于 UI 组件,不强制为导出组件补写可由 TypeScript 稳定推断的 JSX 返回类型。 */\n\t\t\t\t\"@typescript-eslint/explicit-module-boundary-types\": \"off\",\n\t\t\t\t/** TSX 事件属性由框架接管异步结果,允许把 Promise 返回函数传给 `void` 回调属性;其他误用继续检查。 */\n\t\t\t\t\"@typescript-eslint/no-misused-promises\": [\"error\", { checksVoidReturn: { attributes: false } }],\n\t\t\t},\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,mCACZ,CAAC,OAAO,QAAQ,aAAa,GAAG,SAAS,QAAQ,sBAAsB;;;;;;;;;;;AAYxE,MAAa,iCAAiC,sBAAyC,CAAC,OAA6B;CACpH,gBAAgB;CAChB,GAAI,oBAAoB,SAAS,IAAI,EAAE,qBAAqB,CAAC,GAAG,mBAAmB,EAAE,IAAI,CAAC;AAC3F;;;;;;;;;;;;;;AAeA,MAAa,2BACZ,QAA2B,kBAC3B,sBAAyC,CAAC,MAE1C,aAAa,CACZ;CACC,MAAM;CACN,OAAO,CAAC,GAAG,KAAK;CAChB,SAAS,2BAA2B;CACpC,iBAAiB;EAChB,aAAa;EACb,eAAe,8BAA8B,mBAAmB;CACjE;CACA,OAAO;EACN,GAAG;EACH,GAAG;EACH,GAAG;CACJ;AACD,GACA;CACC,MAAM;;CAEN,OAAO,MAAM,KAAK,SAAS,CAAC,MAAM,QAAQ,CAAC;CAC3C,OAAO;;EAEN,qDAAqD;;EAErD,0CAA0C,CAAC,SAAS,EAAE,kBAAkB,EAAE,YAAY,MAAM,EAAE,CAAC;CAChG;AACD,CACD,CAAC"}
|
package/dist/configs/uniapp.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GLOBS_CODE, GLOBS_UNIAPP_JSON, UNIAPP_CONDITIONAL_GLOBALS, UNIAPP_GLOBALS } from "../constants/index.mjs";
|
|
2
|
-
import { defineConfig } from "eslint/config";
|
|
2
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
3
3
|
//#region src/configs/uniapp.ts
|
|
4
4
|
/**
|
|
5
5
|
* 创建 UniApp 跨端运行时与项目清单适配。
|
|
@@ -12,18 +12,24 @@ import { defineConfig } from "eslint/config";
|
|
|
12
12
|
* @param files - 应用 UniApp 公共全局变量的代码文件 glob。
|
|
13
13
|
* @returns UniApp globals 与 JSON 注释兼容配置。
|
|
14
14
|
*/
|
|
15
|
-
const createUniAppConfigs = (files = GLOBS_CODE) => defineConfig([
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
...
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const createUniAppConfigs = (files = GLOBS_CODE) => defineConfig([
|
|
16
|
+
globalIgnores(["**/unpackage/**"], "@fast-china/uniapp/ignores"),
|
|
17
|
+
{
|
|
18
|
+
name: "@fast-china/uniapp/globals",
|
|
19
|
+
files: [...files],
|
|
20
|
+
languageOptions: { globals: {
|
|
21
|
+
...UNIAPP_GLOBALS,
|
|
22
|
+
...UNIAPP_CONDITIONAL_GLOBALS
|
|
23
|
+
} }
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "@fast-china/uniapp/json",
|
|
27
|
+
files: [...GLOBS_UNIAPP_JSON],
|
|
28
|
+
rules: {
|
|
29
|
+
/** UniApp 的 `pages.json` 和 `manifest.json` 使用允许注释的 JSONC 方言。 */
|
|
30
|
+
"jsonc/no-comments": "off" }
|
|
31
|
+
}
|
|
32
|
+
]);
|
|
27
33
|
//#endregion
|
|
28
34
|
export { createUniAppConfigs };
|
|
29
35
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniapp.mjs","names":[],"sources":["../../src/configs/uniapp.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport { GLOBS_CODE, GLOBS_UNIAPP_JSON, UNIAPP_CONDITIONAL_GLOBALS, UNIAPP_GLOBALS } from \"../constants\";\n\n/**\n * 创建 UniApp 跨端运行时与项目清单适配。\n *\n * @remarks\n * 除跨端公共 API 外,也声明条件编译分支常用的 `wx`、`plus`、`my`、`tt` 等平台对象。\n * ESLint 不执行 UniApp 预处理器,因此这些对象在整个 UniApp 文件内可见;该配置不会验证\n * 对象是否位于正确的 `#ifdef` 分支中。`.nvue` 的解析由 Vue 配置负责。\n *\n * @param files - 应用 UniApp 公共全局变量的代码文件 glob。\n * @returns UniApp globals 与 JSON 注释兼容配置。\n */\nexport const createUniAppConfigs = (files: readonly string[] = GLOBS_CODE): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/uniapp/globals\",\n\t\t\tfiles: [...files],\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: {\n\t\t\t\t\t...UNIAPP_GLOBALS,\n\t\t\t\t\t...UNIAPP_CONDITIONAL_GLOBALS,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/uniapp/json\",\n\t\t\tfiles: [...GLOBS_UNIAPP_JSON],\n\t\t\trules: {\n\t\t\t\t
|
|
1
|
+
{"version":3,"file":"uniapp.mjs","names":[],"sources":["../../src/configs/uniapp.ts"],"sourcesContent":["import { defineConfig, globalIgnores } from \"eslint/config\";\nimport { GLOBS_CODE, GLOBS_UNIAPP_JSON, UNIAPP_CONDITIONAL_GLOBALS, UNIAPP_GLOBALS } from \"../constants\";\n\n/**\n * 创建 UniApp 跨端运行时与项目清单适配。\n *\n * @remarks\n * 除跨端公共 API 外,也声明条件编译分支常用的 `wx`、`plus`、`my`、`tt` 等平台对象。\n * ESLint 不执行 UniApp 预处理器,因此这些对象在整个 UniApp 文件内可见;该配置不会验证\n * 对象是否位于正确的 `#ifdef` 分支中。`.nvue` 的解析由 Vue 配置负责。\n *\n * @param files - 应用 UniApp 公共全局变量的代码文件 glob。\n * @returns UniApp globals 与 JSON 注释兼容配置。\n */\nexport const createUniAppConfigs = (files: readonly string[] = GLOBS_CODE): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\tglobalIgnores([\"**/unpackage/**\"], \"@fast-china/uniapp/ignores\"),\n\t\t{\n\t\t\tname: \"@fast-china/uniapp/globals\",\n\t\t\tfiles: [...files],\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: {\n\t\t\t\t\t...UNIAPP_GLOBALS,\n\t\t\t\t\t...UNIAPP_CONDITIONAL_GLOBALS,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/uniapp/json\",\n\t\t\tfiles: [...GLOBS_UNIAPP_JSON],\n\t\t\trules: {\n\t\t\t\t/** UniApp 的 `pages.json` 和 `manifest.json` 使用允许注释的 JSONC 方言。 */\n\t\t\t\t\"jsonc/no-comments\": \"off\",\n\t\t\t},\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,uBAAuB,QAA2B,eAC9D,aAAa;CACZ,cAAc,CAAC,iBAAiB,GAAG,4BAA4B;CAC/D;EACC,MAAM;EACN,OAAO,CAAC,GAAG,KAAK;EAChB,iBAAiB,EAChB,SAAS;GACR,GAAG;GACH,GAAG;EACJ,EACD;CACD;CACA;EACC,MAAM;EACN,OAAO,CAAC,GAAG,iBAAiB;EAC5B,OAAO;;AAEN,qBAAqB,MACtB;CACD;AACD,CAAC"}
|
package/dist/configs/vue.d.mts
CHANGED
|
@@ -4,11 +4,26 @@ import { defineConfig } from "eslint/config";
|
|
|
4
4
|
* 创建 Vue 3 单文件组件配置。
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Vue 模板解析器通过 `parserOptions.parser` 委托给 typescript-eslint,统一使用类型感知检查。
|
|
8
|
+
* UniApp 项目可传入 `.nvue` 文件范围及对应扩展名;普通 Vue 项目默认只处理 `.vue`。
|
|
9
9
|
*
|
|
10
|
+
* @param files - 应用 Vue 解析器与规则的单文件组件 glob。
|
|
11
|
+
* @param extraFileExtensions - 与同一项目组合中的 TypeScript 配置保持一致的额外扩展名。
|
|
10
12
|
* @returns 包含 Vue 模板、脚本解析器、推荐预置与本地规则的 Flat Config 数组。
|
|
11
13
|
*/
|
|
12
|
-
export declare const createVueConfigs: () => ReturnType<typeof defineConfig>;
|
|
14
|
+
export declare const createVueConfigs: (files?: readonly string[], extraFileExtensions?: readonly string[]) => ReturnType<typeof defineConfig>;
|
|
15
|
+
/**
|
|
16
|
+
* 创建 Vue JSX 与 TSX 组件脚本语义配置。
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* `vue-eslint-parser` 会为独立 JSX/TSX 建立 eslint-plugin-vue 所需的组件脚本访问器;
|
|
20
|
+
* TSX 继续委托给 typescript-eslint 并复用项目的 Project Service。这里只加载适用于
|
|
21
|
+
* `defineComponent()`、Options API 与 `setup()` 的脚本规则,不把 kebab-case、模板属性
|
|
22
|
+
* 排序或 `v-text`/`v-html` 等模板节点规则套到 JSX 属性上。
|
|
23
|
+
*
|
|
24
|
+
* @param extraFileExtensions - 与同一项目组合中的 TypeScript 和 SFC 配置保持一致的额外扩展名。
|
|
25
|
+
* @returns 分别处理独立 `.jsx` 与 `.tsx` Vue 组件的 Flat Config 数组。
|
|
26
|
+
*/
|
|
27
|
+
export declare const createVueJsxConfigs: (extraFileExtensions?: readonly string[]) => ReturnType<typeof defineConfig>;
|
|
13
28
|
//#endregion
|
|
14
29
|
//# sourceMappingURL=vue.d.mts.map
|
package/dist/configs/vue.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GLOB_JSX, GLOB_TSX, GLOB_VUE } from "../constants/index.mjs";
|
|
2
|
+
import { javascriptRules } from "../rules/javascript.mjs";
|
|
2
3
|
import { typescriptRules, typescriptTypeCheckedRules } from "../rules/typescript.mjs";
|
|
3
|
-
import { vueRules } from "../rules/vue.mjs";
|
|
4
|
+
import { vueRules, vueScriptRules } from "../rules/vue.mjs";
|
|
4
5
|
import { createTypeScriptParserOptions, getTypeScriptPresetConfigs } from "./typescript.mjs";
|
|
5
6
|
import { defineConfig } from "eslint/config";
|
|
6
7
|
import tseslint from "typescript-eslint";
|
|
@@ -11,14 +12,16 @@ import vueEslintParser from "vue-eslint-parser";
|
|
|
11
12
|
* 创建 Vue 3 单文件组件配置。
|
|
12
13
|
*
|
|
13
14
|
* @remarks
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* Vue 模板解析器通过 `parserOptions.parser` 委托给 typescript-eslint,统一使用类型感知检查。
|
|
16
|
+
* UniApp 项目可传入 `.nvue` 文件范围及对应扩展名;普通 Vue 项目默认只处理 `.vue`。
|
|
16
17
|
*
|
|
18
|
+
* @param files - 应用 Vue 解析器与规则的单文件组件 glob。
|
|
19
|
+
* @param extraFileExtensions - 与同一项目组合中的 TypeScript 配置保持一致的额外扩展名。
|
|
17
20
|
* @returns 包含 Vue 模板、脚本解析器、推荐预置与本地规则的 Flat Config 数组。
|
|
18
21
|
*/
|
|
19
|
-
const createVueConfigs = () => defineConfig([{
|
|
22
|
+
const createVueConfigs = (files = [GLOB_VUE], extraFileExtensions = [".vue"]) => defineConfig([{
|
|
20
23
|
name: "@fast-china/vue/type-checked",
|
|
21
|
-
files: [
|
|
24
|
+
files: [...files],
|
|
22
25
|
extends: [...getTypeScriptPresetConfigs(), ...eslintPluginVue.configs["flat/recommended"]],
|
|
23
26
|
languageOptions: {
|
|
24
27
|
ecmaVersion: "latest",
|
|
@@ -27,15 +30,22 @@ const createVueConfigs = () => defineConfig([{
|
|
|
27
30
|
parser: tseslint.parser,
|
|
28
31
|
ecmaFeatures: { jsx: true },
|
|
29
32
|
sourceType: "module",
|
|
30
|
-
...createTypeScriptParserOptions()
|
|
33
|
+
...createTypeScriptParserOptions(extraFileExtensions)
|
|
31
34
|
}
|
|
32
35
|
},
|
|
33
36
|
rules: {
|
|
34
|
-
|
|
37
|
+
/** Vue SFC 显式接管 TypeScript 预置中的核心规则替换,再由本地策略做最终覆写。 */
|
|
38
|
+
...tseslint.configs.recommendedTypeChecked[1]?.rules ?? {},
|
|
39
|
+
...javascriptRules,
|
|
35
40
|
...typescriptRules,
|
|
36
41
|
...typescriptTypeCheckedRules,
|
|
42
|
+
/** SFC 以模板上下文和快速迭代为主,不强制补写函数返回类型。 */
|
|
37
43
|
"@typescript-eslint/explicit-function-return-type": "off",
|
|
44
|
+
/** SFC 的导出宏由 Vue 编译器建立契约,不强制补写普通模块边界类型。 */
|
|
38
45
|
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
46
|
+
/** Vue 模板事件由框架接管异步结果,允许 Promise 返回的事件处理函数;其他 Promise 误用继续检查。 */
|
|
47
|
+
"@typescript-eslint/no-misused-promises": ["error", { checksVoidReturn: { attributes: false } }],
|
|
48
|
+
/** `defineEmits` 校验器和框架回调的形参可只声明契约;普通未使用变量和导入仍然报错。 */
|
|
39
49
|
"@typescript-eslint/no-unused-vars": ["error", {
|
|
40
50
|
args: "none",
|
|
41
51
|
caughtErrors: "none",
|
|
@@ -44,7 +54,48 @@ const createVueConfigs = () => defineConfig([{
|
|
|
44
54
|
...vueRules
|
|
45
55
|
}
|
|
46
56
|
}]);
|
|
57
|
+
/**
|
|
58
|
+
* 创建 Vue JSX 与 TSX 组件脚本语义配置。
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* `vue-eslint-parser` 会为独立 JSX/TSX 建立 eslint-plugin-vue 所需的组件脚本访问器;
|
|
62
|
+
* TSX 继续委托给 typescript-eslint 并复用项目的 Project Service。这里只加载适用于
|
|
63
|
+
* `defineComponent()`、Options API 与 `setup()` 的脚本规则,不把 kebab-case、模板属性
|
|
64
|
+
* 排序或 `v-text`/`v-html` 等模板节点规则套到 JSX 属性上。
|
|
65
|
+
*
|
|
66
|
+
* @param extraFileExtensions - 与同一项目组合中的 TypeScript 和 SFC 配置保持一致的额外扩展名。
|
|
67
|
+
* @returns 分别处理独立 `.jsx` 与 `.tsx` Vue 组件的 Flat Config 数组。
|
|
68
|
+
*/
|
|
69
|
+
const createVueJsxConfigs = (extraFileExtensions = [".vue"]) => defineConfig([{
|
|
70
|
+
name: "@fast-china/vue/jsx",
|
|
71
|
+
files: [GLOB_JSX],
|
|
72
|
+
plugins: { vue: eslintPluginVue },
|
|
73
|
+
languageOptions: {
|
|
74
|
+
ecmaVersion: "latest",
|
|
75
|
+
parser: vueEslintParser,
|
|
76
|
+
parserOptions: {
|
|
77
|
+
ecmaFeatures: { jsx: true },
|
|
78
|
+
sourceType: "module"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
rules: vueScriptRules
|
|
82
|
+
}, {
|
|
83
|
+
name: "@fast-china/vue/tsx-type-checked",
|
|
84
|
+
files: [GLOB_TSX],
|
|
85
|
+
plugins: { vue: eslintPluginVue },
|
|
86
|
+
languageOptions: {
|
|
87
|
+
ecmaVersion: "latest",
|
|
88
|
+
parser: vueEslintParser,
|
|
89
|
+
parserOptions: {
|
|
90
|
+
parser: tseslint.parser,
|
|
91
|
+
ecmaFeatures: { jsx: true },
|
|
92
|
+
sourceType: "module",
|
|
93
|
+
...createTypeScriptParserOptions(extraFileExtensions)
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
rules: vueScriptRules
|
|
97
|
+
}]);
|
|
47
98
|
//#endregion
|
|
48
|
-
export { createVueConfigs };
|
|
99
|
+
export { createVueConfigs, createVueJsxConfigs };
|
|
49
100
|
|
|
50
101
|
//# sourceMappingURL=vue.mjs.map
|
package/dist/configs/vue.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.mjs","names":[],"sources":["../../src/configs/vue.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport eslintPluginVue from \"eslint-plugin-vue\";\nimport tseslint from \"typescript-eslint\";\nimport vueEslintParser from \"vue-eslint-parser\";\nimport {
|
|
1
|
+
{"version":3,"file":"vue.mjs","names":[],"sources":["../../src/configs/vue.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport eslintPluginVue from \"eslint-plugin-vue\";\nimport tseslint from \"typescript-eslint\";\nimport vueEslintParser from \"vue-eslint-parser\";\nimport { GLOB_JSX, GLOB_TSX, GLOB_VUE } from \"../constants\";\nimport { javascriptRules, typescriptRules, typescriptTypeCheckedRules, vueRules, vueScriptRules } from \"../rules\";\nimport { createTypeScriptParserOptions, getTypeScriptPresetConfigs } from \"./typescript\";\n\n/**\n * 创建 Vue 3 单文件组件配置。\n *\n * @remarks\n * Vue 模板解析器通过 `parserOptions.parser` 委托给 typescript-eslint,统一使用类型感知检查。\n * UniApp 项目可传入 `.nvue` 文件范围及对应扩展名;普通 Vue 项目默认只处理 `.vue`。\n *\n * @param files - 应用 Vue 解析器与规则的单文件组件 glob。\n * @param extraFileExtensions - 与同一项目组合中的 TypeScript 配置保持一致的额外扩展名。\n * @returns 包含 Vue 模板、脚本解析器、推荐预置与本地规则的 Flat Config 数组。\n */\nexport const createVueConfigs = (\n\tfiles: readonly string[] = [GLOB_VUE],\n\textraFileExtensions: readonly string[] = [\".vue\"]\n): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/vue/type-checked\",\n\t\t\tfiles: [...files],\n\t\t\textends: [...getTypeScriptPresetConfigs(), ...eslintPluginVue.configs[\"flat/recommended\"]],\n\t\t\tlanguageOptions: {\n\t\t\t\tecmaVersion: \"latest\",\n\t\t\t\tparser: vueEslintParser,\n\t\t\t\tparserOptions: {\n\t\t\t\t\tparser: tseslint.parser,\n\t\t\t\t\tecmaFeatures: {\n\t\t\t\t\t\tjsx: true,\n\t\t\t\t\t},\n\t\t\t\t\tsourceType: \"module\",\n\t\t\t\t\t...createTypeScriptParserOptions(extraFileExtensions),\n\t\t\t\t},\n\t\t\t},\n\t\t\trules: {\n\t\t\t\t/** Vue SFC 显式接管 TypeScript 预置中的核心规则替换,再由本地策略做最终覆写。 */\n\t\t\t\t...(tseslint.configs.recommendedTypeChecked[1]?.rules ?? {}),\n\t\t\t\t...javascriptRules,\n\t\t\t\t...typescriptRules,\n\t\t\t\t...typescriptTypeCheckedRules,\n\t\t\t\t/** SFC 以模板上下文和快速迭代为主,不强制补写函数返回类型。 */\n\t\t\t\t\"@typescript-eslint/explicit-function-return-type\": \"off\",\n\t\t\t\t/** SFC 的导出宏由 Vue 编译器建立契约,不强制补写普通模块边界类型。 */\n\t\t\t\t\"@typescript-eslint/explicit-module-boundary-types\": \"off\",\n\t\t\t\t/** Vue 模板事件由框架接管异步结果,允许 Promise 返回的事件处理函数;其他 Promise 误用继续检查。 */\n\t\t\t\t\"@typescript-eslint/no-misused-promises\": [\"error\", { checksVoidReturn: { attributes: false } }],\n\t\t\t\t/** `defineEmits` 校验器和框架回调的形参可只声明契约;普通未使用变量和导入仍然报错。 */\n\t\t\t\t\"@typescript-eslint/no-unused-vars\": [\"error\", { args: \"none\", caughtErrors: \"none\", ignoreRestSiblings: true }],\n\t\t\t\t...vueRules,\n\t\t\t},\n\t\t},\n\t]);\n\n/**\n * 创建 Vue JSX 与 TSX 组件脚本语义配置。\n *\n * @remarks\n * `vue-eslint-parser` 会为独立 JSX/TSX 建立 eslint-plugin-vue 所需的组件脚本访问器;\n * TSX 继续委托给 typescript-eslint 并复用项目的 Project Service。这里只加载适用于\n * `defineComponent()`、Options API 与 `setup()` 的脚本规则,不把 kebab-case、模板属性\n * 排序或 `v-text`/`v-html` 等模板节点规则套到 JSX 属性上。\n *\n * @param extraFileExtensions - 与同一项目组合中的 TypeScript 和 SFC 配置保持一致的额外扩展名。\n * @returns 分别处理独立 `.jsx` 与 `.tsx` Vue 组件的 Flat Config 数组。\n */\nexport const createVueJsxConfigs = (extraFileExtensions: readonly string[] = [\".vue\"]): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/vue/jsx\",\n\t\t\tfiles: [GLOB_JSX],\n\t\t\tplugins: {\n\t\t\t\tvue: eslintPluginVue,\n\t\t\t},\n\t\t\tlanguageOptions: {\n\t\t\t\tecmaVersion: \"latest\",\n\t\t\t\tparser: vueEslintParser,\n\t\t\t\tparserOptions: {\n\t\t\t\t\tecmaFeatures: {\n\t\t\t\t\t\tjsx: true,\n\t\t\t\t\t},\n\t\t\t\t\tsourceType: \"module\",\n\t\t\t\t},\n\t\t\t},\n\t\t\trules: vueScriptRules,\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/vue/tsx-type-checked\",\n\t\t\tfiles: [GLOB_TSX],\n\t\t\tplugins: {\n\t\t\t\tvue: eslintPluginVue,\n\t\t\t},\n\t\t\tlanguageOptions: {\n\t\t\t\tecmaVersion: \"latest\",\n\t\t\t\tparser: vueEslintParser,\n\t\t\t\tparserOptions: {\n\t\t\t\t\tparser: tseslint.parser,\n\t\t\t\t\tecmaFeatures: {\n\t\t\t\t\t\tjsx: true,\n\t\t\t\t\t},\n\t\t\t\t\tsourceType: \"module\",\n\t\t\t\t\t...createTypeScriptParserOptions(extraFileExtensions),\n\t\t\t\t},\n\t\t\t},\n\t\t\trules: vueScriptRules,\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,oBACZ,QAA2B,CAAC,QAAQ,GACpC,sBAAyC,CAAC,MAAM,MAEhD,aAAa,CACZ;CACC,MAAM;CACN,OAAO,CAAC,GAAG,KAAK;CAChB,SAAS,CAAC,GAAG,2BAA2B,GAAG,GAAG,gBAAgB,QAAQ,mBAAmB;CACzF,iBAAiB;EAChB,aAAa;EACb,QAAQ;EACR,eAAe;GACd,QAAQ,SAAS;GACjB,cAAc,EACb,KAAK,KACN;GACA,YAAY;GACZ,GAAG,8BAA8B,mBAAmB;EACrD;CACD;CACA,OAAO;;EAEN,GAAI,SAAS,QAAQ,uBAAuB,EAAE,EAAE,SAAS,CAAC;EAC1D,GAAG;EACH,GAAG;EACH,GAAG;;EAEH,oDAAoD;;EAEpD,qDAAqD;;EAErD,0CAA0C,CAAC,SAAS,EAAE,kBAAkB,EAAE,YAAY,MAAM,EAAE,CAAC;;EAE/F,qCAAqC,CAAC,SAAS;GAAE,MAAM;GAAQ,cAAc;GAAQ,oBAAoB;EAAK,CAAC;EAC/G,GAAG;CACJ;AACD,CACD,CAAC;;;;;;;;;;;;;AAcF,MAAa,uBAAuB,sBAAyC,CAAC,MAAM,MACnF,aAAa,CACZ;CACC,MAAM;CACN,OAAO,CAAC,QAAQ;CAChB,SAAS,EACR,KAAK,gBACN;CACA,iBAAiB;EAChB,aAAa;EACb,QAAQ;EACR,eAAe;GACd,cAAc,EACb,KAAK,KACN;GACA,YAAY;EACb;CACD;CACA,OAAO;AACR,GACA;CACC,MAAM;CACN,OAAO,CAAC,QAAQ;CAChB,SAAS,EACR,KAAK,gBACN;CACA,iBAAiB;EAChB,aAAa;EACb,QAAQ;EACR,eAAe;GACd,QAAQ,SAAS;GACjB,cAAc,EACb,KAAK,KACN;GACA,YAAY;GACZ,GAAG,8BAA8B,mBAAmB;EACrD;CACD;CACA,OAAO;AACR,CACD,CAAC"}
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
export declare const GLOBS_JAVASCRIPT: readonly ["**/*.{js,cjs,mjs,jsx}"];
|
|
13
13
|
/** TypeScript 与 TSX 文件;包含 TypeScript 的 ESM/CJS 专用扩展名。 */
|
|
14
14
|
export declare const GLOBS_TYPESCRIPT: readonly ["**/*.{ts,cts,mts,tsx}"];
|
|
15
|
+
/** 独立 JSX 文件;用于为 Vue 等 JSX 运行时叠加组件脚本语义规则。 */
|
|
16
|
+
export declare const GLOB_JSX = "**/*.jsx";
|
|
17
|
+
/** 独立 TSX 文件;用于在完整 TypeScript 范围内叠加 UI 组件专项规则。 */
|
|
18
|
+
export declare const GLOB_TSX = "**/*.tsx";
|
|
15
19
|
/** Vue 3 单文件组件。 */
|
|
16
20
|
export declare const GLOB_VUE = "**/*.vue";
|
|
17
21
|
/** UniApp 原生渲染页面使用的 Vue 单文件组件。 */
|
package/dist/constants/index.mjs
CHANGED
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
const GLOBS_JAVASCRIPT = ["**/*.{js,cjs,mjs,jsx}"];
|
|
13
13
|
/** TypeScript 与 TSX 文件;包含 TypeScript 的 ESM/CJS 专用扩展名。 */
|
|
14
14
|
const GLOBS_TYPESCRIPT = ["**/*.{ts,cts,mts,tsx}"];
|
|
15
|
+
/** 独立 JSX 文件;用于为 Vue 等 JSX 运行时叠加组件脚本语义规则。 */
|
|
16
|
+
const GLOB_JSX = "**/*.jsx";
|
|
17
|
+
/** 独立 TSX 文件;用于在完整 TypeScript 范围内叠加 UI 组件专项规则。 */
|
|
18
|
+
const GLOB_TSX = "**/*.tsx";
|
|
15
19
|
/** Vue 3 单文件组件。 */
|
|
16
20
|
const GLOB_VUE = "**/*.vue";
|
|
17
21
|
/** UniApp 原生渲染页面使用的 Vue 单文件组件。 */
|
|
@@ -89,6 +93,6 @@ const GLOBS_LOCKFILES = [
|
|
|
89
93
|
"**/deno.lock"
|
|
90
94
|
];
|
|
91
95
|
//#endregion
|
|
92
|
-
export { GLOBS_CODE, GLOBS_JAVASCRIPT, GLOBS_LOCKFILES, GLOBS_NODE_TOOLING, GLOBS_TSCONFIG, GLOBS_TYPESCRIPT, GLOBS_UNIAPP_JSON, GLOB_ANGULAR_TEMPLATE, GLOB_ANGULAR_TYPESCRIPT, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_MARKDOWN, GLOB_NVUE, GLOB_VUE, UNIAPP_CONDITIONAL_GLOBALS, UNIAPP_GLOBALS };
|
|
96
|
+
export { GLOBS_CODE, GLOBS_JAVASCRIPT, GLOBS_LOCKFILES, GLOBS_NODE_TOOLING, GLOBS_TSCONFIG, GLOBS_TYPESCRIPT, GLOBS_UNIAPP_JSON, GLOB_ANGULAR_TEMPLATE, GLOB_ANGULAR_TYPESCRIPT, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_MARKDOWN, GLOB_NVUE, GLOB_TSX, GLOB_VUE, UNIAPP_CONDITIONAL_GLOBALS, UNIAPP_GLOBALS };
|
|
93
97
|
|
|
94
98
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/constants/index.ts"],"sourcesContent":["/**\n * `@fast-china/eslint-config/constants` 公开的文件匹配常量。\n *\n * @remarks\n * 所有模式均使用 ESLint Flat Config 的 glob 语义,可直接用于配置的 `files` 或\n * `ignores` 字段。数组常量使用只读元组类型,调用方组合时应复制而非原地修改。\n *\n * @packageDocumentation\n */\n\n/** JavaScript 与 JSX 文件;扩展名列表与 Node.js ESM/CJS 约定保持一致。 */\nexport const GLOBS_JAVASCRIPT = [\"**/*.{js,cjs,mjs,jsx}\"] as const;\n\n/** TypeScript 与 TSX 文件;包含 TypeScript 的 ESM/CJS 专用扩展名。 */\nexport const GLOBS_TYPESCRIPT = [\"**/*.{ts,cts,mts,tsx}\"] as const;\n\n/** Vue 3 单文件组件。 */\nexport const GLOB_VUE = \"**/*.vue\";\n\n/** UniApp 原生渲染页面使用的 Vue 单文件组件。 */\nexport const GLOB_NVUE = \"**/*.nvue\";\n\n/** Angular 组件、指令、服务等框架源码;Angular CLI 项目以 `.ts` 为标准源码扩展名。 */\nexport const GLOB_ANGULAR_TYPESCRIPT = \"**/*.ts\";\n\n/** Angular 外部模板;内联模板由 Angular 处理器提取后复用同一模板配置。 */\nexport const GLOB_ANGULAR_TEMPLATE = \"**/*.html\";\n\n/** 严格 JSON 文件。 */\nexport const GLOB_JSON = \"**/*.json\";\n/** 允许注释与尾随逗号的 JSONC 文件。 */\nexport const GLOB_JSONC = \"**/*.jsonc\";\n/** 使用 JSON5 语法的配置文件。 */\nexport const GLOB_JSON5 = \"**/*.json5\";\n\n/** Markdown 文档。 */\nexport const GLOB_MARKDOWN = \"**/*.md\";\n\n/** UniApp 项目允许使用注释的应用清单和页面路由配置。 */\nexport const GLOBS_UNIAPP_JSON = [\"**/manifest.json\", \"**/pages.json\"] as const;\n\n/** UniApp 跨端运行时提供的公共全局变量。 */\nexport const UNIAPP_GLOBALS = {\n\tgetApp: \"readonly\",\n\tgetCurrentPages: \"readonly\",\n\tgetCurrentSubNVue: \"readonly\",\n\tuni: \"readonly\",\n\tuniCloud: \"readonly\",\n} as const;\n\n/**\n * UniApp 条件编译分支中可能由目标平台注入的全局变量。\n *\n * @remarks\n * ESLint 不执行 `#ifdef`/`#endif` 预处理,因此启用 UniApp 后统一声明这些对象。它们只解决\n * 静态 `no-undef`,不会验证当前发行目标是否真的提供对应 API。\n */\nexport const UNIAPP_CONDITIONAL_GLOBALS = {\n\tdd: \"readonly\",\n\tjd: \"readonly\",\n\tks: \"readonly\",\n\tmy: \"readonly\",\n\tplus: \"readonly\",\n\tqh: \"readonly\",\n\tqq: \"readonly\",\n\tswan: \"readonly\",\n\ttt: \"readonly\",\n\tweex: \"readonly\",\n\twx: \"readonly\",\n} as const;\n\n/** 默认由 JavaScript、TypeScript 和 Vue 规则处理的全部代码文件。 */\nexport const GLOBS_CODE = [...GLOBS_JAVASCRIPT, ...GLOBS_TYPESCRIPT, GLOB_VUE] as const;\n\n/**\n * 应额外获得 Node.js 全局变量的工程文件。\n *\n * 这些模式还会与当前已启用的 JavaScript/TypeScript 文件模式做 AND 匹配,\n * 因而关闭 TypeScript 后不会意外让 ESLint 接管 `.ts` 文件。\n */\nexport const GLOBS_NODE_TOOLING = [\n\t\"**/*.{config,setup}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}\",\n\t\"**/{scripts,bin}/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}\",\n\t\"**/{test,tests}/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}\",\n\t\"**/*.{test,spec}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}\",\n\t\"**/cli.{js,cjs,mjs,ts,cts,mts}\",\n] as const;\n\n/** TypeScript 配置文件;它们使用 JSONC 语法并允许注释。 */\nexport const GLOBS_TSCONFIG = [\"**/tsconfig.json\", \"**/tsconfig.*.json\"] as const;\n\n/** 不应交给 JSON/Markdown 解析器处理的包管理器锁文件。 */\nexport const GLOBS_LOCKFILES = [\"**/package-lock.json\", \"**/yarn.lock\", \"**/pnpm-lock.yaml\", \"**/bun.lock\", \"**/bun.lockb\", \"**/deno.lock\"] as const;\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,mBAAmB,CAAC,uBAAuB;;AAGxD,MAAa,mBAAmB,CAAC,uBAAuB;;AAGxD,MAAa,WAAW;;AAGxB,MAAa,YAAY;;AAGzB,MAAa,0BAA0B;;AAGvC,MAAa,wBAAwB;;AAGrC,MAAa,YAAY;;AAEzB,MAAa,aAAa;;AAE1B,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAG7B,MAAa,oBAAoB,CAAC,oBAAoB,eAAe;;AAGrE,MAAa,iBAAiB;CAC7B,QAAQ;CACR,iBAAiB;CACjB,mBAAmB;CACnB,KAAK;CACL,UAAU;AACX;;;;;;;;AASA,MAAa,6BAA6B;CACzC,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,MAAM;CACN,IAAI;AACL;;AAGA,MAAa,aAAa;CAAC,GAAG;CAAkB,GAAG;CAAkB;AAAQ;;;;;;;AAQ7E,MAAa,qBAAqB;CACjC;CACA;CACA;CACA;CACA;AACD;;AAGA,MAAa,iBAAiB,CAAC,oBAAoB,oBAAoB;;AAGvE,MAAa,kBAAkB;CAAC;CAAwB;CAAgB;CAAqB;CAAe;CAAgB;AAAc"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/constants/index.ts"],"sourcesContent":["/**\n * `@fast-china/eslint-config/constants` 公开的文件匹配常量。\n *\n * @remarks\n * 所有模式均使用 ESLint Flat Config 的 glob 语义,可直接用于配置的 `files` 或\n * `ignores` 字段。数组常量使用只读元组类型,调用方组合时应复制而非原地修改。\n *\n * @packageDocumentation\n */\n\n/** JavaScript 与 JSX 文件;扩展名列表与 Node.js ESM/CJS 约定保持一致。 */\nexport const GLOBS_JAVASCRIPT = [\"**/*.{js,cjs,mjs,jsx}\"] as const;\n\n/** TypeScript 与 TSX 文件;包含 TypeScript 的 ESM/CJS 专用扩展名。 */\nexport const GLOBS_TYPESCRIPT = [\"**/*.{ts,cts,mts,tsx}\"] as const;\n\n/** 独立 JSX 文件;用于为 Vue 等 JSX 运行时叠加组件脚本语义规则。 */\nexport const GLOB_JSX = \"**/*.jsx\";\n\n/** 独立 TSX 文件;用于在完整 TypeScript 范围内叠加 UI 组件专项规则。 */\nexport const GLOB_TSX = \"**/*.tsx\";\n\n/** Vue 3 单文件组件。 */\nexport const GLOB_VUE = \"**/*.vue\";\n\n/** UniApp 原生渲染页面使用的 Vue 单文件组件。 */\nexport const GLOB_NVUE = \"**/*.nvue\";\n\n/** Angular 组件、指令、服务等框架源码;Angular CLI 项目以 `.ts` 为标准源码扩展名。 */\nexport const GLOB_ANGULAR_TYPESCRIPT = \"**/*.ts\";\n\n/** Angular 外部模板;内联模板由 Angular 处理器提取后复用同一模板配置。 */\nexport const GLOB_ANGULAR_TEMPLATE = \"**/*.html\";\n\n/** 严格 JSON 文件。 */\nexport const GLOB_JSON = \"**/*.json\";\n/** 允许注释与尾随逗号的 JSONC 文件。 */\nexport const GLOB_JSONC = \"**/*.jsonc\";\n/** 使用 JSON5 语法的配置文件。 */\nexport const GLOB_JSON5 = \"**/*.json5\";\n\n/** Markdown 文档。 */\nexport const GLOB_MARKDOWN = \"**/*.md\";\n\n/** UniApp 项目允许使用注释的应用清单和页面路由配置。 */\nexport const GLOBS_UNIAPP_JSON = [\"**/manifest.json\", \"**/pages.json\"] as const;\n\n/** UniApp 跨端运行时提供的公共全局变量。 */\nexport const UNIAPP_GLOBALS = {\n\tgetApp: \"readonly\",\n\tgetCurrentPages: \"readonly\",\n\tgetCurrentSubNVue: \"readonly\",\n\tuni: \"readonly\",\n\tuniCloud: \"readonly\",\n} as const;\n\n/**\n * UniApp 条件编译分支中可能由目标平台注入的全局变量。\n *\n * @remarks\n * ESLint 不执行 `#ifdef`/`#endif` 预处理,因此启用 UniApp 后统一声明这些对象。它们只解决\n * 静态 `no-undef`,不会验证当前发行目标是否真的提供对应 API。\n */\nexport const UNIAPP_CONDITIONAL_GLOBALS = {\n\tdd: \"readonly\",\n\tjd: \"readonly\",\n\tks: \"readonly\",\n\tmy: \"readonly\",\n\tplus: \"readonly\",\n\tqh: \"readonly\",\n\tqq: \"readonly\",\n\tswan: \"readonly\",\n\ttt: \"readonly\",\n\tweex: \"readonly\",\n\twx: \"readonly\",\n} as const;\n\n/** 默认由 JavaScript、TypeScript 和 Vue 规则处理的全部代码文件。 */\nexport const GLOBS_CODE = [...GLOBS_JAVASCRIPT, ...GLOBS_TYPESCRIPT, GLOB_VUE] as const;\n\n/**\n * 应额外获得 Node.js 全局变量的工程文件。\n *\n * 这些模式还会与当前已启用的 JavaScript/TypeScript 文件模式做 AND 匹配,\n * 因而关闭 TypeScript 后不会意外让 ESLint 接管 `.ts` 文件。\n */\nexport const GLOBS_NODE_TOOLING = [\n\t\"**/*.{config,setup}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}\",\n\t\"**/{scripts,bin}/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}\",\n\t\"**/{test,tests}/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}\",\n\t\"**/*.{test,spec}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}\",\n\t\"**/cli.{js,cjs,mjs,ts,cts,mts}\",\n] as const;\n\n/** TypeScript 配置文件;它们使用 JSONC 语法并允许注释。 */\nexport const GLOBS_TSCONFIG = [\"**/tsconfig.json\", \"**/tsconfig.*.json\"] as const;\n\n/** 不应交给 JSON/Markdown 解析器处理的包管理器锁文件。 */\nexport const GLOBS_LOCKFILES = [\"**/package-lock.json\", \"**/yarn.lock\", \"**/pnpm-lock.yaml\", \"**/bun.lock\", \"**/bun.lockb\", \"**/deno.lock\"] as const;\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,mBAAmB,CAAC,uBAAuB;;AAGxD,MAAa,mBAAmB,CAAC,uBAAuB;;AAGxD,MAAa,WAAW;;AAGxB,MAAa,WAAW;;AAGxB,MAAa,WAAW;;AAGxB,MAAa,YAAY;;AAGzB,MAAa,0BAA0B;;AAGvC,MAAa,wBAAwB;;AAGrC,MAAa,YAAY;;AAEzB,MAAa,aAAa;;AAE1B,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAG7B,MAAa,oBAAoB,CAAC,oBAAoB,eAAe;;AAGrE,MAAa,iBAAiB;CAC7B,QAAQ;CACR,iBAAiB;CACjB,mBAAmB;CACnB,KAAK;CACL,UAAU;AACX;;;;;;;;AASA,MAAa,6BAA6B;CACzC,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,MAAM;CACN,IAAI;AACL;;AAGA,MAAa,aAAa;CAAC,GAAG;CAAkB,GAAG;CAAkB;AAAQ;;;;;;;AAQ7E,MAAa,qBAAqB;CACjC;CACA;CACA;CACA;CACA;AACD;;AAGA,MAAa,iBAAiB,CAAC,oBAAoB,oBAAoB;;AAGvE,MAAa,kBAAkB;CAAC;CAAwB;CAAgB;CAAqB;CAAe;CAAgB;AAAc"}
|
package/dist/index.d.mts
CHANGED
|
@@ -5,84 +5,63 @@ import { Linter } from "eslint";
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
type RejectUnknownRuleNames<Rules extends RuleOptions> = Rules & Record<Exclude<keyof Rules, keyof RuleOptions>, never>;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* 定义带有完整规则名与选项类型检查的 ESLint 规则记录。
|
|
9
9
|
*
|
|
10
10
|
* @remarks
|
|
11
|
-
*
|
|
11
|
+
* 该辅助函数只提供 TypeScript 类型约束,不会克隆、规范化或修改传入对象。规则记录可以
|
|
12
|
+
* 直接放入 Flat Config 的 `rules` 字段,也可以与本包导出的规则记录组合。
|
|
12
13
|
*
|
|
13
|
-
* @typeParam Rules -
|
|
14
|
-
* @param rules -
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
export declare const defineRules: <const Rules extends RuleOptions>(rules: RejectUnknownRuleNames<Rules>) => Rules & Linter.RulesRecord;
|
|
18
|
-
/**
|
|
19
|
-
* 根配置工厂唯一保留的项目选项。
|
|
14
|
+
* @typeParam Rules - 基于生成规则 schema 推断出的具体规则记录类型。
|
|
15
|
+
* @param rules - 需要验证的 ESLint 规则记录;未知规则名和无效规则选项会产生类型错误。
|
|
16
|
+
* @returns 原样返回传入的规则记录,并补充 ESLint `RulesRecord` 兼容类型。
|
|
20
17
|
*
|
|
21
|
-
* @
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const rules = defineRules({
|
|
21
|
+
* eqeqeq: ["error", "always"],
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
26
24
|
*/
|
|
27
|
-
export
|
|
25
|
+
export declare const defineRules: <const Rules extends RuleOptions>(rules: RejectUnknownRuleNames<Rules>) => Rules & Linter.RulesRecord;
|
|
26
|
+
/** Vue、UniApp 与框架无关项目完整配置共享的运行环境选项。 */
|
|
27
|
+
export interface ProjectConfigOptions {
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* - `"browser"`:提供浏览器全局变量。
|
|
32
|
-
* - `"node"`:提供 Node.js 全局变量。
|
|
33
|
-
* - `"universal"`:同时提供浏览器与 Node.js 全局变量。
|
|
34
|
-
*
|
|
35
|
-
* 配置文件、脚本、测试和 CLI 文件无论选择何种环境都会单独获得 Node.js globals。
|
|
29
|
+
* 应用代码实际运行的环境。配置、脚本、测试和 CLI 文件始终单独获得 Node.js globals。
|
|
36
30
|
* @defaultValue `"browser"`
|
|
37
31
|
*/
|
|
38
32
|
environment?: RuntimeEnvironment;
|
|
39
33
|
}
|
|
40
34
|
/**
|
|
41
|
-
*
|
|
35
|
+
* 创建不绑定前端框架的 JavaScript 与 TypeScript 完整配置。
|
|
42
36
|
*
|
|
43
37
|
* @remarks
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* React、Angular、Markdown 与 Lodash 等能力由调用方从 `./configs` 子路径继续组合。
|
|
38
|
+
* TypeScript 模块的导出成员按 SDK 公共 API 检查,内部实现保留类型推断。
|
|
39
|
+
* React、Angular、Markdown 与 Lodash 等能力从 `./configs` 子路径按需组合。
|
|
47
40
|
*
|
|
48
|
-
* @param options -
|
|
49
|
-
* @returns
|
|
41
|
+
* @param options - 应用源码的运行环境;默认仅注入浏览器全局变量。
|
|
42
|
+
* @returns 可直接传给 `eslint.config.*` 的 Flat Config 数组。
|
|
50
43
|
*/
|
|
51
|
-
export declare const createBaseConfigs: ({ environment }?:
|
|
44
|
+
export declare const createBaseConfigs: ({ environment }?: ProjectConfigOptions) => Config[];
|
|
52
45
|
/**
|
|
53
|
-
*
|
|
46
|
+
* 创建处理 `.vue`、Vue JSX 与 Vue TSX,且不注入任何 UniApp 能力的 Vue 3 完整配置。
|
|
54
47
|
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* 额外配置会放在全部内置片段之后,因此可以覆盖项目规则、globals、ignores 或解析器选项。
|
|
59
|
-
*
|
|
60
|
-
* @param options - 应用代码的运行环境。
|
|
61
|
-
* @param overrides - 追加到全部内置片段之后的 ESLint Flat Config。
|
|
62
|
-
* @returns 可直接导出给 ESLint 的 Flat Config 数组。
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* import { defineRules, fastConfig } from "@fast-china/eslint-config";
|
|
67
|
-
*
|
|
68
|
-
* export default fastConfig(
|
|
69
|
-
* { environment: "browser" },
|
|
70
|
-
* {
|
|
71
|
-
* files: ["src/generated/*.ts"],
|
|
72
|
-
* rules: defineRules({ "@typescript-eslint/no-unused-vars": "off" }),
|
|
73
|
-
* },
|
|
74
|
-
* );
|
|
75
|
-
* ```
|
|
48
|
+
* @param options - 应用源码的运行环境;默认仅注入浏览器全局变量。
|
|
49
|
+
* @param overrides - 追加在内置配置之后的项目级 Flat Config 覆写。
|
|
50
|
+
* @returns Vue 3 项目可直接使用的 Flat Config 数组。
|
|
76
51
|
*/
|
|
77
|
-
export declare const
|
|
52
|
+
export declare const createVueProjectConfigs: ({ environment }?: ProjectConfigOptions, ...overrides: Config[]) => Config[];
|
|
78
53
|
/**
|
|
79
|
-
*
|
|
54
|
+
* 创建处理 `.vue`、`.nvue`、Vue JSX/TSX、UniApp globals 与应用清单的完整配置。
|
|
80
55
|
*
|
|
81
|
-
* @
|
|
82
|
-
*
|
|
83
|
-
*
|
|
56
|
+
* @param options - 应用源码的运行环境;默认仅注入浏览器全局变量。
|
|
57
|
+
* @param overrides - 追加在内置配置之后的项目级 Flat Config 覆写。
|
|
58
|
+
* @returns UniApp 项目可直接使用的 Flat Config 数组。
|
|
84
59
|
*/
|
|
85
|
-
declare const
|
|
60
|
+
export declare const createUniAppProjectConfigs: ({ environment }?: ProjectConfigOptions, ...overrides: Config[]) => Config[];
|
|
61
|
+
/** 不带项目级覆写、可直接导入使用的 Vue 3 默认配置。 */
|
|
62
|
+
export declare const vueConfig: Config[];
|
|
63
|
+
/** 不带项目级覆写、可直接导入使用的 UniApp 默认配置。 */
|
|
64
|
+
export declare const uniAppConfig: Config[];
|
|
86
65
|
//#endregion
|
|
87
|
-
export {
|
|
66
|
+
export type { RuleOptions };
|
|
88
67
|
//# sourceMappingURL=index.d.mts.map
|