@lark-apaas/fullstack-presets 1.1.5-alpha.1 → 1.1.5-alpha.3

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.
@@ -1,8 +1,8 @@
1
1
  /**
2
- * ESLint rule to require AppContainer component in entry files.
2
+ * ESLint 规则:要求入口文件中必须包含 AppContainer 组件
3
3
  *
4
- * This rule ensures that client/src/index.tsx and client/src/app.tsx
5
- * files contain the AppContainer component to ensure platform features work correctly.
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,17 @@ 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 = '缺少平台组件AppContainer,请确认App外层包裹了AppContainer组件以确保平台功能正常运行';
38
- // Files that must contain AppContainer
39
- const REQUIRED_FILES = ['index.tsx', 'app.tsx'];
40
- // Directory pattern to match
37
+ const DEFAULT_MESSAGE = 'Missing platform component AppContainer. Please ensure that App is wrapped with AppContainer to enable platform features.';
38
+ // 必须包含 AppContainer 的文件列表
39
+ // TODO: 后续放开 index.tsx 的校验
40
+ const REQUIRED_FILES = ['app.tsx'];
41
+ // 匹配 client/src/ 目录的正则表达式
41
42
  const CLIENT_SRC_PATTERN = /[/\\]client[/\\]src[/\\]$/;
42
43
  const rule = {
43
44
  meta: {
44
45
  type: 'problem',
45
46
  docs: {
46
- description: 'Require AppContainer component in entry files',
47
+ description: '要求入口文件中必须包含 AppContainer 组件',
47
48
  category: 'Possible Errors',
48
49
  recommended: true,
49
50
  },
@@ -53,7 +54,7 @@ const rule = {
53
54
  properties: {
54
55
  message: {
55
56
  type: 'string',
56
- description: 'Custom error message',
57
+ description: '自定义错误信息',
57
58
  },
58
59
  },
59
60
  additionalProperties: false,
@@ -67,48 +68,38 @@ const rule = {
67
68
  const options = context.options[0];
68
69
  const customMessage = options?.message;
69
70
  const filename = context.filename || context.getFilename();
70
- // Check if this file should be validated
71
+ // 获取文件名和目录名
71
72
  const basename = path.basename(filename);
72
73
  const dirname = path.dirname(filename);
73
- // Only check files in client/src/ directory that match our required files
74
+ // 判断是否为需要检查的文件:必须在 client/src/ 目录下且文件名匹配
74
75
  const isRequiredFile = REQUIRED_FILES.includes(basename.toLowerCase()) &&
75
76
  CLIENT_SRC_PATTERN.test(dirname + path.sep);
77
+ // 如果不是需要检查的文件,直接跳过
76
78
  if (!isRequiredFile) {
77
79
  return {};
78
80
  }
79
- let hasAppContainer = false;
81
+ // 标记是否在 JSX 中实际使用了 AppContainer
82
+ let hasAppContainerUsage = false;
80
83
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
84
  let programNode = null;
82
85
  return {
83
- // Track if AppContainer is imported
84
- ImportDeclaration(node) {
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>
86
+ // 检查 JSX 中是否使用了 <AppContainer> 组件
87
+ // 注意:仅导入不使用不算通过,必须在 JSX 中实际使用
97
88
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
89
  JSXOpeningElement(node) {
99
90
  const elementName = node.name;
100
91
  if (elementName?.type === 'JSXIdentifier' &&
101
92
  elementName?.name === 'AppContainer') {
102
- hasAppContainer = true;
93
+ hasAppContainerUsage = true;
103
94
  }
104
95
  },
105
- // Store the program node for reporting at the end
96
+ // 保存 Program 节点,用于在文件末尾报错时定位
106
97
  Program(node) {
107
98
  programNode = node;
108
99
  },
109
- // Check at the end of file if AppContainer was found
100
+ // 文件解析完成后,检查是否在 JSX 中使用了 AppContainer
110
101
  'Program:exit'() {
111
- if (!hasAppContainer && programNode) {
102
+ if (!hasAppContainerUsage && programNode) {
112
103
  context.report({
113
104
  node: programNode,
114
105
  ...(customMessage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-presets",
3
- "version": "1.1.5-alpha.1",
3
+ "version": "1.1.5-alpha.3",
4
4
  "files": [
5
5
  "lib"
6
6
  ],