@lark-apaas/fullstack-presets 1.1.5-alpha.0 → 1.1.5-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/custom-eslint-rules/require-app-container.d.ts +3 -3
- package/lib/custom-eslint-rules/require-app-container.js +16 -26
- package/lib/recommend/eslint/eslint-client.d.ts +1 -1
- package/lib/recommend/eslint/eslint-client.js +2 -2
- package/lib/recommend/eslint/index.d.ts +1 -1
- package/lib/simple/recommend/eslint/eslint-client.d.ts +4 -4
- package/lib/simple/recommend/eslint/eslint-client.js +3 -4
- package/lib/simple/recommend/eslint/index.d.ts +4 -4
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ESLint
|
|
2
|
+
* ESLint 规则:要求入口文件中必须包含 AppContainer 组件
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 此规则确保 client/src/index.tsx 和 client/src/app.tsx 文件中
|
|
5
|
+
* 包含 AppContainer 组件,以保证平台功能正常运行。
|
|
6
6
|
*/
|
|
7
7
|
import type { Rule } from 'eslint';
|
|
8
8
|
declare const rule: Rule.RuleModule;
|
|
@@ -34,16 +34,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
const path = __importStar(require("path"));
|
|
37
|
-
const DEFAULT_MESSAGE = '
|
|
38
|
-
//
|
|
37
|
+
const DEFAULT_MESSAGE = 'Missing platform component AppContainer. Please ensure that App is wrapped with AppContainer to enable platform features.';
|
|
38
|
+
// 必须包含 AppContainer 的文件列表
|
|
39
39
|
const REQUIRED_FILES = ['index.tsx', 'app.tsx'];
|
|
40
|
-
//
|
|
40
|
+
// 匹配 client/src/ 目录的正则表达式
|
|
41
41
|
const CLIENT_SRC_PATTERN = /[/\\]client[/\\]src[/\\]$/;
|
|
42
42
|
const rule = {
|
|
43
43
|
meta: {
|
|
44
44
|
type: 'problem',
|
|
45
45
|
docs: {
|
|
46
|
-
description: '
|
|
46
|
+
description: '要求入口文件中必须包含 AppContainer 组件',
|
|
47
47
|
category: 'Possible Errors',
|
|
48
48
|
recommended: true,
|
|
49
49
|
},
|
|
@@ -53,7 +53,7 @@ const rule = {
|
|
|
53
53
|
properties: {
|
|
54
54
|
message: {
|
|
55
55
|
type: 'string',
|
|
56
|
-
description: '
|
|
56
|
+
description: '自定义错误信息',
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
59
|
additionalProperties: false,
|
|
@@ -67,48 +67,38 @@ const rule = {
|
|
|
67
67
|
const options = context.options[0];
|
|
68
68
|
const customMessage = options?.message;
|
|
69
69
|
const filename = context.filename || context.getFilename();
|
|
70
|
-
//
|
|
70
|
+
// 获取文件名和目录名
|
|
71
71
|
const basename = path.basename(filename);
|
|
72
72
|
const dirname = path.dirname(filename);
|
|
73
|
-
//
|
|
73
|
+
// 判断是否为需要检查的文件:必须在 client/src/ 目录下且文件名匹配
|
|
74
74
|
const isRequiredFile = REQUIRED_FILES.includes(basename.toLowerCase()) &&
|
|
75
75
|
CLIENT_SRC_PATTERN.test(dirname + path.sep);
|
|
76
|
+
// 如果不是需要检查的文件,直接跳过
|
|
76
77
|
if (!isRequiredFile) {
|
|
77
78
|
return {};
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
+
// 标记是否在 JSX 中实际使用了 AppContainer
|
|
81
|
+
let hasAppContainerUsage = false;
|
|
80
82
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
83
|
let programNode = null;
|
|
82
84
|
return {
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
// Check for default or named import of AppContainer
|
|
86
|
-
for (const specifier of node.specifiers) {
|
|
87
|
-
if (specifier.type === 'ImportSpecifier' ||
|
|
88
|
-
specifier.type === 'ImportDefaultSpecifier') {
|
|
89
|
-
if (specifier.local.name === 'AppContainer') {
|
|
90
|
-
hasAppContainer = true;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
// Check for JSX usage of <AppContainer>
|
|
85
|
+
// 检查 JSX 中是否使用了 <AppContainer> 组件
|
|
86
|
+
// 注意:仅导入不使用不算通过,必须在 JSX 中实际使用
|
|
97
87
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
88
|
JSXOpeningElement(node) {
|
|
99
89
|
const elementName = node.name;
|
|
100
90
|
if (elementName?.type === 'JSXIdentifier' &&
|
|
101
91
|
elementName?.name === 'AppContainer') {
|
|
102
|
-
|
|
92
|
+
hasAppContainerUsage = true;
|
|
103
93
|
}
|
|
104
94
|
},
|
|
105
|
-
//
|
|
95
|
+
// 保存 Program 节点,用于在文件末尾报错时定位
|
|
106
96
|
Program(node) {
|
|
107
97
|
programNode = node;
|
|
108
98
|
},
|
|
109
|
-
//
|
|
99
|
+
// 文件解析完成后,检查是否在 JSX 中使用了 AppContainer
|
|
110
100
|
'Program:exit'() {
|
|
111
|
-
if (!
|
|
101
|
+
if (!hasAppContainerUsage && programNode) {
|
|
112
102
|
context.report({
|
|
113
103
|
node: programNode,
|
|
114
104
|
...(customMessage
|
|
@@ -23,7 +23,7 @@ exports.default = {
|
|
|
23
23
|
plugins: {
|
|
24
24
|
'react-hooks': reactHooks,
|
|
25
25
|
import: importPlugin,
|
|
26
|
-
'
|
|
26
|
+
'@lark-apaas': {
|
|
27
27
|
rules: custom_eslint_rules_1.customRules,
|
|
28
28
|
},
|
|
29
29
|
},
|
|
@@ -41,7 +41,7 @@ exports.default = {
|
|
|
41
41
|
// React Hooks 推荐规则
|
|
42
42
|
...reactHooks.configs.recommended.rules,
|
|
43
43
|
// 平台规则:确保入口文件包含 AppContainer 组件
|
|
44
|
-
'
|
|
44
|
+
'@lark-apaas/require-app-container': 'error',
|
|
45
45
|
// TypeScript 规则
|
|
46
46
|
'@typescript-eslint/no-unused-vars': 'off', // 未使用变量检查关闭
|
|
47
47
|
'@typescript-eslint/no-explicit-any': 'off', // 允许使用 any 类型
|
|
@@ -16,7 +16,7 @@ export declare const eslintPresets: {
|
|
|
16
16
|
plugins: {
|
|
17
17
|
'react-hooks': any;
|
|
18
18
|
import: any;
|
|
19
|
-
'
|
|
19
|
+
'@lark-apaas': {
|
|
20
20
|
rules: {
|
|
21
21
|
'no-nested-styled-jsx': import("eslint").Rule.RuleModule;
|
|
22
22
|
'require-app-container': import("eslint").Rule.RuleModule;
|
|
@@ -15,14 +15,14 @@ declare const _default: ({
|
|
|
15
15
|
globals: any;
|
|
16
16
|
};
|
|
17
17
|
plugins: {
|
|
18
|
-
'
|
|
18
|
+
'react-hooks': any;
|
|
19
|
+
import: any;
|
|
20
|
+
'@lark-apaas': {
|
|
19
21
|
rules: {
|
|
20
22
|
'no-nested-styled-jsx': import("eslint").Rule.RuleModule;
|
|
21
23
|
'require-app-container': import("eslint").Rule.RuleModule;
|
|
22
24
|
};
|
|
23
|
-
}
|
|
24
|
-
'react-hooks': any;
|
|
25
|
-
import: any;
|
|
25
|
+
};
|
|
26
26
|
};
|
|
27
27
|
settings: {
|
|
28
28
|
'import/resolver': {
|
|
@@ -94,9 +94,6 @@ const strictSyntaxRules = [
|
|
|
94
94
|
message: 'Classname "text-accent" would cause visibility issues. Consider using proper semantic color tokens from `client/src/tailwind-theme.css`',
|
|
95
95
|
},
|
|
96
96
|
];
|
|
97
|
-
const looseSpecificPlugins = {
|
|
98
|
-
'@lark-apaas': { rules: custom_eslint_rules_1.customRules }
|
|
99
|
-
};
|
|
100
97
|
const looseSpecificRules = {
|
|
101
98
|
'@lark-apaas/no-nested-styled-jsx': 'error'
|
|
102
99
|
};
|
|
@@ -128,7 +125,7 @@ const baseConfig = {
|
|
|
128
125
|
plugins: {
|
|
129
126
|
'react-hooks': reactHooks,
|
|
130
127
|
import: importPlugin,
|
|
131
|
-
|
|
128
|
+
'@lark-apaas': { rules: custom_eslint_rules_1.customRules },
|
|
132
129
|
},
|
|
133
130
|
settings: {
|
|
134
131
|
'import/resolver': {
|
|
@@ -143,6 +140,8 @@ const baseConfig = {
|
|
|
143
140
|
rules: {
|
|
144
141
|
// React Hooks 推荐规则
|
|
145
142
|
...reactHooks.configs.recommended.rules,
|
|
143
|
+
// 平台规则:确保入口文件包含 AppContainer 组件
|
|
144
|
+
'@lark-apaas/require-app-container': 'error',
|
|
146
145
|
// TypeScript 规则
|
|
147
146
|
'@typescript-eslint/no-unused-vars': 'off', // 未使用变量检查关闭
|
|
148
147
|
'@typescript-eslint/no-explicit-any': 'off', // 允许使用 any 类型
|
|
@@ -14,14 +14,14 @@ export declare const eslintPresets: {
|
|
|
14
14
|
globals: any;
|
|
15
15
|
};
|
|
16
16
|
plugins: {
|
|
17
|
-
'
|
|
17
|
+
'react-hooks': any;
|
|
18
|
+
import: any;
|
|
19
|
+
'@lark-apaas': {
|
|
18
20
|
rules: {
|
|
19
21
|
'no-nested-styled-jsx': import("eslint").Rule.RuleModule;
|
|
20
22
|
'require-app-container': import("eslint").Rule.RuleModule;
|
|
21
23
|
};
|
|
22
|
-
}
|
|
23
|
-
'react-hooks': any;
|
|
24
|
-
import: any;
|
|
24
|
+
};
|
|
25
25
|
};
|
|
26
26
|
settings: {
|
|
27
27
|
'import/resolver': {
|