diff --git a/arkui-plugins/ui-syntax-plugins/rules/entry-componentv2-invalid-params.ts b/arkui-plugins/ui-syntax-plugins/rules/entry-componentv2-invalid-params.ts index 0aa95b24229f21e84e35fcdaa64416df06e021f0..a40343da37f44abfba914a150debb05266f5add5 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/entry-componentv2-invalid-params.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/entry-componentv2-invalid-params.ts @@ -17,13 +17,18 @@ import * as arkts from '@koalaui/libarkts'; import { getAnnotationUsage, PresetDecorators } from '../utils'; import { AbstractUISyntaxRule } from './ui-syntax-rule'; +const ENTRY_VALUE: string = 'value'; const ENTRY_STORAGE: string = 'storage'; -const ENTRY_USE_SHARED_STORAGE = 'useSharedStorage'; +const ENTRY_USE_SHARED_STORAGE: string = 'useSharedStorage'; class EntryComponentV2InvalidParamsRule extends AbstractUISyntaxRule { + private entryDecoratorhasInvalidEntryOptions: boolean = false; + private entryDecoratorhasInvalidLocalStorage: boolean = false; + public setup(): Record { return { - invalidEntryParams: `The "@ComponentV2" decorator cannot be used together with the "@Entry" decorator that has "storage" or "useSharedStorage" parameters.` + invalidEntryOptions: `The "@Entry" decorator that has "storage" or "useSharedStorage" parameters cannot be used together with the "@ComponentV2" decorator.`, + invalidLocalStorage: `The "@Entry" decorator that has a "LocalStorage" type parameter cannot be used together with the "@ComponentV2" decorator.` }; } @@ -42,22 +47,33 @@ class EntryComponentV2InvalidParamsRule extends AbstractUISyntaxRule { return; } - const entryDecoratorhasInvalidParams = this.checkEntryDecoratorHasInvalidParams(entryDecoratorUsage); - if (entryDecoratorhasInvalidParams) { + this.checkEntryDecoratorHasInvalidEntryOptions(entryDecoratorUsage); + if (this.entryDecoratorhasInvalidEntryOptions) { + this.report({ + node: entryDecoratorUsage, + message: this.messages.invalidEntryOptions, + }); + return; + } + + if (this.entryDecoratorhasInvalidLocalStorage) { this.report({ node: entryDecoratorUsage, - message: this.messages.invalidEntryParams, + message: this.messages.invalidLocalStorage, }); } } - private checkEntryDecoratorHasInvalidParams(entryDecorator: arkts.AnnotationUsage): boolean { - return entryDecorator.properties.some((property) => { + private checkEntryDecoratorHasInvalidEntryOptions(entryDecorator: arkts.AnnotationUsage): void { + entryDecorator.properties.forEach((property) => { if (arkts.isClassProperty(property) && property.key && arkts.isIdentifier(property.key)) { const propertyName = property.key.name; - return propertyName === ENTRY_STORAGE || propertyName === ENTRY_USE_SHARED_STORAGE; + if (propertyName === ENTRY_STORAGE || propertyName === ENTRY_USE_SHARED_STORAGE) { + this.entryDecoratorhasInvalidEntryOptions = true; + } else if (propertyName === ENTRY_VALUE) { + this.entryDecoratorhasInvalidLocalStorage = true; + } } - return false; }); } } diff --git a/arkui-plugins/ui-syntax-plugins/rules/index.ts b/arkui-plugins/ui-syntax-plugins/rules/index.ts index c20774408c494429fe458e368f9dee77b7164a76..aec9b5304520b3b4b04ce92dfb13cf1376d544fd 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/index.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/index.ts @@ -70,7 +70,7 @@ import SpecificComponentChildrenRule from './specific-component-children'; import EntryComponentV2StorageRule from './entry-componentv2-invalid-params'; const rules: Array = [ - [AttributeNoInvokeRule, 'warn'], + [AttributeNoInvokeRule, 'error'], [BuildRootNodeRule, 'error'], [BuilderParamDecoratorCheckRule, 'error'], [CheckConstructPrivateParameterRule, 'warn'], @@ -123,7 +123,7 @@ const rules: Array = [ [RequireDecoratorRegularRule, 'warn'], [ReusableComponentInV2CheckRule, 'warn'], [SpecificComponentChildrenRule, 'error'], - [EntryComponentV2StorageRule, 'error'] + [EntryComponentV2StorageRule, 'warn'] ]; export default rules; \ No newline at end of file diff --git a/arkui-plugins/ui-syntax-plugins/rules/ui-syntax-rule.ts b/arkui-plugins/ui-syntax-plugins/rules/ui-syntax-rule.ts index 817d5ddd00dca49aee2bf960c81d34f42744d5cd..a3a20dd64ca511625ecf5d1813b4cbfd98615284 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/ui-syntax-rule.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/ui-syntax-rule.ts @@ -54,6 +54,7 @@ export type UISyntaxRule = { export type UISyntaxRuleReportOptions = { node: arkts.AstNode; message: string; + level?: UISyntaxRuleLevel; data?: Record; fix?: (node: arkts.AstNode) => FixSuggestion; }; @@ -80,7 +81,7 @@ export abstract class AbstractUISyntaxRule { protected report(options: UISyntaxRuleReportOptions): void { this.context.report({ ...options, - level: this.level, + level: options.level ?? this.level, }); } } diff --git a/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-function.ts b/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-function.ts index fe2135a6e9a5c4ec74509f4270a6cb382897bb0b..8f921df172c6d1499f8f239d528087aab8383103 100644 --- a/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-function.ts +++ b/arkui-plugins/ui-syntax-plugins/rules/watch-decorator-function.ts @@ -177,6 +177,7 @@ class WatchDecoratorFunctionRule extends AbstractUISyntaxRule { this.report({ node: watchDecorator, message: this.messages.stringOnly, + level: 'warn', data: { parameterName: this.getExpressionValue(parameters, privateNames) }, fix: () => { const startPosition = parameters.startPosition;