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 e4ddae7dc0366146f2e7590576124140c1f7a3e4..c0b9181e4a4de46ff022adfd40d0b7db2bfb62e6 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 c3942a7a36fb8587527c8238a8c4baea984beae4..06cc166b1354ff8493903b788b66de530dfba7bd 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 d73f539d0750207a7aacaa766b37e2d78a15a0fa..640493db9230ac2589f35e80dd0dbdf4c1154d24 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 {