From ded793c85ad7c80b346be69e9f399f4aa460b107 Mon Sep 17 00:00:00 2001 From: wangweiyuan2 Date: Wed, 23 Jul 2025 10:36:26 +0800 Subject: [PATCH] ui-syntax-plugins-0723 Signed-off-by: wangweiyuan2 --- .../rules/main-pages-entry-check.ts | 6 +++--- .../rules/struct-variable-initialization.ts | 14 +++++++++++++- koala-wrapper/src/arkts-api/types.ts | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arkui-plugins/ui-syntax-plugins/rules/main-pages-entry-check.ts b/arkui-plugins/ui-syntax-plugins/rules/main-pages-entry-check.ts index e4ddae7dc..c0b9181e4 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/main-pages-entry-check.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/main-pages-entry-check.ts @@ -23,8 +23,8 @@ class MainPagesEntryCheckRule extends AbstractUISyntaxRule { mainPagesEntryCheck: `A page configured in 'main_pages. json or build-profile. json5' must have one and only one '@Entry' annotation. ` }; } - public parsed(node: arkts.StructDeclaration): void { - if (!arkts.isEtsScript(node)) { + public parsed(node: arkts.AstNode): void { + if (!arkts.isEtsScript(node) || node.isNamespace) { return; } const currentFilePath = getCurrentFilePath(node); @@ -42,7 +42,7 @@ class MainPagesEntryCheckRule extends AbstractUISyntaxRule { // Check if it's of type StructDeclaration if (arkts.isStructDeclaration(child)) { if (!firstStructDeclaration) { - firstStructDeclaration = child; + firstStructDeclaration = child.definition.ident; } const entryDocoratorUsage = getAnnotationUsage( child, diff --git a/arkui-plugins/ui-syntax-plugins/rules/struct-variable-initialization.ts b/arkui-plugins/ui-syntax-plugins/rules/struct-variable-initialization.ts index c3942a7a3..06cc166b1 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/struct-variable-initialization.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/struct-variable-initialization.ts @@ -41,7 +41,8 @@ class StructVariableInitializationRule extends AbstractUISyntaxRule { public setup(): Record { return { mustBeInitializedLocally: `The '@{{decoratorName}}' property must be specified a default value.`, - prohibitLocalInitialization: `The '@{{decoratorName}}' property cannot be specified a default value.` + prohibitLocalInitialization: `The '@{{decoratorName}}' property cannot be specified a default value.`, + propRefRequireNoDefault: `The '@PropRef' property with '@Require' cannot be specified a default value.`, }; } @@ -58,6 +59,10 @@ class StructVariableInitializationRule extends AbstractUISyntaxRule { const valueExists = !!node.value; // Check for the presence of require decorator const hasRequire = findDecorator(node, PresetDecorators.REQUIRE); + const hasPropRef = findDecorator(node, PresetDecorators.PROP_REF); + if (hasPropRef && hasRequire && valueExists) { + this.reportPropRefRequireNoDefault(hasPropRef); + } node.annotations.some(annotation => { if (annotation.expr && arkts.isIdentifier(annotation.expr) && mustInitializeDecorators.includes(annotation.expr.name)) { @@ -103,6 +108,13 @@ class StructVariableInitializationRule extends AbstractUISyntaxRule { }); } } + + private reportPropRefRequireNoDefault(annotation: arkts.AnnotationUsage): void { + this.report({ + node: annotation, + message: this.messages.propRefRequireNoDefault, + }); + } } export default StructVariableInitializationRule; \ No newline at end of file diff --git a/koala-wrapper/src/arkts-api/types.ts b/koala-wrapper/src/arkts-api/types.ts index d73f539d0..640493db9 100644 --- a/koala-wrapper/src/arkts-api/types.ts +++ b/koala-wrapper/src/arkts-api/types.ts @@ -120,6 +120,10 @@ export class EtsScript extends AstNode { nodes.length ); } + + get isNamespace(): boolean { + return global.generatedEs2panda._ETSModuleIsNamespaceConst(global.context, this.peer); + } } export class ExpressionStatement extends AstNode { -- Gitee