From 88da86e58abc3859f14203a9473d4d339a42fbdf Mon Sep 17 00:00:00 2001 From: sniperc96 Date: Wed, 20 Aug 2025 15:53:35 +0800 Subject: [PATCH] Modify the error message Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICTXD9 Signed-off-by: sniperc96 --- ets2panda/linter/rule-config.json | 2 +- ets2panda/linter/src/lib/CookBookMsg.ts | 3 +- ets2panda/linter/src/lib/FaultAttrs.ts | 2 +- ets2panda/linter/src/lib/FaultDesc.ts | 2 +- ets2panda/linter/src/lib/Problems.ts | 2 +- ets2panda/linter/src/lib/TypeScriptLinter.ts | 27 ++++++- .../test/main/make_observed_1.ets.arkts2.json | 8 +- .../test/main/make_observed_2.ets.arkts2.json | 8 +- .../linter/test/main/make_observed_4.ets | 33 +++++++++ .../test/main/make_observed_4.ets.args.json | 19 +++++ .../test/main/make_observed_4.ets.arkts2.json | 74 +++++++++++++++++++ .../linter/test/main/make_observed_4.ets.json | 3 + 12 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 ets2panda/linter/test/main/make_observed_4.ets create mode 100644 ets2panda/linter/test/main/make_observed_4.ets.args.json create mode 100644 ets2panda/linter/test/main/make_observed_4.ets.arkts2.json create mode 100644 ets2panda/linter/test/main/make_observed_4.ets.json diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 2b4b13d656..00c48628dc 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -122,7 +122,7 @@ "arkui-data-observation", "arkui-modular-interface", "arkui-entry-annotation-parameters", - "arkui-no-makeobserved-function", + "arkui-makeobserved-cannot-observe-custom-class", "arkui-provide-annotation-parameters", "arkui-custom-layout-need-add-decorator", "arkui-no-prop-decorator", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index eb595308ca..5f403f3ce7 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -288,7 +288,8 @@ cookBookTag[259] = 'The ArkUI interface should be imported before it is used (ar cookBookTag[260] = 'The "@Entry" annotation does not support dynamic parameters (arkui-entry-annotation-parameters)'; cookBookTag[261] = 'The UIAbility of 1.2 needs to be listened by the new StaticAbilityLifecycleCallback. The original AbilityLifecycleCallback can only listen to the UIAbility of 1.1 (sdk-ability-lifecycle-monitor)'; -cookBookTag[262] = 'The makeObserved function is not supported (arkui-no-makeobserved-function)'; +cookBookTag[262] = + 'The "makeObserved" function cannot observe custom class (arkui-makeobserved-cannot-observe-custom-class)'; cookBookTag[263] = 'The "@Provide" annotation does not support dynamic parameters (arkui-provide-annotation-parameters)'; cookBookTag[264] = diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index d7d64f4e67..d81b37da19 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -197,7 +197,7 @@ faultsAttrs[FaultID.DataObservation] = new FaultAttributes(258); faultsAttrs[FaultID.UIInterfaceImport] = new FaultAttributes(259); faultsAttrs[FaultID.EntryAnnotation] = new FaultAttributes(260); faultsAttrs[FaultID.SdkAbilityLifecycleMonitor] = new FaultAttributes(261); -faultsAttrs[FaultID.MakeObservedIsNotSupported] = new FaultAttributes(262); +faultsAttrs[FaultID.MakeObservedCannotObserveCustomClass] = new FaultAttributes(262); faultsAttrs[FaultID.ProvideAnnotation] = new FaultAttributes(263); faultsAttrs[FaultID.FieldTypeMismatch] = new FaultAttributes(264); faultsAttrs[FaultID.InteropJsObjectInheritance] = new FaultAttributes(265); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index eebe9aef41..9297f2b85b 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -252,7 +252,7 @@ faultDesc[FaultID.LimitedStdLibNoDoncurrentDecorator] = 'Limited stdlib no concu faultDesc[FaultID.NoNeedStdlibWorker] = 'No need stdlib worker'; faultDesc[FaultID.BuiltinGetOwnPropertyNames] = 'No "Object.getOwnPropertyNames" in API'; faultDesc[FaultID.LocalBuilderDecoratorNotSupported] = '"@LocalBuilder" decorator'; -faultDesc[FaultID.MakeObservedIsNotSupported] = 'MakeObserved is not supported'; +faultDesc[FaultID.MakeObservedCannotObserveCustomClass] = 'MakeObserved cannot observe custom class'; faultDesc[FaultID.NoEnumPropAsType] = 'No enum prop as type'; faultDesc[FaultID.NoAwaitJsPromise] = 'No await js promise'; faultDesc[FaultID.NosparseArray] = 'No sparse array'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index 99bdbd2687..e13490e85e 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -251,7 +251,7 @@ export enum FaultID { NoNeedStdlibWorker, BuiltinGetOwnPropertyNames, LocalBuilderDecoratorNotSupported, - MakeObservedIsNotSupported, + MakeObservedCannotObserveCustomClass, NoEnumPropAsType, NoAwaitJsPromise, NosparseArray, diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index c2f34353a2..618c9a2638 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -11814,7 +11814,32 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } - this.incrementCounters(node, FaultID.MakeObservedIsNotSupported); + const callExpr = node.parent; + if (!callExpr || !ts.isCallExpression(callExpr)) { + return; + } + + const arg = callExpr.arguments?.[0]; + if (!arg) { + return; + } + + if (!this.isCustomClass(arg)) { + return; + } + + this.incrementCounters(node, FaultID.MakeObservedCannotObserveCustomClass); + } + + private isCustomClass(node: ts.Node): boolean { + const type = this.tsTypeChecker.getTypeAtLocation(node); + const typeSymbol = type.getSymbol(); + if (!typeSymbol) { + return false; + } + + const decl = TsUtils.getDeclaration(typeSymbol); + return decl !== undefined && decl.getSourceFile() === node.getSourceFile() && ts.isClassDeclaration(decl); } private handlePropertyDeclarationForProp(node: ts.PropertyDeclaration): void { diff --git a/ets2panda/linter/test/main/make_observed_1.ets.arkts2.json b/ets2panda/linter/test/main/make_observed_1.ets.arkts2.json index a1d930ced0..4f6be2ebe6 100644 --- a/ets2panda/linter/test/main/make_observed_1.ets.arkts2.json +++ b/ets2panda/linter/test/main/make_observed_1.ets.arkts2.json @@ -19,9 +19,9 @@ "column": 26, "endLine": 28, "endColumn": 46, - "problem": "MakeObservedIsNotSupported", + "problem": "MakeObservedCannotObserveCustomClass", "suggest": "", - "rule": "The makeObserved function is not supported (arkui-no-makeobserved-function)", + "rule": "The \"makeObserved\" function cannot observe custom class (arkui-makeobserved-cannot-observe-custom-class)", "severity": "ERROR" }, { @@ -29,9 +29,9 @@ "column": 24, "endLine": 38, "endColumn": 44, - "problem": "MakeObservedIsNotSupported", + "problem": "MakeObservedCannotObserveCustomClass", "suggest": "", - "rule": "The makeObserved function is not supported (arkui-no-makeobserved-function)", + "rule": "The \"makeObserved\" function cannot observe custom class (arkui-makeobserved-cannot-observe-custom-class)", "severity": "ERROR" }, { diff --git a/ets2panda/linter/test/main/make_observed_2.ets.arkts2.json b/ets2panda/linter/test/main/make_observed_2.ets.arkts2.json index cb52174e8f..5930931613 100644 --- a/ets2panda/linter/test/main/make_observed_2.ets.arkts2.json +++ b/ets2panda/linter/test/main/make_observed_2.ets.arkts2.json @@ -19,9 +19,9 @@ "column": 26, "endLine": 28, "endColumn": 44, - "problem": "MakeObservedIsNotSupported", + "problem": "MakeObservedCannotObserveCustomClass", "suggest": "", - "rule": "The makeObserved function is not supported (arkui-no-makeobserved-function)", + "rule": "The \"makeObserved\" function cannot observe custom class (arkui-makeobserved-cannot-observe-custom-class)", "severity": "ERROR" }, { @@ -29,9 +29,9 @@ "column": 24, "endLine": 38, "endColumn": 42, - "problem": "MakeObservedIsNotSupported", + "problem": "MakeObservedCannotObserveCustomClass", "suggest": "", - "rule": "The makeObserved function is not supported (arkui-no-makeobserved-function)", + "rule": "The \"makeObserved\" function cannot observe custom class (arkui-makeobserved-cannot-observe-custom-class)", "severity": "ERROR" }, { diff --git a/ets2panda/linter/test/main/make_observed_4.ets b/ets2panda/linter/test/main/make_observed_4.ets new file mode 100644 index 0000000000..5ef66a5672 --- /dev/null +++ b/ets2panda/linter/test/main/make_observed_4.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { UIUtils } from '@kit.ArkUI'; + +interface User { + name: string; +} + +@Entry +@Component +struct Index { + user: User = UIUtils.makeObserved({ name: 'jack' }); + MyArr: Array = UIUtils.makeObserved(new Array(1, 2)); + MySet: Set = UIUtils.makeObserved(new Set([1, 2, 3])) + myMap: Map = UIUtils.makeObserved(new Map([["jack", 3], ["tom", 2]])); + myDate: Date = UIUtils.makeObserved(new Date()); + + build() { + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/make_observed_4.ets.args.json b/ets2panda/linter/test/main/make_observed_4.ets.args.json new file mode 100644 index 0000000000..d8d3390ad9 --- /dev/null +++ b/ets2panda/linter/test/main/make_observed_4.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/make_observed_4.ets.arkts2.json b/ets2panda/linter/test/main/make_observed_4.ets.arkts2.json new file mode 100644 index 0000000000..7d3ef2b4a0 --- /dev/null +++ b/ets2panda/linter/test/main/make_observed_4.ets.arkts2.json @@ -0,0 +1,74 @@ +{ + "result": [ + { + "line": 26, + "column": 51, + "endLine": 26, + "endColumn": 56, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 47, + "endLine": 26, + "endColumn": 62, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 45, + "endLine": 27, + "endColumn": 63, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 28, + "column": 53, + "endLine": 28, + "endColumn": 87, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 29, + "column": 43, + "endLine": 29, + "endColumn": 47, + "problem": "BuiltinNewCtor", + "suggest": "", + "rule": "API is not support initial ctor signature (arkts-builtin-new-cotr)", + "severity": "ERROR" + }, + { + "line": 22, + "column": 2, + "endLine": 22, + "endColumn": 7, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Entry\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 2, + "endLine": 23, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "The ArkUI interface \"Component\" should be imported before it is used (arkui-modular-interface)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/make_observed_4.ets.json b/ets2panda/linter/test/main/make_observed_4.ets.json new file mode 100644 index 0000000000..43cb4a27bc --- /dev/null +++ b/ets2panda/linter/test/main/make_observed_4.ets.json @@ -0,0 +1,3 @@ +{ + "result": [] +} \ No newline at end of file -- Gitee