diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 349cef2c459fc39086f0bc974d1128ba3edbfeb5..25b59ce671992aff9234b03de8ece42720ee1268 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -136,7 +136,9 @@ "sdk-constructor-funcs", "sdk-no-literal-as-property-name", "sdk-no-decl-with-duplicate-name", - "sdk-type-query" + "sdk-type-query", + "sdk-ability-asynchronous-lifecycle", + "sdk-ability-lifecycle-monitor" ], "concurrent": [ "arkts-no-need-stdlib-ason", diff --git a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets index 71d8cd2396a17b3ef5261f5ddb4d43efe5230b73..b3af1c4b7764f50f47272f85f4e3c83fe158323d 100644 --- a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets @@ -14,28 +14,58 @@ */ import { UIAbility } from '@kit.AbilityKit'; +import { UIExtensionAbility } from '@kit.AbilityKit'; +import { AutoFillExtensionAbility } from '@kit.AbilityKit'; +import { ServiceExtensionAbility } from '@kit.AbilityKit'; function sleep(ms: number): Promise { return new Promise((resolve, reject) => { setTimeout(resolve, ms) }) } -export default class MyUIAbility extends UIAbility { - async onDestroy(): Promise { // ❌ Error + +function sleep1(ms: number): void { + return void +} + +export default class MyUIAbility1 extends UIAbility { + async onDestroy(): Promise { // use UIAbility onDestroy, should report error hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); return sleep(1000); } } +export default class MyUIAbility2 extends UIExtensionAbility { + async onDestroy(): Promise { // use UIExtensionAbility onDestroy, should report error + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + return sleep(1000); + } +} -function sleep(ms: number): Promise { - return new Promise((resolve, reject) => { - setTimeout(resolve, ms) - }) +export default class MyUIAbility3 extends AutoFillExtensionAbility { + async onDestroy(): Promise { // use AutoFillExtensionAbility onDestroy, should report error + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + return sleep(1000); + } } -export default class MyUIAbility extends UIAbility { - onDestroy() { // ❌ Error + +export default class MyUIAbility4 extends ServiceExtensionAbility { + async onDisconnect(): Promise { // use UIAbility onDestroy, should report error hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); return sleep(1000); } } + +export default class MyUIAbility5 extends UIAbility { + onDestroy() { // use UIAbility onDestroy with Promise return, should report error + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + return sleep(1000); + } +} + +export default class MyUIAbility6 extends UIAbility { + onDestroy() { // use UIAbility onDestroy with void return, should not report error + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + return sleep1(1000); + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json index dd37cd82be901a52af98be7a50ce82d1870dcb01..423ad83ad2f85bf7c107bf44a8f895f378362bc3 100644 --- a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle.ets.arkts2.json @@ -15,29 +15,29 @@ ], "result": [ { - "line": 18, - "column": 1, - "endLine": 22, - "endColumn": 2, - "problem": "TsOverload", + "line": 22, + "column": 10, + "endLine": 24, + "endColumn": 5, + "problem": "GenericCallNoTypeArgs", "suggest": "", - "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, { - "line": 19, + "line": 28, "column": 10, - "endLine": 21, - "endColumn": 5, - "problem": "GenericCallNoTypeArgs", + "endLine": 28, + "endColumn": 14, + "problem": "VoidOperator", "suggest": "", - "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "rule": "\"void\" operator is not supported (arkts-no-void-operator)", "severity": "ERROR" }, { - "line": 24, + "line": 32, "column": 3, - "endLine": 27, + "endLine": 35, "endColumn": 4, "problem": "LimitedVoidTypeFromSdk", "suggest": "", @@ -45,9 +45,9 @@ "severity": "ERROR" }, { - "line": 24, + "line": 32, "column": 9, - "endLine": 24, + "endLine": 32, "endColumn": 18, "problem": "SdkAbilityAsynchronousLifecycle", "suggest": "", @@ -55,9 +55,9 @@ "severity": "ERROR" }, { - "line": 26, + "line": 34, "column": 18, - "endLine": 26, + "endLine": 34, "endColumn": 22, "problem": "NumericSemantics", "suggest": "", @@ -65,29 +65,79 @@ "severity": "ERROR" }, { - "line": 31, - "column": 1, - "endLine": 35, - "endColumn": 2, - "problem": "TsOverload", + "line": 39, + "column": 3, + "endLine": 42, + "endColumn": 4, + "problem": "LimitedVoidTypeFromSdk", "suggest": "", - "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", "severity": "ERROR" }, { - "line": 32, - "column": 10, - "endLine": 34, - "endColumn": 5, - "problem": "GenericCallNoTypeArgs", + "line": 39, + "column": 9, + "endLine": 39, + "endColumn": 18, + "problem": "SdkAbilityAsynchronousLifecycle", "suggest": "", - "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "rule": "1.2 Void cannot be combined. OnDestroy/onDisconnect (The return type of the method is now void | Promise) needs to be split into two interfaces. (sdk-ability-asynchronous-lifecycle)", + "severity": "ERROR" + }, + { + "line": 41, + "column": 18, + "endLine": 41, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 46, + "column": 9, + "endLine": 46, + "endColumn": 18, + "problem": "SdkAbilityAsynchronousLifecycle", + "suggest": "", + "rule": "1.2 Void cannot be combined. OnDestroy/onDisconnect (The return type of the method is now void | Promise) needs to be split into two interfaces. (sdk-ability-asynchronous-lifecycle)", + "severity": "ERROR" + }, + { + "line": 48, + "column": 18, + "endLine": 48, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, { - "line": 37, + "line": 53, + "column": 9, + "endLine": 53, + "endColumn": 21, + "problem": "SdkAbilityAsynchronousLifecycle", + "suggest": "", + "rule": "1.2 Void cannot be combined. OnDestroy/onDisconnect (The return type of the method is now void | Promise) needs to be split into two interfaces. (sdk-ability-asynchronous-lifecycle)", + "severity": "ERROR" + }, + { + "line": 55, + "column": 18, + "endLine": 55, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 60, "column": 3, - "endLine": 40, + "endLine": 63, "endColumn": 4, "problem": "LimitedVoidTypeFromSdk", "suggest": "", @@ -95,9 +145,9 @@ "severity": "ERROR" }, { - "line": 37, + "line": 60, "column": 3, - "endLine": 37, + "endLine": 60, "endColumn": 12, "problem": "SdkAbilityAsynchronousLifecycle", "suggest": "", @@ -105,14 +155,34 @@ "severity": "ERROR" }, { - "line": 39, + "line": 62, "column": 18, - "endLine": 39, + "endLine": 62, "endColumn": 22, "problem": "NumericSemantics", "suggest": "", "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" + }, + { + "line": 67, + "column": 3, + "endLine": 70, + "endColumn": 4, + "problem": "LimitedVoidTypeFromSdk", + "suggest": "", + "rule": "Type \"void\" has no instances.(sdk-limited-void-type)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 19, + "endLine": 69, + "endColumn": 23, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..d480eb33021fa05682128f0e7e3b3f00db3e9aa9 --- /dev/null +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets @@ -0,0 +1,37 @@ +/* + * 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 { ServiceExtensionAbility } from '@kit.AbilityKit'; + +function sleep(ms: number): Promise { + return new Promise((resolve, reject) => { + setTimeout(resolve, ms) + }) +} + +export default class MyUIAbility1 extends ServiceExtensionAbility { + async onDestroy(): Promise { // use ServiceExtensionAbility onDestroy, should not report error + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + return sleep(1000); + } +} + +class UIAbility {} +export default class MyUIAbility2 extends UIAbility { + async onDestroy(): Promise { // use UIAbility not from SDK, should not report error + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + return sleep(1000); + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets.args.json b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..66fb88f85945924e8be0e83d90123507033f4c5d --- /dev/null +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.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": "" + } +} diff --git a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets.arkts2.json b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..e5e2d851980528aac83f9b8a48bfbeac0f63876b --- /dev/null +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets.arkts2.json @@ -0,0 +1,48 @@ +{ + "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." + ], + "result": [ + { + "line": 19, + "column": 10, + "endLine": 21, + "endColumn": 5, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 18, + "endLine": 27, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 35, + "column": 18, + "endLine": 35, + "endColumn": 22, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets.json b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..ca88f857e960b437dcf767c0ac40be998c8f1236 --- /dev/null +++ b/ets2panda/linter/test/main/sdk_ability_asynchronous_lifecycle_2.ets.json @@ -0,0 +1,17 @@ +{ + "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." + ], + "result": [] +} \ No newline at end of file